From 02031447489fdcd53d1581d4b6897fa4b281833d Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Mon, 26 Feb 2018 14:22:23 +0100 Subject: [PATCH 001/203] PCHR-3353: Set custom field group that should not be editable to is_reserved yes --- hrdemog/CRM/HRDemog/Upgrader.php | 14 ++++++++++++ hrjobcontract/CRM/Hrjobcontract/Upgrader.php | 15 +++++++++++++ hrrecruitment/CRM/HRRecruitment/Upgrader.php | 15 +++++++++++++ hrui/CRM/HRUI/Upgrader.php | 1 + hrui/CRM/HRUI/Upgrader/Steps/4708.php | 20 +++++++++++++++++ .../CRM/Hremergency/Upgrader.php | 1 + .../CRM/Hremergency/Upgrader/Steps/1004.php | 22 +++++++++++++++++++ 7 files changed, 88 insertions(+) create mode 100644 hrui/CRM/HRUI/Upgrader/Steps/4708.php create mode 100644 org.civicrm.hremergency/CRM/Hremergency/Upgrader/Steps/1004.php diff --git a/hrdemog/CRM/HRDemog/Upgrader.php b/hrdemog/CRM/HRDemog/Upgrader.php index 4a61caf1926..e4946e316af 100644 --- a/hrdemog/CRM/HRDemog/Upgrader.php +++ b/hrdemog/CRM/HRDemog/Upgrader.php @@ -161,4 +161,18 @@ public function upgrade_1400() { CRM_Core_DAO::executeQuery("UPDATE civicrm_custom_group SET is_reserved = 0, collapse_display = 1 where name = 'Extended_Demographics'"); return TRUE; } + + /** + * Upgrade CustomGroup, setting Extended_Demographics is_reserved value to YES + */ + public function upgrade_1401() { + $result = civicrm_api3('CustomGroup', 'get', [ + 'sequential' => 1, + 'return' => ["id"], + 'name' => "Extended_Demographics", + 'api.CustomGroup.create' => ['id' => "\$value.id", 'is_reserved' => 0], + ]); + + return true; + } } diff --git a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php index 50b323a33dc..d60ae228d42 100755 --- a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php +++ b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php @@ -1157,6 +1157,21 @@ public function upgrade_1033() { return TRUE; } + /** + * Update CustomGroup, setting Contact_Length_Of_Service is_reserved to Yes + * @return bool + */ + public function upgrade_1034() { + $result = civicrm_api3('CustomGroup', 'get', [ + 'sequential' => 1, + 'return' => ["id"], + 'name' => "Contact_Length_Of_Service", + 'api.CustomGroup.create' => ['id' => "\$value.id", 'is_reserved' => 0], + ]); + + return true; + } + /** * Removes the "Pension Type" item from the * "Administer -> Customize Data and Screens -> Dropdowns" menu diff --git a/hrrecruitment/CRM/HRRecruitment/Upgrader.php b/hrrecruitment/CRM/HRRecruitment/Upgrader.php index 41bca437eb0..417ebbeeccc 100644 --- a/hrrecruitment/CRM/HRRecruitment/Upgrader.php +++ b/hrrecruitment/CRM/HRRecruitment/Upgrader.php @@ -49,4 +49,19 @@ public function upgrade_1402() { return TRUE; } + + /** + * Upgrade CustomGroup, setting Application, application_case and Evaluation_fields names to is_reserved Yes + * @return bool + */ + public function upgrade_1403() { + $result = civicrm_api3('CustomGroup', 'get', array( + 'sequential' => 1, + 'return' => array("id"), + 'name' => array('IN' => array("Application", "application_case", "Evaluation_fields")), + 'api.CustomGroup.create' => array('id' => "\$value.id", 'is_reserved' => 0), + )); + + return true; + } } diff --git a/hrui/CRM/HRUI/Upgrader.php b/hrui/CRM/HRUI/Upgrader.php index d63ccad0f47..3645442b0e4 100755 --- a/hrui/CRM/HRUI/Upgrader.php +++ b/hrui/CRM/HRUI/Upgrader.php @@ -38,6 +38,7 @@ class CRM_HRUI_Upgrader extends CRM_HRUI_Upgrader_Base { use CRM_HRUI_Upgrader_Steps_4705; use CRM_HRUI_Upgrader_Steps_4706; use CRM_HRUI_Upgrader_Steps_4707; + use CRM_HRUI_Upgrader_Steps_4708; public function install() { $this->runAllUpgraders(); diff --git a/hrui/CRM/HRUI/Upgrader/Steps/4708.php b/hrui/CRM/HRUI/Upgrader/Steps/4708.php new file mode 100644 index 00000000000..3dc509486f3 --- /dev/null +++ b/hrui/CRM/HRUI/Upgrader/Steps/4708.php @@ -0,0 +1,20 @@ + 1, + 'return' => ["id"], + 'name' => "Inline_Custom_Data", + 'api.CustomGroup.create' => ['id' => "\$value.id", 'is_reserved' => 1], + ]); + + return true; + } + +} \ No newline at end of file diff --git a/org.civicrm.hremergency/CRM/Hremergency/Upgrader.php b/org.civicrm.hremergency/CRM/Hremergency/Upgrader.php index c6efb3a4b5f..af912c99c81 100644 --- a/org.civicrm.hremergency/CRM/Hremergency/Upgrader.php +++ b/org.civicrm.hremergency/CRM/Hremergency/Upgrader.php @@ -9,6 +9,7 @@ class CRM_Hremergency_Upgrader extends CRM_Hremergency_Upgrader_Base { use CRM_Hremergency_Upgrader_Steps_1001; use CRM_Hremergency_Upgrader_Steps_1002; use CRM_Hremergency_Upgrader_Steps_1003; + use CRM_Hremergency_Upgrader_Steps_1004; /** * Change the custom_group ID to 99999 as we have this exported through Drupal webforms so the ID needs to be always the same diff --git a/org.civicrm.hremergency/CRM/Hremergency/Upgrader/Steps/1004.php b/org.civicrm.hremergency/CRM/Hremergency/Upgrader/Steps/1004.php new file mode 100644 index 00000000000..ab57de21603 --- /dev/null +++ b/org.civicrm.hremergency/CRM/Hremergency/Upgrader/Steps/1004.php @@ -0,0 +1,22 @@ + 1, + 'return' => ["id"], + 'name' => "Emergency_Contacts", + 'api.CustomGroup.create' => ['id' => "\$value.id", 'is_reserved' => 1, 'title' => "Emergency Contacts"], + ]); + + return true; + } + +} \ No newline at end of file From 6a89702af3a845ca78861c7c98809f5f95f8e959 Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Mon, 26 Feb 2018 14:46:00 +0100 Subject: [PATCH 002/203] PCHR-3353: Code refactoring from review --- hrdemog/CRM/HRDemog/Upgrader.php | 25 ++++++------ hrjobcontract/CRM/Hrjobcontract/Upgrader.php | 23 +++++------ hrrecruitment/CRM/HRRecruitment/Upgrader.php | 24 ++++++------ hrui/CRM/HRUI/Upgrader/Steps/4708.php | 29 +++++++------- .../CRM/Hremergency/Upgrader/Steps/1004.php | 39 +++++++++++-------- 5 files changed, 77 insertions(+), 63 deletions(-) diff --git a/hrdemog/CRM/HRDemog/Upgrader.php b/hrdemog/CRM/HRDemog/Upgrader.php index e4946e316af..eea9e09c32f 100644 --- a/hrdemog/CRM/HRDemog/Upgrader.php +++ b/hrdemog/CRM/HRDemog/Upgrader.php @@ -162,17 +162,20 @@ public function upgrade_1400() { return TRUE; } - /** - * Upgrade CustomGroup, setting Extended_Demographics is_reserved value to YES - */ + /** + * Upgrade CustomGroup, setting Extended_Demographics is_reserved value to YES + * + * @return bool + */ public function upgrade_1401() { - $result = civicrm_api3('CustomGroup', 'get', [ - 'sequential' => 1, - 'return' => ["id"], - 'name' => "Extended_Demographics", - 'api.CustomGroup.create' => ['id' => "\$value.id", 'is_reserved' => 0], - ]); - - return true; + civicrm_api3('CustomGroup', 'get', [ + 'sequential' => 1, + 'return' => ['id'], + 'name' => 'Extended_Demographics', + 'api.CustomGroup.create' => ['id' => '\$value.id', 'is_reserved' => 1], + ]); + + return TRUE; } + } diff --git a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php index d60ae228d42..c9ddc18c230 100755 --- a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php +++ b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php @@ -1157,19 +1157,20 @@ public function upgrade_1033() { return TRUE; } - /** - * Update CustomGroup, setting Contact_Length_Of_Service is_reserved to Yes - * @return bool - */ + /** + * Update CustomGroup, setting Contact_Length_Of_Service is_reserved to Yes + * + * @return bool + */ public function upgrade_1034() { - $result = civicrm_api3('CustomGroup', 'get', [ - 'sequential' => 1, - 'return' => ["id"], - 'name' => "Contact_Length_Of_Service", - 'api.CustomGroup.create' => ['id' => "\$value.id", 'is_reserved' => 0], - ]); + civicrm_api3('CustomGroup', 'get', [ + 'sequential' => 1, + 'return' => ['id'], + 'name' => 'Contact_Length_Of_Service', + 'api.CustomGroup.create' => ['id' => '\$value.id', 'is_reserved' => 1], + ]); - return true; + return TRUE; } /** diff --git a/hrrecruitment/CRM/HRRecruitment/Upgrader.php b/hrrecruitment/CRM/HRRecruitment/Upgrader.php index 417ebbeeccc..52eed6daa18 100644 --- a/hrrecruitment/CRM/HRRecruitment/Upgrader.php +++ b/hrrecruitment/CRM/HRRecruitment/Upgrader.php @@ -50,18 +50,20 @@ public function upgrade_1402() { return TRUE; } - /** - * Upgrade CustomGroup, setting Application, application_case and Evaluation_fields names to is_reserved Yes - * @return bool - */ + /** + * Upgrade CustomGroup, setting Application, application_case and Evaluation_fields names to is_reserved Yes + * + * @return bool + */ public function upgrade_1403() { - $result = civicrm_api3('CustomGroup', 'get', array( - 'sequential' => 1, - 'return' => array("id"), - 'name' => array('IN' => array("Application", "application_case", "Evaluation_fields")), - 'api.CustomGroup.create' => array('id' => "\$value.id", 'is_reserved' => 0), - )); + civicrm_api3('CustomGroup', 'get', [ + 'sequential' => 1, + 'return' => ['id'], + 'name' => ['IN' => ['Application', 'application_case', 'Evaluation_fields']], + 'api.CustomGroup.create' => ['id' => '\$value.id', 'is_reserved' => 1], + ]); - return true; + return TRUE; } + } diff --git a/hrui/CRM/HRUI/Upgrader/Steps/4708.php b/hrui/CRM/HRUI/Upgrader/Steps/4708.php index 3dc509486f3..f28b33e274b 100644 --- a/hrui/CRM/HRUI/Upgrader/Steps/4708.php +++ b/hrui/CRM/HRUI/Upgrader/Steps/4708.php @@ -2,19 +2,20 @@ trait CRM_HRUI_Upgrader_Steps_4708 { - /** - * Upgrade CustomGroup, set Inline_Custom_Data is_reserved Yes - * @return bool - */ - public function upgrade_4708() { - $result = civicrm_api3('CustomGroup', 'get', [ - 'sequential' => 1, - 'return' => ["id"], - 'name' => "Inline_Custom_Data", - 'api.CustomGroup.create' => ['id' => "\$value.id", 'is_reserved' => 1], - ]); + /** + * Upgrade CustomGroup, set Inline_Custom_Data is_reserved Yes + * + * @return bool + */ + public function upgrade_4708() { + civicrm_api3('CustomGroup', 'get', [ + 'sequential' => 1, + 'return' => ['id'], + 'name' => 'Inline_Custom_Data', + 'api.CustomGroup.create' => ['id' => '\$value.id', 'is_reserved' => 1], + ]); - return true; - } + return TRUE; + } -} \ No newline at end of file +} diff --git a/org.civicrm.hremergency/CRM/Hremergency/Upgrader/Steps/1004.php b/org.civicrm.hremergency/CRM/Hremergency/Upgrader/Steps/1004.php index ab57de21603..18f27d38b80 100644 --- a/org.civicrm.hremergency/CRM/Hremergency/Upgrader/Steps/1004.php +++ b/org.civicrm.hremergency/CRM/Hremergency/Upgrader/Steps/1004.php @@ -2,21 +2,28 @@ trait CRM_Hremergency_Upgrader_Steps_1004 { - /** - * Upgrade CustomGroup, setting Emergency_Contacts is_reserved to Yes - * title was included here because of an issue with webform_civicrm - * @see https://www.drupal.org/project/webform_civicrm/issues/2947922 - * @return bool - */ - public function upgrade_1004() { - $result = civicrm_api3('CustomGroup', 'get', [ - 'sequential' => 1, - 'return' => ["id"], - 'name' => "Emergency_Contacts", - 'api.CustomGroup.create' => ['id' => "\$value.id", 'is_reserved' => 1, 'title' => "Emergency Contacts"], - ]); + /** + * Upgrade CustomGroup, setting Emergency_Contacts is_reserved to Yes. + * Title was included here because of an issue with webform_civicrm + * @see https://www.drupal.org/project/webform_civicrm/issues/2947922 + * + * @return bool + */ + public function upgrade_1004() { + $creationParams = [ + 'id' => '\$value.id', + 'is_reserved' => 1, + 'title' => 'Emergency Contacts' + ]; + + civicrm_api3('CustomGroup', 'get', [ + 'sequential' => 1, + 'return' => ['id'], + 'name' => 'Emergency_Contacts', + 'api.CustomGroup.create' => $creationParams, + ]); - return true; - } + return TRUE; + } -} \ No newline at end of file +} From 6ccde6e1826a3f536e5912d98b5e0ab3ad95b16c Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Wed, 28 Feb 2018 11:18:14 +0000 Subject: [PATCH 003/203] PCHR-3353: Code refactor for Jenkins build failure --- hrdemog/CRM/HRDemog/Upgrader.php | 8 ++++++-- hrjobcontract/CRM/Hrjobcontract/Upgrader.php | 18 +++++++++++------- hrrecruitment/CRM/HRRecruitment/Upgrader.php | 10 ++++++++-- hrui/CRM/HRUI/Upgrader/Steps/4708.php | 10 +++++++--- .../CRM/Hremergency/Upgrader/Steps/1004.php | 17 ++++++++--------- 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/hrdemog/CRM/HRDemog/Upgrader.php b/hrdemog/CRM/HRDemog/Upgrader.php index eea9e09c32f..e32e54c4e78 100644 --- a/hrdemog/CRM/HRDemog/Upgrader.php +++ b/hrdemog/CRM/HRDemog/Upgrader.php @@ -168,11 +168,15 @@ public function upgrade_1400() { * @return bool */ public function upgrade_1401() { - civicrm_api3('CustomGroup', 'get', [ + $result = civicrm_api3('CustomGroup', 'get', [ 'sequential' => 1, 'return' => ['id'], 'name' => 'Extended_Demographics', - 'api.CustomGroup.create' => ['id' => '\$value.id', 'is_reserved' => 1], + ]); + + civicrm_api3('CustomGroup', 'create', [ + 'id' => $result['id'], + 'is_reserved' => 1, ]); return TRUE; diff --git a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php index c9ddc18c230..19140c0a7dc 100755 --- a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php +++ b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php @@ -165,7 +165,7 @@ public function upgradeBundle() { ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 "); CRM_Core_DAO::executeQuery(" - INSERT INTO `civicrm_hrhours_location` (`id`, `location`, `standard_hours`, `periodicity`, `is_active`) + INSERT INTO `civicrm_hrhours_location` (`id`, `location`, `standard_hours`, `periodicity`, `is_active`) VALUES (1, 'Head office', 40, 'Week', 1) "); @@ -925,7 +925,7 @@ function upgrade_1020() { if (empty($data)) { CRM_Core_DAO::executeQuery(" - INSERT INTO `civicrm_hrpay_scale` (`pay_scale`, `pay_grade`, `currency`, `amount`, `periodicity`, `is_active`) + INSERT INTO `civicrm_hrpay_scale` (`pay_scale`, `pay_grade`, `currency`, `amount`, `periodicity`, `is_active`) VALUES ('Not Applicable', NULL, NULL, NULL, NULL, 1) "); } @@ -1007,8 +1007,8 @@ public function upgrade_1025() { */ public function upgrade_1026() { $query = " - ALTER TABLE `civicrm_hrjobcontract_hour` - CHANGE `fte_num` `fte_num` INT(10) UNSIGNED NULL DEFAULT '0' COMMENT '.', + ALTER TABLE `civicrm_hrjobcontract_hour` + CHANGE `fte_num` `fte_num` INT(10) UNSIGNED NULL DEFAULT '0' COMMENT '.', CHANGE `fte_denom` `fte_denom` INT(10) UNSIGNED NULL DEFAULT '0' COMMENT '.' "; CRM_Core_DAO::executeQuery($query); @@ -1163,12 +1163,16 @@ public function upgrade_1033() { * @return bool */ public function upgrade_1034() { - civicrm_api3('CustomGroup', 'get', [ + $result = civicrm_api3('CustomGroup', 'get', array( 'sequential' => 1, 'return' => ['id'], 'name' => 'Contact_Length_Of_Service', - 'api.CustomGroup.create' => ['id' => '\$value.id', 'is_reserved' => 1], - ]); + )); + + civicrm_api3('CustomGroup', 'create', array( + 'id' => $result['id'], + 'is_reserved' => 1, + )); return TRUE; } diff --git a/hrrecruitment/CRM/HRRecruitment/Upgrader.php b/hrrecruitment/CRM/HRRecruitment/Upgrader.php index 52eed6daa18..2b0c053ded6 100644 --- a/hrrecruitment/CRM/HRRecruitment/Upgrader.php +++ b/hrrecruitment/CRM/HRRecruitment/Upgrader.php @@ -56,12 +56,18 @@ public function upgrade_1402() { * @return bool */ public function upgrade_1403() { - civicrm_api3('CustomGroup', 'get', [ + $result = civicrm_api3('CustomGroup', 'get', [ 'sequential' => 1, 'return' => ['id'], 'name' => ['IN' => ['Application', 'application_case', 'Evaluation_fields']], - 'api.CustomGroup.create' => ['id' => '\$value.id', 'is_reserved' => 1], ]); + + foreach ($result['values'] as $value) { + civicrm_api3('CustomGroup', 'create', [ + 'id' => $value['id'], + 'is_reserved' => 1, + ]); + } return TRUE; } diff --git a/hrui/CRM/HRUI/Upgrader/Steps/4708.php b/hrui/CRM/HRUI/Upgrader/Steps/4708.php index f28b33e274b..bbd3c0de73a 100644 --- a/hrui/CRM/HRUI/Upgrader/Steps/4708.php +++ b/hrui/CRM/HRUI/Upgrader/Steps/4708.php @@ -8,13 +8,17 @@ trait CRM_HRUI_Upgrader_Steps_4708 { * @return bool */ public function upgrade_4708() { - civicrm_api3('CustomGroup', 'get', [ + $result = civicrm_api3('CustomGroup', 'get', [ 'sequential' => 1, 'return' => ['id'], 'name' => 'Inline_Custom_Data', - 'api.CustomGroup.create' => ['id' => '\$value.id', 'is_reserved' => 1], ]); - + + civicrm_api3('CustomGroup', 'create', [ + 'id' => $result['id'], + 'is_reserved' => 1, + ]); + return TRUE; } diff --git a/org.civicrm.hremergency/CRM/Hremergency/Upgrader/Steps/1004.php b/org.civicrm.hremergency/CRM/Hremergency/Upgrader/Steps/1004.php index 18f27d38b80..cf222bce359 100644 --- a/org.civicrm.hremergency/CRM/Hremergency/Upgrader/Steps/1004.php +++ b/org.civicrm.hremergency/CRM/Hremergency/Upgrader/Steps/1004.php @@ -6,21 +6,20 @@ trait CRM_Hremergency_Upgrader_Steps_1004 { * Upgrade CustomGroup, setting Emergency_Contacts is_reserved to Yes. * Title was included here because of an issue with webform_civicrm * @see https://www.drupal.org/project/webform_civicrm/issues/2947922 - * + * * @return bool */ public function upgrade_1004() { - $creationParams = [ - 'id' => '\$value.id', - 'is_reserved' => 1, - 'title' => 'Emergency Contacts' - ]; - - civicrm_api3('CustomGroup', 'get', [ + $result = civicrm_api3('CustomGroup', 'get', [ 'sequential' => 1, 'return' => ['id'], 'name' => 'Emergency_Contacts', - 'api.CustomGroup.create' => $creationParams, + ]); + + civicrm_api3('CustomGroup', 'create', [ + 'id' => $result['id'], + 'is_reserved' => 1, + 'title' => 'Emergency Contacts' ]); return TRUE; From 928f1414626b167ab16b5f3c3cfc08645c64514d Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Thu, 1 Mar 2018 10:38:49 +0100 Subject: [PATCH 004/203] PCHR-3162-configurability-changes: Merge conflict resolution --- hrui/CRM/HRUI/Upgrader.php | 1 + hrui/CRM/HRUI/Upgrader/Steps/4709.php | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 hrui/CRM/HRUI/Upgrader/Steps/4709.php diff --git a/hrui/CRM/HRUI/Upgrader.php b/hrui/CRM/HRUI/Upgrader.php index 3645442b0e4..d80d0eb7771 100755 --- a/hrui/CRM/HRUI/Upgrader.php +++ b/hrui/CRM/HRUI/Upgrader.php @@ -39,6 +39,7 @@ class CRM_HRUI_Upgrader extends CRM_HRUI_Upgrader_Base { use CRM_HRUI_Upgrader_Steps_4706; use CRM_HRUI_Upgrader_Steps_4707; use CRM_HRUI_Upgrader_Steps_4708; + use CRM_HRUI_Upgrader_Steps_4709; public function install() { $this->runAllUpgraders(); diff --git a/hrui/CRM/HRUI/Upgrader/Steps/4709.php b/hrui/CRM/HRUI/Upgrader/Steps/4709.php new file mode 100644 index 00000000000..1d5b4645365 --- /dev/null +++ b/hrui/CRM/HRUI/Upgrader/Steps/4709.php @@ -0,0 +1,25 @@ + 1, + 'return' => ['id'], + 'name' => 'Inline_Custom_Data', + ]); + + civicrm_api3('CustomGroup', 'create', [ + 'id' => $result['id'], + 'is_reserved' => 1, + ]); + + return TRUE; + } + +} From 80cd279d208c09a0b8854c807a5a8c92d5c1fa4d Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Thu, 1 Mar 2018 15:16:11 +0100 Subject: [PATCH 005/203] PCHR-3392: Set custom field group to is_reserved yes --- hrident/CRM/HRIdent/Upgrader.php | 24 ++++++++++++ hrjobcontract/CRM/Hrjobcontract/Upgrader.php | 41 +++++++++++++++++--- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/hrident/CRM/HRIdent/Upgrader.php b/hrident/CRM/HRIdent/Upgrader.php index dd45de20b7e..96044b97b34 100755 --- a/hrident/CRM/HRIdent/Upgrader.php +++ b/hrident/CRM/HRIdent/Upgrader.php @@ -135,4 +135,28 @@ public function upgrade_1501() { return true; } + + /** + * Upgrade CustomGroup, setting Identify is_reserved value to Yes + * if it existing. + * + * @return bool + */ + public function upgrade_1502() { + $result = civicrm_api3('CustomGroup', 'get', [ + 'sequential' => 1, + 'return' => ['id'], + 'name' => 'Identify', + ]); + + if ($result['id']) { + civicrm_api3('CustomGroup', 'create', [ + 'id' => $result['id'], + 'is_reserved' => 1, + ]); + } + + return TRUE; + } + } diff --git a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php index 19140c0a7dc..bd806c1b77b 100755 --- a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php +++ b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php @@ -1163,16 +1163,47 @@ public function upgrade_1033() { * @return bool */ public function upgrade_1034() { - $result = civicrm_api3('CustomGroup', 'get', array( + $result = civicrm_api3('CustomGroup', 'get', [ 'sequential' => 1, 'return' => ['id'], 'name' => 'Contact_Length_Of_Service', - )); - - civicrm_api3('CustomGroup', 'create', array( + ]); + + civicrm_api3('CustomGroup', 'create', [ 'id' => $result['id'], 'is_reserved' => 1, - )); + ]); + + return TRUE; + } + + /** + * Upgrade CustomGroup, setting HRJobContract_Dates, HRJob_Summary and + * HRJobContract_Summary is_reserved value to Yes if it is existing. + * + * @return bool + */ + public function upgrade_1035() { + $customGroups = [ + 'HRJobContract_Dates', + 'HRJob_Summary', + 'HRJobContract_Summary' + ]; + + $result = civicrm_api3('CustomGroup', 'get', [ + 'sequential' => 1, + 'return' => ['id'], + 'name' => ['IN' => $customGroups], + ]); + + if (count($result['values'])) { + foreach ($result['values'] as $value) { + civicrm_api3('CustomGroup', 'create', [ + 'id' => $value['id'], + 'is_reserved' => 1, + ]); + } + } return TRUE; } From b79bddc78c663a88c46014cd84390cbf6d430c68 Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Thu, 1 Mar 2018 17:20:27 +0100 Subject: [PATCH 006/203] PCHR-3392: Code refactoring --- hrident/CRM/HRIdent/Upgrader.php | 1 - hrjobcontract/CRM/Hrjobcontract/Upgrader.php | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/hrident/CRM/HRIdent/Upgrader.php b/hrident/CRM/HRIdent/Upgrader.php index 96044b97b34..18b0cb6df93 100755 --- a/hrident/CRM/HRIdent/Upgrader.php +++ b/hrident/CRM/HRIdent/Upgrader.php @@ -144,7 +144,6 @@ public function upgrade_1501() { */ public function upgrade_1502() { $result = civicrm_api3('CustomGroup', 'get', [ - 'sequential' => 1, 'return' => ['id'], 'name' => 'Identify', ]); diff --git a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php index bd806c1b77b..3645ec3a097 100755 --- a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php +++ b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php @@ -1191,12 +1191,11 @@ public function upgrade_1035() { ]; $result = civicrm_api3('CustomGroup', 'get', [ - 'sequential' => 1, 'return' => ['id'], 'name' => ['IN' => $customGroups], ]); - if (count($result['values'])) { + if ($result['count'] > 0) { foreach ($result['values'] as $value) { civicrm_api3('CustomGroup', 'create', [ 'id' => $value['id'], From b1f4ad138b85bd87a1da526f7842a8ad7dc08fe1 Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Tue, 6 Mar 2018 11:49:49 +0100 Subject: [PATCH 007/203] PCHR-3392: Moved HRIdent upgrade to HRCore due to HRIdent extension being disabled --- hrident/CRM/HRIdent/Upgrader.php | 22 -------------- .../CRM/HRCore/Upgrader.php | 1 + .../CRM/HRCore/Upgrader/Steps/1011.php | 30 +++++++++++++++++++ 3 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1011.php diff --git a/hrident/CRM/HRIdent/Upgrader.php b/hrident/CRM/HRIdent/Upgrader.php index 18b0cb6df93..f52db740561 100755 --- a/hrident/CRM/HRIdent/Upgrader.php +++ b/hrident/CRM/HRIdent/Upgrader.php @@ -136,26 +136,4 @@ public function upgrade_1501() { return true; } - /** - * Upgrade CustomGroup, setting Identify is_reserved value to Yes - * if it existing. - * - * @return bool - */ - public function upgrade_1502() { - $result = civicrm_api3('CustomGroup', 'get', [ - 'return' => ['id'], - 'name' => 'Identify', - ]); - - if ($result['id']) { - civicrm_api3('CustomGroup', 'create', [ - 'id' => $result['id'], - 'is_reserved' => 1, - ]); - } - - return TRUE; - } - } diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php index c5dabab231d..e15a417dc7b 100755 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php @@ -18,6 +18,7 @@ class CRM_HRCore_Upgrader extends CRM_HRCore_Upgrader_Base { use CRM_HRCore_Upgrader_Steps_1008; use CRM_HRCore_Upgrader_Steps_1009; use CRM_HRCore_Upgrader_Steps_1010; + use CRM_HRCore_Upgrader_Steps_1011; /** * @var array diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1011.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1011.php new file mode 100644 index 00000000000..d5140595f63 --- /dev/null +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1011.php @@ -0,0 +1,30 @@ + ['id'], + 'name' => 'Identify', + ]); + + if ($result['id']) { + civicrm_api3('CustomGroup', 'create', [ + 'id' => $result['id'], + 'is_reserved' => 1, + ]); + } + + return TRUE; + } +} From f2dea6219a1f33993625d8fa4f8650b8b8358264 Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Tue, 6 Mar 2018 12:32:51 +0100 Subject: [PATCH 008/203] PCHR-3392: Comments refactor --- .../CRM/HRCore/Upgrader/Steps/1011.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1011.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1011.php index d5140595f63..736482c7272 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1011.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1011.php @@ -1,14 +1,11 @@ Date: Wed, 7 Mar 2018 09:40:12 +0100 Subject: [PATCH 009/203] PCHR-3433: Rename inline custom field data --- hrui/CRM/HRUI/Upgrader.php | 1 + hrui/CRM/HRUI/Upgrader/Steps/4710.php | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 hrui/CRM/HRUI/Upgrader/Steps/4710.php diff --git a/hrui/CRM/HRUI/Upgrader.php b/hrui/CRM/HRUI/Upgrader.php index d80d0eb7771..883b60a142c 100755 --- a/hrui/CRM/HRUI/Upgrader.php +++ b/hrui/CRM/HRUI/Upgrader.php @@ -40,6 +40,7 @@ class CRM_HRUI_Upgrader extends CRM_HRUI_Upgrader_Base { use CRM_HRUI_Upgrader_Steps_4707; use CRM_HRUI_Upgrader_Steps_4708; use CRM_HRUI_Upgrader_Steps_4709; + use CRM_HRUI_Upgrader_Steps_4710; public function install() { $this->runAllUpgraders(); diff --git a/hrui/CRM/HRUI/Upgrader/Steps/4710.php b/hrui/CRM/HRUI/Upgrader/Steps/4710.php new file mode 100644 index 00000000000..f93b9b94ecf --- /dev/null +++ b/hrui/CRM/HRUI/Upgrader/Steps/4710.php @@ -0,0 +1,23 @@ + ['id'], + 'name' => 'Inline_Custom_Data', + ]); + + civicrm_api3('CustomGroup', 'create', [ + 'id' => $result['id'], + 'title' => 'NI/SSN Number', + ]); + + return TRUE; + } + +} From 8805efb76002758e3568fb88447eb52fa582c94b Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 26 Feb 2018 11:12:53 +0000 Subject: [PATCH 010/203] PCHR-3354: Add permission 'access root menu items and configurations' --- uk.co.compucorp.civicrm.hrcore/hrcore.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/hrcore.php b/uk.co.compucorp.civicrm.hrcore/hrcore.php index 3ef44d449fe..883ae508a6d 100644 --- a/uk.co.compucorp.civicrm.hrcore/hrcore.php +++ b/uk.co.compucorp.civicrm.hrcore/hrcore.php @@ -309,11 +309,13 @@ function hrcore_civicrm_alterMenu(&$items) { * Implements hook_civicrm_permission(). * * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_permission/ + * + * @param array $permissions */ function hrcore_civicrm_permission(&$permissions) { - $permissions += [ - 'access CiviCRM developer menu and tools' => ts('Access CiviCRM developer menu and tools') - ]; + $prefix = ts('CiviHR') . ': '; + $permissions['access CiviCRM developer menu and tools'] = ts('Access CiviCRM developer menu and tools'); + $permissions['access root menu items and configurations'] = $prefix . ts('Access root menu items and configurations'); } /** From 5696b1e0cac35d16f008a9f08f52d76466fd0250 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 26 Feb 2018 13:11:33 +0000 Subject: [PATCH 011/203] PCHR-3365: Change permission on "CiviHR website" menu link --- uk.co.compucorp.civicrm.hrcore/hrcore.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uk.co.compucorp.civicrm.hrcore/hrcore.php b/uk.co.compucorp.civicrm.hrcore/hrcore.php index 883ae508a6d..ce4c410a7c0 100644 --- a/uk.co.compucorp.civicrm.hrcore/hrcore.php +++ b/uk.co.compucorp.civicrm.hrcore/hrcore.php @@ -427,7 +427,7 @@ function _hrcore_createHelpMenu(&$menu) { 'name' => ts('CiviHR website'), 'url' => 'https://www.civihr.org/', 'target' => '_blank', - 'permission' => 'access CiviCRM' + 'permission' => 'access root menu items and configurations' ]); _hrcore_civix_insert_navigation_menu($menu, 'Help', [ From 113c0e78a84d51a9f999f7310603747817c3f9bf Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Wed, 28 Feb 2018 13:33:45 +0000 Subject: [PATCH 012/203] PCHR-3374: Add helper class for nav menu manipulation --- .../HRCore/Helper/NavigationMenuHelper.php | 214 + .../HRCore/Files/sample_navigation_menu.json | 4348 +++++++++++++++++ .../Helper/NavigationMenuHelperTest.php | 208 + 3 files changed, 4770 insertions(+) create mode 100644 uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php create mode 100644 uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Files/sample_navigation_menu.json create mode 100644 uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php new file mode 100644 index 00000000000..2b9c8f7f860 --- /dev/null +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php @@ -0,0 +1,214 @@ + $label, 'active' => 1]; + $newItem = ['attributes' => array_merge($defaults, $itemAttributes)]; + + $parent['child'][] = $newItem; + } + + /** + * @param $menu + * @param $nameOfItemToMove + * @param $nameOfItemBefore + * @throws Exception + */ + public static function relocateAfter(&$menu, $nameOfItemToMove, $nameOfItemBefore) { + $parentName = self::findParentItemName($menu, $nameOfItemBefore); + + if ($parentName === 'root') { + $children = &$menu; + } + else { + $parent = &self::findMenuItemReferenceByName($menu, $parentName); + $children = &$parent['child']; + } + + $itemToMove = self::findMenuItemByName($menu, $nameOfItemToMove); + self::remove($menu, $nameOfItemToMove); + + $targetIndex = NULL; + $offset = 1; // because we want to insert it after + $found = FALSE; + foreach ($children as $index => $child) { + if ($child['attributes']['name'] === $nameOfItemBefore) { + $found = TRUE; + break; + } + $offset++; + } + + if (!$found) { + $err = sprintf('Could not find menu item "%s"', $nameOfItemBefore); + throw new \Exception($err); + } + + array_splice($children, $offset, 0, [$itemToMove]); + } + + public static function remove(&$menu, $name) { + $parentName = self::findParentItemName($menu, $name); + + if ($parentName === NULL) { + $err = sprintf('Cannot find parent of menu item "%s"', $name); + throw new \Exception($err); + } + + if ($parentName === 'root') { + $children = &$menu; + } + else { + $parent = &self::findMenuItemReferenceByName($menu, $parentName); + $children = &$parent['child']; + } + + foreach ($children as $index => $child) { + if ($child['attributes']['name'] === $name) { + unset($children[$index]); + return; + } + } + } + + /** + * Sets the permission on a named menu item + * + * @param array $menu + * The full menu + * @param string $name + * The name of the target menu item + * @param string $newPermission + * The new permission for accessing this item + */ + public static function updatePermissionByName(&$menu, $name, $newPermission) { + $item = &self::findMenuItemReferenceByName($menu, $name); + + if (!$item) { + $err = sprintf('Cannot find menu item with name "%s"', $name); + throw new \Exception($err); + } + + $item['attributes']['permission'] = $newPermission; + } + + /** + * Recursively search for a menu item by its name + * + * @param array $menu + * @param string $name + * + * @return array|null + * The menu item, if found, or null otherwise + */ + public static function findMenuItemByName($menu, $name) { + return self::findMenuItemReferenceByName($menu, $name); + } + + /** + * Recursively search for a menu item by its name. Returns a reference to + * the item. + * + * @param array $menu + * @param string $name + * + * @return array|null + * The referenced menu item, if found, or null otherwise + */ + private static function &findMenuItemReferenceByName(&$menu, $name) { + foreach ($menu as &$item) { + if ($item['attributes']['name'] === $name) { + return $item; + } + if (!empty($item['child'])) { + $found = &self::findMenuItemReferenceByName($item['child'], $name); + + if ($found) { + return $found; + } + } + } + + // must return reference to variable + $item = NULL; + + return $item; + } + + /** + * Recursively search for a menu item's parent name by the child name + * + * This is a wrapper for a private function that requires a third argument. + * + * @param array $menu + * @param string $childName + * + * @return string|null + * The parent item name, if found, or null otherwise. + * If item is at top level parent name will be 'root' + */ + public static function findParentItemName($menu, $childName + ) { + return self::findParentItemNameFromRoot($menu, $childName, 'root'); + } + + /** + * Recursively search for a menu item's parent name by the child name + * + * @param array $menu + * @param string $childName + * @param string $parentName + * + * @return string|null + * The parent item name, if found, or null otherwise. + * If item is at top level parent name will be 'root' + */ + private static function findParentItemNameFromRoot( + $menu, + $childName, + $parentName + ) { + foreach ($menu as $item) { + if ($item['attributes']['name'] === $childName) { + return $parentName; + } + if (!empty($item['child'])) { + $children = $item['child']; + $found = self::findParentItemNameFromRoot( + $children, + $childName, + $item['attributes']['name'] + ); + + if ($found) { + return $found; + } + } + } + + return NULL; + } + +} diff --git a/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Files/sample_navigation_menu.json b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Files/sample_navigation_menu.json new file mode 100644 index 00000000000..e5d18f90d3f --- /dev/null +++ b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Files/sample_navigation_menu.json @@ -0,0 +1,4348 @@ +{ + "1": { + "attributes": { + "label": "Home", + "name": "Home", + "url": "civicrm/tasksassignments/dashboard#/tasks", + "icon": null, + "permission": null, + "operator": "", + "separator": null, + "parentID": null, + "navID": "1", + "active": "1" + } + }, + "2": { + "attributes": { + "label": "Search", + "name": "Search...", + "url": null, + "icon": "crm-i fa-search", + "permission": null, + "operator": "", + "separator": null, + "parentID": null, + "navID": "2", + "active": "1" + }, + "child": { + "3": { + "attributes": { + "label": "Find Contacts", + "name": "Find Contacts", + "url": "civicrm/contact/search?reset=1", + "icon": null, + "permission": null, + "operator": "", + "separator": null, + "parentID": "2", + "navID": "3", + "active": "1" + } + }, + "4": { + "attributes": { + "label": "Advanced Search", + "name": "Advanced Search", + "url": "civicrm/contact/search/advanced?reset=1", + "icon": null, + "permission": null, + "operator": "", + "separator": null, + "parentID": "2", + "navID": "4", + "active": "1" + } + }, + "5": { + "attributes": { + "label": "Full-text Search", + "name": "Full-text Search", + "url": "civicrm/contact/search/custom?csid=15&reset=1", + "icon": null, + "permission": null, + "operator": "", + "separator": null, + "parentID": "2", + "navID": "5", + "active": "1" + } + }, + "6": { + "attributes": { + "label": "Search Builder", + "name": "Search Builder", + "url": "civicrm/contact/search/builder?reset=1", + "icon": null, + "permission": null, + "operator": "", + "separator": "1", + "parentID": "2", + "navID": "6", + "active": "1" + } + }, + "7": { + "attributes": { + "label": "Find Cases", + "name": "Find Cases", + "url": "civicrm/case/search?reset=1", + "icon": null, + "permission": "access my cases and activities,access all cases and activities", + "operator": "OR", + "separator": null, + "parentID": "2", + "navID": "7", + "active": "1" + } + }, + "8": { + "attributes": { + "label": "Find Contributions", + "name": "Find Contributions", + "url": "civicrm/contribute/search?reset=1", + "icon": null, + "permission": "access CiviContribute", + "operator": "", + "separator": null, + "parentID": "2", + "navID": "8", + "active": "1" + } + }, + "9": { + "attributes": { + "label": "Find Mailings", + "name": "Find Mailings", + "url": "civicrm/mailing?reset=1", + "icon": null, + "permission": "access CiviMail", + "operator": "", + "separator": null, + "parentID": "2", + "navID": "9", + "active": "1" + } + }, + "10": { + "attributes": { + "label": "Find Memberships", + "name": "Find Memberships", + "url": "civicrm/member/search?reset=1", + "icon": null, + "permission": "access CiviMember", + "operator": "", + "separator": null, + "parentID": "2", + "navID": "10", + "active": "1" + } + }, + "11": { + "attributes": { + "label": "Find Participants", + "name": "Find Participants", + "url": "civicrm/event/search?reset=1", + "icon": null, + "permission": "access CiviEvent", + "operator": "", + "separator": null, + "parentID": "2", + "navID": "11", + "active": "1" + } + }, + "12": { + "attributes": { + "label": "Find Pledges", + "name": "Find Pledges", + "url": "civicrm/pledge/search?reset=1", + "icon": null, + "permission": "access CiviPledge", + "operator": "", + "separator": null, + "parentID": "2", + "navID": "12", + "active": "1" + } + }, + "13": { + "attributes": { + "label": "Find Activities", + "name": "Find Activities", + "url": "civicrm/activity/search?reset=1", + "icon": null, + "permission": null, + "operator": "", + "separator": "1", + "parentID": "2", + "navID": "13", + "active": "1" + } + }, + "14": { + "attributes": { + "label": "Custom Searches", + "name": "Custom Searches", + "url": "civicrm/contact/search/custom/list?reset=1", + "icon": null, + "permission": null, + "operator": "", + "separator": null, + "parentID": "2", + "navID": "14", + "active": "1" + } + } + } + }, + "15": { + "attributes": { + "label": "Contacts", + "name": "Contacts", + "url": null, + "icon": "crm-i fa-users", + "permission": null, + "operator": "", + "separator": null, + "parentID": null, + "navID": "15", + "active": "1" + }, + "child": { + "16": { + "attributes": { + "label": "New Individual", + "name": "New Individual", + "url": "civicrm/contact/add?reset=1&ct=Individual", + "icon": null, + "permission": "add contacts", + "operator": "", + "separator": null, + "parentID": "15", + "navID": "16", + "active": "1" + } + }, + "17": { + "attributes": { + "label": "New Household", + "name": "New Household", + "url": "civicrm/contact/add?reset=1&ct=Household", + "icon": null, + "permission": "add contacts", + "operator": "", + "separator": null, + "parentID": "15", + "navID": "17", + "active": "0" + } + }, + "18": { + "attributes": { + "label": "New Organization", + "name": "New Organization", + "url": "civicrm/contact/add?reset=1&ct=Organization", + "icon": null, + "permission": "add contacts", + "operator": "", + "separator": "1", + "parentID": "15", + "navID": "18", + "active": "1" + }, + "child": { + "265": { + "attributes": { + "label": "New Health Insurance Provider", + "name": "New Health_Insurance_Provider", + "url": "civicrm/contact/add?ct=Organization&cst=Health_Insurance_Provider&reset=1", + "icon": null, + "permission": "add contacts", + "operator": null, + "separator": "0", + "parentID": "18", + "navID": "265", + "active": "1" + } + }, + "266": { + "attributes": { + "label": "New Life Insurance Provider", + "name": "New Life_Insurance_Provider", + "url": "civicrm/contact/add?ct=Organization&cst=Life_Insurance_Provider&reset=1", + "icon": null, + "permission": "add contacts", + "operator": null, + "separator": "0", + "parentID": "18", + "navID": "266", + "active": "1" + } + }, + "282": { + "attributes": { + "label": "New Pension Provider", + "name": "New Pension_Provider", + "url": "civicrm/contact/add?ct=Organization&cst=Pension_Provider&reset=1", + "icon": null, + "permission": "add contacts", + "operator": null, + "separator": "0", + "parentID": "18", + "navID": "282", + "active": "1" + } + } + } + }, + "19": { + "attributes": { + "label": "Contact Reports", + "name": "Contact Reports", + "url": "civicrm/report/list?compid=99&reset=1", + "icon": null, + "permission": "access CiviReport", + "operator": "", + "separator": "1", + "parentID": "15", + "navID": "19", + "active": "1" + } + }, + "20": { + "attributes": { + "label": "New Activity", + "name": "New Activity", + "url": "civicrm/activity?reset=1&action=add&context=standalone", + "icon": null, + "permission": null, + "operator": "", + "separator": null, + "parentID": "15", + "navID": "20", + "active": "1" + } + }, + "21": { + "attributes": { + "label": "New Email", + "name": "New Email", + "url": "civicrm/activity/email/add?atype=3&action=add&reset=1&context=standalone", + "icon": null, + "permission": null, + "operator": "", + "separator": "1", + "parentID": "15", + "navID": "21", + "active": "1" + } + }, + "22": { + "attributes": { + "label": "Import Contacts", + "name": "Import Contacts", + "url": "civicrm/import/contact?reset=1", + "icon": null, + "permission": "import contacts", + "operator": "", + "separator": null, + "parentID": "15", + "navID": "22", + "active": "1" + } + }, + "23": { + "attributes": { + "label": "Import Activities", + "name": "Import Activities", + "url": "civicrm/import/activity?reset=1", + "icon": null, + "permission": "import contacts", + "operator": "", + "separator": "1", + "parentID": "15", + "navID": "23", + "active": "1" + } + }, + "24": { + "attributes": { + "label": "New Group", + "name": "New Group", + "url": "civicrm/group/add?reset=1", + "icon": null, + "permission": "edit groups", + "operator": "", + "separator": null, + "parentID": "15", + "navID": "24", + "active": "1" + } + }, + "25": { + "attributes": { + "label": "Manage Groups", + "name": "Manage Groups", + "url": "civicrm/group?reset=1", + "icon": null, + "permission": "access CiviCRM", + "operator": "", + "separator": "1", + "parentID": "15", + "navID": "25", + "active": "1" + } + }, + "26": { + "attributes": { + "label": "New Tag", + "name": "New Tag", + "url": "civicrm/tag?reset=1&action=add", + "icon": null, + "permission": "manage tags", + "operator": "", + "separator": null, + "parentID": "15", + "navID": "26", + "active": "1" + } + }, + "27": { + "attributes": { + "label": "Manage Tags (Categories)", + "name": "Manage Tags (Categories)", + "url": "civicrm/tag?reset=1", + "icon": null, + "permission": "manage tags", + "operator": "", + "separator": "1", + "parentID": "15", + "navID": "27", + "active": "1" + } + }, + "28": { + "attributes": { + "label": "Find and Merge Duplicate Contacts", + "name": "Find and Merge Duplicate Contacts", + "url": "civicrm/contact/deduperules?reset=1", + "icon": null, + "permission": "administer dedupe rules,merge duplicate contacts", + "operator": "OR", + "separator": null, + "parentID": "15", + "navID": "28", + "active": "1" + } + }, + "280": { + "attributes": { + "label": "Import / Export", + "name": "import_export_job_contracts", + "url": null, + "icon": null, + "permission": "access HRJobs", + "operator": null, + "separator": null, + "parentID": "15", + "navID": "280", + "active": "1" + }, + "child": { + "281": { + "attributes": { + "label": "Import Job Contracts", + "name": "import_job_contracts", + "url": "civicrm/job/import", + "icon": null, + "permission": "access HRJobs", + "operator": null, + "separator": "0", + "parentID": "280", + "navID": "281", + "active": "1" + } + } + } + }, + "302": { + "attributes": { + "label": "Import Custom Fields", + "name": "import_custom_fields", + "url": "civicrm/import/custom?reset=1", + "icon": null, + "permission": "access CiviCRM", + "operator": null, + "separator": null, + "parentID": "15", + "navID": "302", + "active": "1" + } + } + } + }, + "29": { + "attributes": { + "label": "Contributions", + "name": "Contributions", + "url": null, + "icon": null, + "permission": "access CiviContribute", + "operator": "", + "separator": null, + "parentID": null, + "navID": "29", + "active": "1" + }, + "child": { + "30": { + "attributes": { + "label": "Dashboard", + "name": "Dashboard", + "url": "civicrm/contribute?reset=1", + "icon": null, + "permission": "access CiviContribute", + "operator": "", + "separator": null, + "parentID": "29", + "navID": "30", + "active": "1" + } + }, + "31": { + "attributes": { + "label": "New Contribution", + "name": "New Contribution", + "url": "civicrm/contribute/add?reset=1&action=add&context=standalone", + "icon": null, + "permission": "access CiviContribute,edit contributions", + "operator": "AND", + "separator": null, + "parentID": "29", + "navID": "31", + "active": "1" + } + }, + "32": { + "attributes": { + "label": "Find Contributions", + "name": "Find Contributions", + "url": "civicrm/contribute/search?reset=1", + "icon": null, + "permission": "access CiviContribute", + "operator": "", + "separator": null, + "parentID": "29", + "navID": "32", + "active": "1" + } + }, + "33": { + "attributes": { + "label": "Contribution Reports", + "name": "Contribution Reports", + "url": "civicrm/report/list?compid=2&reset=1", + "icon": null, + "permission": "access CiviContribute", + "operator": "", + "separator": "1", + "parentID": "29", + "navID": "33", + "active": "1" + } + }, + "34": { + "attributes": { + "label": "Import Contributions", + "name": "Import Contributions", + "url": "civicrm/contribute/import?reset=1", + "icon": null, + "permission": "access CiviContribute,edit contributions", + "operator": "AND", + "separator": "1", + "parentID": "29", + "navID": "34", + "active": "1" + } + }, + "35": { + "attributes": { + "label": "Batch Data Entry", + "name": "Batch Data Entry", + "url": "civicrm/batch?reset=1", + "icon": null, + "permission": "access CiviContribute", + "operator": "", + "separator": null, + "parentID": "29", + "navID": "35", + "active": "1" + } + }, + "36": { + "attributes": { + "label": "Pledges", + "name": "Pledges", + "url": null, + "icon": null, + "permission": "access CiviPledge", + "operator": "", + "separator": "1", + "parentID": "29", + "navID": "36", + "active": "1" + }, + "child": { + "38": { + "attributes": { + "label": "Dashboard", + "name": "Dashboard", + "url": "civicrm/pledge?reset=1", + "icon": null, + "permission": "access CiviPledge", + "operator": "", + "separator": null, + "parentID": "36", + "navID": "38", + "active": "1" + } + }, + "39": { + "attributes": { + "label": "New Pledge", + "name": "New Pledge", + "url": "civicrm/pledge/add?reset=1&action=add&context=standalone", + "icon": null, + "permission": "access CiviPledge,edit pledges", + "operator": "AND", + "separator": null, + "parentID": "36", + "navID": "39", + "active": "1" + } + }, + "40": { + "attributes": { + "label": "Find Pledges", + "name": "Find Pledges", + "url": "civicrm/pledge/search?reset=1", + "icon": null, + "permission": "access CiviPledge", + "operator": "", + "separator": null, + "parentID": "36", + "navID": "40", + "active": "1" + } + }, + "41": { + "attributes": { + "label": "Pledge Reports", + "name": "Pledge Reports", + "url": "civicrm/report/list?compid=6&reset=1", + "icon": null, + "permission": "access CiviPledge", + "operator": "", + "separator": "0", + "parentID": "36", + "navID": "41", + "active": "1" + } + } + } + }, + "37": { + "attributes": { + "label": "Accounting Batches", + "name": "Accounting Batches", + "url": null, + "icon": null, + "permission": "view own manual batches,view all manual batches", + "operator": "OR", + "separator": "1", + "parentID": "29", + "navID": "37", + "active": "1" + }, + "child": { + "48": { + "attributes": { + "label": "New Batch", + "name": "New Batch", + "url": "civicrm/financial/batch?reset=1&action=add", + "icon": null, + "permission": "create manual batch", + "operator": "AND", + "separator": null, + "parentID": "37", + "navID": "48", + "active": "1" + } + }, + "49": { + "attributes": { + "label": "Open Batches", + "name": "Open Batches", + "url": "civicrm/financial/financialbatches?reset=1&batchStatus=1", + "icon": null, + "permission": "view own manual batches,view all manual batches", + "operator": "OR", + "separator": null, + "parentID": "37", + "navID": "49", + "active": "1" + } + }, + "50": { + "attributes": { + "label": "Closed Batches", + "name": "Closed Batches", + "url": "civicrm/financial/financialbatches?reset=1&batchStatus=2", + "icon": null, + "permission": "view own manual batches,view all manual batches", + "operator": "OR", + "separator": null, + "parentID": "37", + "navID": "50", + "active": "1" + } + }, + "51": { + "attributes": { + "label": "Exported Batches", + "name": "Exported Batches", + "url": "civicrm/financial/financialbatches?reset=1&batchStatus=5", + "icon": null, + "permission": "view own manual batches,view all manual batches", + "operator": "OR", + "separator": null, + "parentID": "37", + "navID": "51", + "active": "1" + } + } + } + }, + "42": { + "attributes": { + "label": "New Contribution Page", + "name": "New Contribution Page", + "url": "civicrm/admin/contribute/add?reset=1&action=add", + "icon": null, + "permission": "access CiviContribute,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "29", + "navID": "42", + "active": "1" + } + }, + "43": { + "attributes": { + "label": "Manage Contribution Pages", + "name": "Manage Contribution Pages", + "url": "civicrm/admin/contribute?reset=1", + "icon": null, + "permission": "access CiviContribute,administer CiviCRM", + "operator": "AND", + "separator": "1", + "parentID": "29", + "navID": "43", + "active": "1" + } + }, + "44": { + "attributes": { + "label": "Personal Campaign Pages", + "name": "Personal Campaign Pages", + "url": "civicrm/admin/pcp?reset=1&page_type=contribute", + "icon": null, + "permission": "access CiviContribute,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "29", + "navID": "44", + "active": "1" + } + }, + "45": { + "attributes": { + "label": "Premiums (Thank-you Gifts)", + "name": "Premiums", + "url": "civicrm/admin/contribute/managePremiums?reset=1", + "icon": null, + "permission": "access CiviContribute,administer CiviCRM", + "operator": "AND", + "separator": "1", + "parentID": "29", + "navID": "45", + "active": "1" + } + }, + "46": { + "attributes": { + "label": "New Price Set", + "name": "New Price Set", + "url": "civicrm/admin/price?reset=1&action=add", + "icon": null, + "permission": "access CiviContribute,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "29", + "navID": "46", + "active": "1" + } + }, + "47": { + "attributes": { + "label": "Manage Price Sets", + "name": "Manage Price Sets", + "url": "civicrm/admin/price?reset=1", + "icon": null, + "permission": "access CiviContribute,administer CiviCRM", + "operator": "AND", + "separator": "1", + "parentID": "29", + "navID": "47", + "active": "1" + } + } + } + }, + "52": { + "attributes": { + "label": "Events", + "name": "Events", + "url": null, + "icon": null, + "permission": "access CiviEvent", + "operator": "", + "separator": null, + "parentID": null, + "navID": "52", + "active": "1" + }, + "child": { + "53": { + "attributes": { + "label": "Dashboard", + "name": "CiviEvent Dashboard", + "url": "civicrm/event?reset=1", + "icon": null, + "permission": "access CiviEvent", + "operator": "", + "separator": null, + "parentID": "52", + "navID": "53", + "active": "1" + } + }, + "54": { + "attributes": { + "label": "Register Event Participant", + "name": "Register Event Participant", + "url": "civicrm/participant/add?reset=1&action=add&context=standalone", + "icon": null, + "permission": "access CiviEvent,edit event participants", + "operator": "AND", + "separator": null, + "parentID": "52", + "navID": "54", + "active": "1" + } + }, + "55": { + "attributes": { + "label": "Find Participants", + "name": "Find Participants", + "url": "civicrm/event/search?reset=1", + "icon": null, + "permission": "access CiviEvent", + "operator": "", + "separator": null, + "parentID": "52", + "navID": "55", + "active": "1" + } + }, + "56": { + "attributes": { + "label": "Event Reports", + "name": "Event Reports", + "url": "civicrm/report/list?compid=1&reset=1", + "icon": null, + "permission": "access CiviEvent", + "operator": "", + "separator": "1", + "parentID": "52", + "navID": "56", + "active": "1" + } + }, + "57": { + "attributes": { + "label": "Import Participants", + "name": "Import Participants", + "url": "civicrm/event/import?reset=1", + "icon": null, + "permission": "access CiviEvent,edit event participants", + "operator": "AND", + "separator": "1", + "parentID": "52", + "navID": "57", + "active": "1" + } + }, + "58": { + "attributes": { + "label": "New Event", + "name": "New Event", + "url": "civicrm/event/add?reset=1&action=add", + "icon": null, + "permission": "access CiviEvent,edit all events", + "operator": "AND", + "separator": null, + "parentID": "52", + "navID": "58", + "active": "1" + } + }, + "59": { + "attributes": { + "label": "Manage Events", + "name": "Manage Events", + "url": "civicrm/event/manage?reset=1", + "icon": null, + "permission": "access CiviEvent,edit all events", + "operator": "AND", + "separator": "1", + "parentID": "52", + "navID": "59", + "active": "1" + } + }, + "60": { + "attributes": { + "label": "Personal Campaign Pages", + "name": "Personal Campaign Pages", + "url": "civicrm/admin/pcp?reset=1&page_type=event", + "icon": null, + "permission": "access CiviEvent,administer CiviCRM", + "operator": "AND", + "separator": "1", + "parentID": "52", + "navID": "60", + "active": "1" + } + }, + "61": { + "attributes": { + "label": "Event Templates", + "name": "Event Templates", + "url": "civicrm/admin/eventTemplate?reset=1", + "icon": null, + "permission": "access CiviEvent,edit all events", + "operator": "AND", + "separator": "1", + "parentID": "52", + "navID": "61", + "active": "1" + } + }, + "62": { + "attributes": { + "label": "New Price Set", + "name": "New Price Set", + "url": "civicrm/admin/price?reset=1&action=add", + "icon": null, + "permission": "access CiviEvent,edit all events", + "operator": "AND", + "separator": null, + "parentID": "52", + "navID": "62", + "active": "1" + } + }, + "63": { + "attributes": { + "label": "Manage Price Sets", + "name": "Manage Price Sets", + "url": "civicrm/admin/price?reset=1", + "icon": null, + "permission": "access CiviEvent,edit all events", + "operator": "AND", + "separator": null, + "parentID": "52", + "navID": "63", + "active": "1" + } + } + } + }, + "64": { + "attributes": { + "label": "Mailings", + "name": "Mailings", + "url": null, + "icon": null, + "permission": "access CiviMail,create mailings,approve mailings,schedule mailings", + "operator": "OR", + "separator": null, + "parentID": null, + "navID": "64", + "active": "1" + }, + "child": { + "65": { + "attributes": { + "label": "New Mailing", + "name": "New Mailing", + "url": "civicrm/mailing/send?reset=1", + "icon": null, + "permission": "access CiviMail,create mailings", + "operator": "OR", + "separator": null, + "parentID": "64", + "navID": "65", + "active": "1" + } + }, + "66": { + "attributes": { + "label": "Draft and Unscheduled Mailings", + "name": "Draft and Unscheduled Mailings", + "url": "civicrm/mailing/browse/unscheduled?reset=1&scheduled=false", + "icon": null, + "permission": "access CiviMail,create mailings,schedule mailings", + "operator": "OR", + "separator": null, + "parentID": "64", + "navID": "66", + "active": "1" + } + }, + "67": { + "attributes": { + "label": "Scheduled and Sent Mailings", + "name": "Scheduled and Sent Mailings", + "url": "civicrm/mailing/browse/scheduled?reset=1&scheduled=true", + "icon": null, + "permission": "access CiviMail,approve mailings,create mailings,schedule mailings", + "operator": "OR", + "separator": null, + "parentID": "64", + "navID": "67", + "active": "1" + } + }, + "68": { + "attributes": { + "label": "Archived Mailings", + "name": "Archived Mailings", + "url": "civicrm/mailing/browse/archived?reset=1", + "icon": null, + "permission": "access CiviMail,create mailings", + "operator": "OR", + "separator": null, + "parentID": "64", + "navID": "68", + "active": "1" + } + }, + "69": { + "attributes": { + "label": "Mailing Reports", + "name": "Mailing Reports", + "url": "civicrm/report/list?compid=4&reset=1", + "icon": null, + "permission": "access CiviMail", + "operator": "", + "separator": "1", + "parentID": "64", + "navID": "69", + "active": "1" + } + }, + "70": { + "attributes": { + "label": "Headers, Footers, and Automated Messages", + "name": "Headers, Footers, and Automated Messages", + "url": "civicrm/admin/component?reset=1", + "icon": null, + "permission": "access CiviMail,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "64", + "navID": "70", + "active": "1" + } + }, + "71": { + "attributes": { + "label": "Message Templates", + "name": "Message Templates", + "url": "civicrm/admin/messageTemplates?reset=1", + "icon": null, + "permission": "edit message templates", + "operator": "", + "separator": null, + "parentID": "64", + "navID": "71", + "active": "1" + } + }, + "72": { + "attributes": { + "label": "From Email Addresses", + "name": "From Email Addresses", + "url": "civicrm/admin/options/from_email_address?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": "1", + "parentID": "64", + "navID": "72", + "active": "1" + } + }, + "73": { + "attributes": { + "label": "New SMS", + "name": "New SMS", + "url": "civicrm/sms/send?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": null, + "separator": null, + "parentID": "64", + "navID": "73", + "active": "1" + } + }, + "74": { + "attributes": { + "label": "Find Mass SMS", + "name": "Find Mass SMS", + "url": "civicrm/mailing/browse?reset=1&sms=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": null, + "separator": "1", + "parentID": "64", + "navID": "74", + "active": "1" + } + }, + "75": { + "attributes": { + "label": "New A/B Test", + "name": "New A/B Test", + "url": "civicrm/a/#/abtest/new", + "icon": null, + "permission": "access CiviMail", + "operator": "", + "separator": null, + "parentID": "64", + "navID": "75", + "active": "1" + } + }, + "76": { + "attributes": { + "label": "Manage A/B Tests", + "name": "Manage A/B Tests", + "url": "civicrm/a/#/abtest", + "icon": null, + "permission": "access CiviMail", + "operator": "", + "separator": "1", + "parentID": "64", + "navID": "76", + "active": "1" + } + } + } + }, + "77": { + "attributes": { + "label": "Memberships", + "name": "Memberships", + "url": null, + "icon": null, + "permission": "access CiviMember", + "operator": "", + "separator": null, + "parentID": null, + "navID": "77", + "active": "1" + }, + "child": { + "78": { + "attributes": { + "label": "Dashboard", + "name": "Dashboard", + "url": "civicrm/member?reset=1", + "icon": null, + "permission": "access CiviMember", + "operator": "", + "separator": null, + "parentID": "77", + "navID": "78", + "active": "1" + } + }, + "79": { + "attributes": { + "label": "New Membership", + "name": "New Membership", + "url": "civicrm/member/add?reset=1&action=add&context=standalone", + "icon": null, + "permission": "access CiviMember,edit memberships", + "operator": "AND", + "separator": null, + "parentID": "77", + "navID": "79", + "active": "1" + } + }, + "80": { + "attributes": { + "label": "Find Memberships", + "name": "Find Memberships", + "url": "civicrm/member/search?reset=1", + "icon": null, + "permission": "access CiviMember", + "operator": "", + "separator": null, + "parentID": "77", + "navID": "80", + "active": "1" + } + }, + "81": { + "attributes": { + "label": "Membership Reports", + "name": "Membership Reports", + "url": "civicrm/report/list?compid=3&reset=1", + "icon": null, + "permission": "access CiviMember", + "operator": "", + "separator": "1", + "parentID": "77", + "navID": "81", + "active": "1" + } + }, + "82": { + "attributes": { + "label": "Batch Data Entry", + "name": "Batch Data Entry", + "url": "civicrm/batch?reset=1", + "icon": null, + "permission": "access CiviContribute", + "operator": "", + "separator": null, + "parentID": "77", + "navID": "82", + "active": "1" + } + }, + "83": { + "attributes": { + "label": "Import Memberships", + "name": "Import Members", + "url": "civicrm/member/import?reset=1", + "icon": null, + "permission": "access CiviMember,edit memberships", + "operator": "AND", + "separator": "1", + "parentID": "77", + "navID": "83", + "active": "1" + } + }, + "84": { + "attributes": { + "label": "New Price Set", + "name": "New Price Set", + "url": "civicrm/admin/price?reset=1&action=add", + "icon": null, + "permission": "access CiviMember,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "77", + "navID": "84", + "active": "1" + } + }, + "85": { + "attributes": { + "label": "Manage Price Sets", + "name": "Manage Price Sets", + "url": "civicrm/admin/price?reset=1", + "icon": null, + "permission": "access CiviMember,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "77", + "navID": "85", + "active": "1" + } + } + } + }, + "86": { + "attributes": { + "label": "Campaigns", + "name": "Campaigns", + "url": null, + "icon": null, + "permission": "interview campaign contacts,release campaign contacts,reserve campaign contacts,manage campaign,administer CiviCampaign,gotv campaign contacts", + "operator": "OR", + "separator": null, + "parentID": null, + "navID": "86", + "active": "1" + }, + "child": { + "87": { + "attributes": { + "label": "Dashboard", + "name": "Dashboard", + "url": "civicrm/campaign?reset=1", + "icon": null, + "permission": "manage campaign,administer CiviCampaign", + "operator": "OR", + "separator": null, + "parentID": "86", + "navID": "87", + "active": "1" + }, + "child": { + "88": { + "attributes": { + "label": "Surveys", + "name": "Survey Dashboard", + "url": "civicrm/campaign?reset=1&subPage=survey", + "icon": null, + "permission": "manage campaign,administer CiviCampaign", + "operator": "OR", + "separator": null, + "parentID": "87", + "navID": "88", + "active": "1" + } + }, + "89": { + "attributes": { + "label": "Petitions", + "name": "Petition Dashboard", + "url": "civicrm/campaign?reset=1&subPage=petition", + "icon": null, + "permission": "manage campaign,administer CiviCampaign", + "operator": "OR", + "separator": null, + "parentID": "87", + "navID": "89", + "active": "1" + } + }, + "90": { + "attributes": { + "label": "Campaigns", + "name": "Campaign Dashboard", + "url": "civicrm/campaign?reset=1&subPage=campaign", + "icon": null, + "permission": "manage campaign,administer CiviCampaign", + "operator": "OR", + "separator": null, + "parentID": "87", + "navID": "90", + "active": "1" + } + } + } + }, + "91": { + "attributes": { + "label": "New Campaign", + "name": "New Campaign", + "url": "civicrm/campaign/add?reset=1", + "icon": null, + "permission": "manage campaign,administer CiviCampaign", + "operator": "OR", + "separator": null, + "parentID": "86", + "navID": "91", + "active": "1" + } + }, + "92": { + "attributes": { + "label": "New Survey", + "name": "New Survey", + "url": "civicrm/survey/add?reset=1", + "icon": null, + "permission": "manage campaign,administer CiviCampaign", + "operator": "OR", + "separator": null, + "parentID": "86", + "navID": "92", + "active": "1" + } + }, + "93": { + "attributes": { + "label": "New Petition", + "name": "New Petition", + "url": "civicrm/petition/add?reset=1", + "icon": null, + "permission": "manage campaign,administer CiviCampaign", + "operator": "OR", + "separator": null, + "parentID": "86", + "navID": "93", + "active": "1" + } + }, + "94": { + "attributes": { + "label": "Reserve Respondents", + "name": "Reserve Respondents", + "url": "civicrm/survey/search?reset=1&op=reserve", + "icon": null, + "permission": "administer CiviCampaign,manage campaign,reserve campaign contacts", + "operator": "OR", + "separator": null, + "parentID": "86", + "navID": "94", + "active": "1" + } + }, + "95": { + "attributes": { + "label": "Interview Respondents", + "name": "Interview Respondents", + "url": "civicrm/survey/search?reset=1&op=interview", + "icon": null, + "permission": "administer CiviCampaign,manage campaign,interview campaign contacts", + "operator": "OR", + "separator": null, + "parentID": "86", + "navID": "95", + "active": "1" + } + }, + "96": { + "attributes": { + "label": "Release Respondents", + "name": "Release Respondents", + "url": "civicrm/survey/search?reset=1&op=release", + "icon": null, + "permission": "administer CiviCampaign,manage campaign,release campaign contacts", + "operator": "OR", + "separator": null, + "parentID": "86", + "navID": "96", + "active": "1" + } + }, + "97": { + "attributes": { + "label": "Campaign Reports", + "name": "Campaign Reports", + "url": "civicrm/report/list?compid=9&reset=1", + "icon": null, + "permission": "interview campaign contacts,release campaign contacts,reserve campaign contacts,manage campaign,administer CiviCampaign,gotv campaign contacts", + "operator": "OR", + "separator": "1", + "parentID": "86", + "navID": "97", + "active": "1" + } + }, + "98": { + "attributes": { + "label": "Conduct Survey", + "name": "Conduct Survey", + "url": "civicrm/campaign/vote?reset=1", + "icon": null, + "permission": "administer CiviCampaign,manage campaign,reserve campaign contacts,interview campaign contacts", + "operator": "OR", + "separator": null, + "parentID": "86", + "navID": "98", + "active": "1" + } + }, + "99": { + "attributes": { + "label": "GOTV (Voter Tracking)", + "name": "Voter Listing", + "url": "civicrm/campaign/gotv?reset=1", + "icon": null, + "permission": "administer CiviCampaign,manage campaign,release campaign contacts,gotv campaign contacts", + "operator": "OR", + "separator": null, + "parentID": "86", + "navID": "99", + "active": "1" + } + } + } + }, + "100": { + "attributes": { + "label": "Cases", + "name": "Cases", + "url": null, + "icon": null, + "permission": "access my cases and activities,access all cases and activities", + "operator": "OR", + "separator": null, + "parentID": null, + "navID": "100", + "active": "0" + }, + "child": { + "101": { + "attributes": { + "label": "Dashboard", + "name": "Dashboard", + "url": "civicrm/case?reset=1", + "icon": null, + "permission": "access my cases and activities,access all cases and activities", + "operator": "OR", + "separator": null, + "parentID": "100", + "navID": "101", + "active": "1" + } + }, + "102": { + "attributes": { + "label": "New Case", + "name": "New Case", + "url": "civicrm/case/add?reset=1&action=add&atype=13&context=standalone", + "icon": null, + "permission": "add cases,access all cases and activities", + "operator": "OR", + "separator": null, + "parentID": "100", + "navID": "102", + "active": "1" + } + }, + "103": { + "attributes": { + "label": "Find Cases", + "name": "Find Cases", + "url": "civicrm/case/search?reset=1", + "icon": null, + "permission": "access my cases and activities,access all cases and activities", + "operator": "OR", + "separator": "1", + "parentID": "100", + "navID": "103", + "active": "1" + } + }, + "104": { + "attributes": { + "label": "Case Reports", + "name": "Case Reports", + "url": "civicrm/report/list?compid=7&reset=1", + "icon": null, + "permission": "access my cases and activities,access all cases and activities,administer CiviCase", + "operator": "OR", + "separator": "0", + "parentID": "100", + "navID": "104", + "active": "1" + } + } + } + }, + "105": { + "attributes": { + "label": "Grants", + "name": "Grants", + "url": null, + "icon": null, + "permission": "access CiviGrant", + "operator": "", + "separator": null, + "parentID": null, + "navID": "105", + "active": "1" + }, + "child": { + "106": { + "attributes": { + "label": "Dashboard", + "name": "Dashboard", + "url": "civicrm/grant?reset=1", + "icon": null, + "permission": "access CiviGrant", + "operator": "", + "separator": null, + "parentID": "105", + "navID": "106", + "active": "1" + } + }, + "107": { + "attributes": { + "label": "New Grant", + "name": "New Grant", + "url": "civicrm/grant/add?reset=1&action=add&context=standalone", + "icon": null, + "permission": "access CiviGrant,edit grants", + "operator": "AND", + "separator": null, + "parentID": "105", + "navID": "107", + "active": "1" + } + }, + "108": { + "attributes": { + "label": "Find Grants", + "name": "Find Grants", + "url": "civicrm/grant/search?reset=1", + "icon": null, + "permission": "access CiviGrant", + "operator": "", + "separator": "1", + "parentID": "105", + "navID": "108", + "active": "1" + } + }, + "109": { + "attributes": { + "label": "Grant Reports", + "name": "Grant Reports", + "url": "civicrm/report/list?compid=5&reset=1", + "icon": null, + "permission": "access CiviGrant", + "operator": "", + "separator": "0", + "parentID": "105", + "navID": "109", + "active": "1" + } + } + } + }, + "110": { + "attributes": { + "label": "Administer", + "name": "Administer", + "url": null, + "icon": "crm-i fa-cog", + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": null, + "navID": "110", + "active": "1" + }, + "child": { + "111": { + "attributes": { + "label": "Administration Console", + "name": "Administration Console", + "url": "civicrm/admin?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "110", + "navID": "111", + "active": "1" + }, + "child": { + "112": { + "attributes": { + "label": "System Status", + "name": "System Status", + "url": "civicrm/a/#/status", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "111", + "navID": "112", + "active": "1" + } + }, + "113": { + "attributes": { + "label": "Configuration Checklist", + "name": "Configuration Checklist", + "url": "civicrm/admin/configtask?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "111", + "navID": "113", + "active": "1" + } + } + } + }, + "114": { + "attributes": { + "label": "Customize Data and Screens", + "name": "Customize Data and Screens", + "url": null, + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "110", + "navID": "114", + "active": "1" + }, + "child": { + "115": { + "attributes": { + "label": "Custom Fields", + "name": "Custom Fields", + "url": "civicrm/admin/custom/group?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "114", + "navID": "115", + "active": "1" + } + }, + "116": { + "attributes": { + "label": "Profiles", + "name": "Profiles", + "url": "civicrm/admin/uf/group?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "114", + "navID": "116", + "active": "1" + } + }, + "117": { + "attributes": { + "label": "Tags (Categories)", + "name": "Tags (Categories)", + "url": "civicrm/tag?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "114", + "navID": "117", + "active": "1" + } + }, + "118": { + "attributes": { + "label": "Activity Types", + "name": "Activity Types", + "url": "civicrm/admin/options/activity_type?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "114", + "navID": "118", + "active": "1" + } + }, + "119": { + "attributes": { + "label": "Relationship Types", + "name": "Relationship Types", + "url": "civicrm/admin/reltype?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "114", + "navID": "119", + "active": "1" + } + }, + "120": { + "attributes": { + "label": "Contact Types", + "name": "Contact Types", + "url": "civicrm/admin/options/subtype?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "114", + "navID": "120", + "active": "1" + } + }, + "121": { + "attributes": { + "label": "Display Preferences", + "name": "Display Preferences", + "url": "civicrm/admin/setting/preferences/display?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "114", + "navID": "121", + "active": "1" + } + }, + "122": { + "attributes": { + "label": "Search Preferences", + "name": "Search Preferences", + "url": "civicrm/admin/setting/search?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "114", + "navID": "122", + "active": "1" + } + }, + "123": { + "attributes": { + "label": "Date Preferences", + "name": "Date Preferences", + "url": "civicrm/admin/setting/preferences/date?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "114", + "navID": "123", + "active": "1" + } + }, + "124": { + "attributes": { + "label": "Navigation Menu", + "name": "Navigation Menu", + "url": "civicrm/admin/menu?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "114", + "navID": "124", + "active": "1" + } + }, + "125": { + "attributes": { + "label": "Word Replacements", + "name": "Word Replacements", + "url": "civicrm/admin/options/wordreplacements?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "114", + "navID": "125", + "active": "1" + } + }, + "126": { + "attributes": { + "label": "Manage Custom Searches", + "name": "Manage Custom Searches", + "url": "civicrm/admin/options/custom_search?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "114", + "navID": "126", + "active": "1" + } + }, + "127": { + "attributes": { + "label": "Dropdown Options", + "name": "Dropdown Options", + "url": null, + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "114", + "navID": "127", + "active": "1" + }, + "child": { + "128": { + "attributes": { + "label": "Gender Options", + "name": "Gender Options", + "url": "civicrm/admin/options/gender?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "127", + "navID": "128", + "active": "1" + } + }, + "129": { + "attributes": { + "label": "Individual Prefixes (Ms, Mr...)", + "name": "Individual Prefixes (Ms, Mr...)", + "url": "civicrm/admin/options/individual_prefix?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "127", + "navID": "129", + "active": "1" + } + }, + "130": { + "attributes": { + "label": "Individual Suffixes (Jr, Sr...)", + "name": "Individual Suffixes (Jr, Sr...)", + "url": "civicrm/admin/options/individual_suffix?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "127", + "navID": "130", + "active": "1" + } + }, + "131": { + "attributes": { + "label": "Instant Messenger Services", + "name": "Instant Messenger Services", + "url": "civicrm/admin/options/instant_messenger_service?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "127", + "navID": "131", + "active": "1" + } + }, + "132": { + "attributes": { + "label": "Location Types (Home, Work...)", + "name": "Location Types (Home, Work...)", + "url": "civicrm/admin/locationType?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "127", + "navID": "132", + "active": "1" + } + }, + "133": { + "attributes": { + "label": "Mobile Phone Providers", + "name": "Mobile Phone Providers", + "url": "civicrm/admin/options/mobile_provider?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "127", + "navID": "133", + "active": "1" + } + }, + "134": { + "attributes": { + "label": "Phone Types", + "name": "Phone Types", + "url": "civicrm/admin/options/phone_type?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "127", + "navID": "134", + "active": "1" + } + }, + "135": { + "attributes": { + "label": "Website Types", + "name": "Website Types", + "url": "civicrm/admin/options/website_type?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "127", + "navID": "135", + "active": "1" + } + }, + "267": { + "attributes": { + "label": "Hours Types", + "name": "hoursType", + "url": "civicrm/hour/editoption", + "icon": null, + "permission": "administer CiviCRM", + "operator": null, + "separator": "0", + "parentID": "127", + "navID": "267", + "active": "1" + } + }, + "268": { + "attributes": { + "label": "Job Contract Pay Scale", + "name": "pay_scale", + "url": "civicrm/pay_scale", + "icon": null, + "permission": "administer CiviCRM", + "operator": null, + "separator": "0", + "parentID": "127", + "navID": "268", + "active": "1" + } + }, + "269": { + "attributes": { + "label": "Job Contract Hours/Location", + "name": "hours_location", + "url": "civicrm/hours_location", + "icon": null, + "permission": "administer CiviCRM", + "operator": null, + "separator": "0", + "parentID": "127", + "navID": "269", + "active": "1" + } + }, + "270": { + "attributes": { + "label": "Contract Type", + "name": "hrjc_contract_type", + "url": "civicrm/admin/options/hrjc_contract_type?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": null, + "separator": "0", + "parentID": "127", + "navID": "270", + "active": "1" + } + }, + "271": { + "attributes": { + "label": "Normal place of work", + "name": "hrjc_location", + "url": "civicrm/admin/options/hrjc_location?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": null, + "separator": "0", + "parentID": "127", + "navID": "271", + "active": "1" + } + }, + "272": { + "attributes": { + "label": "Pay cycle", + "name": "hrjc_pay_cycle", + "url": "civicrm/admin/options/hrjc_pay_cycle?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": null, + "separator": "0", + "parentID": "127", + "navID": "272", + "active": "1" + } + }, + "273": { + "attributes": { + "label": "Benefits", + "name": "hrjc_benefit_name", + "url": "civicrm/admin/options/hrjc_benefit_name?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": null, + "separator": "0", + "parentID": "127", + "navID": "273", + "active": "1" + } + }, + "274": { + "attributes": { + "label": "Benefit type", + "name": "hrjc_benefit_type", + "url": "civicrm/admin/options/hrjc_benefit_type?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": null, + "separator": "0", + "parentID": "127", + "navID": "274", + "active": "1" + } + }, + "275": { + "attributes": { + "label": "Deductions", + "name": "hrjc_deduction_name", + "url": "civicrm/admin/options/hrjc_deduction_name?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": null, + "separator": "0", + "parentID": "127", + "navID": "275", + "active": "1" + } + }, + "276": { + "attributes": { + "label": "Deduction type", + "name": "hrjc_deduction_type", + "url": "civicrm/admin/options/hrjc_deduction_type?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": null, + "separator": "0", + "parentID": "127", + "navID": "276", + "active": "1" + } + }, + "278": { + "attributes": { + "label": "Reason for change", + "name": "hrjc_revision_change_reason", + "url": "civicrm/admin/options/hrjc_revision_change_reason?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": null, + "separator": "0", + "parentID": "127", + "navID": "278", + "active": "1" + } + }, + "279": { + "attributes": { + "label": "Reason for Job Contract end", + "name": "hrjc_contract_end_reason", + "url": "civicrm/admin/options/hrjc_contract_end_reason?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": null, + "separator": "0", + "parentID": "127", + "navID": "279", + "active": "1" + } + } + } + } + } + }, + "136": { + "attributes": { + "label": "Communications", + "name": "Communications", + "url": null, + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "110", + "navID": "136", + "active": "1" + }, + "child": { + "137": { + "attributes": { + "label": "Organization Address and Contact Info", + "name": "Organization Address and Contact Info", + "url": "civicrm/admin/domain?action=update&reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "136", + "navID": "137", + "active": "1" + } + }, + "138": { + "attributes": { + "label": "FROM Email Addresses", + "name": "FROM Email Addresses", + "url": "civicrm/admin/options/from_email_address?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "136", + "navID": "138", + "active": "1" + } + }, + "139": { + "attributes": { + "label": "Message Templates", + "name": "Message Templates", + "url": "civicrm/admin/messageTemplates?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "136", + "navID": "139", + "active": "1" + } + }, + "140": { + "attributes": { + "label": "Schedule Reminders", + "name": "Schedule Reminders", + "url": "civicrm/admin/scheduleReminders?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "136", + "navID": "140", + "active": "1" + } + }, + "141": { + "attributes": { + "label": "Preferred Communication Methods", + "name": "Preferred Communication Methods", + "url": "civicrm/admin/options/preferred_communication_method?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "136", + "navID": "141", + "active": "1" + } + }, + "142": { + "attributes": { + "label": "Label Formats", + "name": "Label Formats", + "url": "civicrm/admin/labelFormats?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "136", + "navID": "142", + "active": "1" + } + }, + "143": { + "attributes": { + "label": "Print Page (PDF) Formats", + "name": "Print Page (PDF) Formats", + "url": "civicrm/admin/pdfFormats?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "136", + "navID": "143", + "active": "1" + } + }, + "144": { + "attributes": { + "label": "Communication Style Options", + "name": "Communication Style Options", + "url": "civicrm/admin/options/communication_style?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "136", + "navID": "144", + "active": "1" + } + }, + "145": { + "attributes": { + "label": "Email Greeting Formats", + "name": "Email Greeting Formats", + "url": "civicrm/admin/options/email_greeting?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "136", + "navID": "145", + "active": "1" + } + }, + "146": { + "attributes": { + "label": "Postal Greeting Formats", + "name": "Postal Greeting Formats", + "url": "civicrm/admin/options/postal_greeting?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "136", + "navID": "146", + "active": "1" + } + }, + "147": { + "attributes": { + "label": "Addressee Formats", + "name": "Addressee Formats", + "url": "civicrm/admin/options/addressee?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "136", + "navID": "147", + "active": "1" + } + } + } + }, + "148": { + "attributes": { + "label": "Localization", + "name": "Localization", + "url": null, + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "110", + "navID": "148", + "active": "1" + }, + "child": { + "149": { + "attributes": { + "label": "Languages, Currency, Locations", + "name": "Languages, Currency, Locations", + "url": "civicrm/admin/setting/localization?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "148", + "navID": "149", + "active": "1" + } + }, + "150": { + "attributes": { + "label": "Address Settings", + "name": "Address Settings", + "url": "civicrm/admin/setting/preferences/address?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "148", + "navID": "150", + "active": "1" + } + }, + "151": { + "attributes": { + "label": "Date Formats", + "name": "Date Formats", + "url": "civicrm/admin/setting/date?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "148", + "navID": "151", + "active": "1" + } + }, + "152": { + "attributes": { + "label": "Preferred Language Options", + "name": "Preferred Language Options", + "url": "civicrm/admin/options/languages?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "148", + "navID": "152", + "active": "1" + } + } + } + }, + "153": { + "attributes": { + "label": "Users and Permissions", + "name": "Users and Permissions", + "url": null, + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "110", + "navID": "153", + "active": "1" + }, + "child": { + "154": { + "attributes": { + "label": "Permissions (Access Control)", + "name": "Permissions (Access Control)", + "url": "civicrm/admin/access?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "153", + "navID": "154", + "active": "1" + } + }, + "155": { + "attributes": { + "label": "Synchronize Users to Contacts", + "name": "Synchronize Users to Contacts", + "url": "civicrm/admin/synchUser?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "153", + "navID": "155", + "active": "1" + } + } + } + }, + "156": { + "attributes": { + "label": "System Settings", + "name": "System Settings", + "url": null, + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "110", + "navID": "156", + "active": "1" + }, + "child": { + "157": { + "attributes": { + "label": "Components", + "name": "Enable Components", + "url": "civicrm/admin/setting/component?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "156", + "navID": "157", + "active": "1" + } + }, + "158": { + "attributes": { + "label": "Connections", + "name": "Connections", + "url": "civicrm/a/#/cxn", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "156", + "navID": "158", + "active": "1" + } + }, + "159": { + "attributes": { + "label": "Extensions", + "name": "Manage Extensions", + "url": "civicrm/admin/extensions?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": "1", + "parentID": "156", + "navID": "159", + "active": "1" + } + }, + "160": { + "attributes": { + "label": "Cleanup Caches and Update Paths", + "name": "Cleanup Caches and Update Paths", + "url": "civicrm/admin/setting/updateConfigBackend?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "156", + "navID": "160", + "active": "1" + } + }, + "161": { + "attributes": { + "label": "CMS Database Integration", + "name": "CMS Integration", + "url": "civicrm/admin/setting/uf?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "156", + "navID": "161", + "active": "1" + } + }, + "162": { + "attributes": { + "label": "Debugging and Error Handling", + "name": "Debugging and Error Handling", + "url": "civicrm/admin/setting/debug?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "156", + "navID": "162", + "active": "1" + } + }, + "163": { + "attributes": { + "label": "Directories", + "name": "Directories", + "url": "civicrm/admin/setting/path?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "156", + "navID": "163", + "active": "1" + } + }, + "164": { + "attributes": { + "label": "Import/Export Mappings", + "name": "Import/Export Mappings", + "url": "civicrm/admin/mapping?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "156", + "navID": "164", + "active": "1" + } + }, + "165": { + "attributes": { + "label": "Mapping and Geocoding", + "name": "Mapping and Geocoding", + "url": "civicrm/admin/setting/mapping?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "156", + "navID": "165", + "active": "1" + } + }, + "166": { + "attributes": { + "label": "Misc (Undelete, PDFs, Limits, Logging, Captcha, etc.)", + "name": "Misc (Undelete, PDFs, Limits, Logging, Captcha, etc.)", + "url": "civicrm/admin/setting/misc?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "156", + "navID": "166", + "active": "1" + } + }, + "167": { + "attributes": { + "label": "Multi Site Settings", + "name": "Multi Site Settings", + "url": "civicrm/admin/setting/preferences/multisite?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "156", + "navID": "167", + "active": "1" + } + }, + "168": { + "attributes": { + "label": "Option Groups", + "name": "Option Groups", + "url": "civicrm/admin/options?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "156", + "navID": "168", + "active": "1" + } + }, + "169": { + "attributes": { + "label": "Outbound Email (SMTP/Sendmail)", + "name": "Outbound Email", + "url": "civicrm/admin/setting/smtp?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "156", + "navID": "169", + "active": "1" + } + }, + "170": { + "attributes": { + "label": "Payment Processors", + "name": "Payment Processors", + "url": "civicrm/admin/paymentProcessor?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "156", + "navID": "170", + "active": "1" + } + }, + "171": { + "attributes": { + "label": "Resource URLs", + "name": "Resource URLs", + "url": "civicrm/admin/setting/url?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "156", + "navID": "171", + "active": "1" + } + }, + "172": { + "attributes": { + "label": "Safe File Extensions", + "name": "Safe File Extensions", + "url": "civicrm/admin/options/safe_file_extension?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "156", + "navID": "172", + "active": "1" + } + }, + "173": { + "attributes": { + "label": "Scheduled Jobs", + "name": "Scheduled Jobs", + "url": "civicrm/admin/job?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "156", + "navID": "173", + "active": "1" + } + }, + "174": { + "attributes": { + "label": "SMS Providers", + "name": "SMS Providers", + "url": "civicrm/admin/sms/provider?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "156", + "navID": "174", + "active": "1" + } + } + } + }, + "175": { + "attributes": { + "label": "CiviCampaign", + "name": "CiviCampaign", + "url": null, + "icon": null, + "permission": "administer CiviCampaign,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "110", + "navID": "175", + "active": "1" + }, + "child": { + "176": { + "attributes": { + "label": "Survey Types", + "name": "Survey Types", + "url": "civicrm/admin/campaign/surveyType?reset=1", + "icon": null, + "permission": "administer CiviCampaign", + "operator": "", + "separator": null, + "parentID": "175", + "navID": "176", + "active": "1" + } + }, + "177": { + "attributes": { + "label": "Campaign Types", + "name": "Campaign Types", + "url": "civicrm/admin/options/campaign_type?reset=1", + "icon": null, + "permission": "administer CiviCampaign", + "operator": "", + "separator": null, + "parentID": "175", + "navID": "177", + "active": "1" + } + }, + "178": { + "attributes": { + "label": "Campaign Status", + "name": "Campaign Status", + "url": "civicrm/admin/options/campaign_status?reset=1", + "icon": null, + "permission": "administer CiviCampaign", + "operator": "", + "separator": null, + "parentID": "175", + "navID": "178", + "active": "1" + } + }, + "179": { + "attributes": { + "label": "Engagement Index", + "name": "Engagement Index", + "url": "civicrm/admin/options/engagement_index?reset=1", + "icon": null, + "permission": "administer CiviCampaign", + "operator": "", + "separator": null, + "parentID": "175", + "navID": "179", + "active": "1" + } + }, + "180": { + "attributes": { + "label": "CiviCampaign Component Settings", + "name": "CiviCampaign Component Settings", + "url": "civicrm/admin/setting/preferences/campaign?reset=1", + "icon": null, + "permission": "administer CiviCampaign", + "operator": "", + "separator": null, + "parentID": "175", + "navID": "180", + "active": "1" + } + } + } + }, + "181": { + "attributes": { + "label": "CiviCase", + "name": "CiviCase", + "url": null, + "icon": null, + "permission": "administer CiviCase", + "operator": null, + "separator": null, + "parentID": "110", + "navID": "181", + "active": "1" + }, + "child": { + "182": { + "attributes": { + "label": "CiviCase Settings", + "name": "CiviCase Settings", + "url": "civicrm/admin/setting/case?reset=1", + "icon": null, + "permission": "administer CiviCase", + "operator": null, + "separator": null, + "parentID": "181", + "navID": "182", + "active": "1" + } + }, + "183": { + "attributes": { + "label": "Case Types", + "name": "Case Types", + "url": "civicrm/a/#/caseType", + "icon": null, + "permission": "administer CiviCase", + "operator": null, + "separator": null, + "parentID": "181", + "navID": "183", + "active": "1" + } + }, + "184": { + "attributes": { + "label": "Redaction Rules", + "name": "Redaction Rules", + "url": "civicrm/admin/options/redaction_rule?reset=1", + "icon": null, + "permission": "administer CiviCase", + "operator": null, + "separator": null, + "parentID": "181", + "navID": "184", + "active": "1" + } + }, + "185": { + "attributes": { + "label": "Case Statuses", + "name": "Case Statuses", + "url": "civicrm/admin/options/case_status?reset=1", + "icon": null, + "permission": "administer CiviCase", + "operator": null, + "separator": null, + "parentID": "181", + "navID": "185", + "active": "1" + } + }, + "186": { + "attributes": { + "label": "Encounter Medium", + "name": "Encounter Medium", + "url": "civicrm/admin/options/encounter_medium?reset=1", + "icon": null, + "permission": "administer CiviCase", + "operator": null, + "separator": null, + "parentID": "181", + "navID": "186", + "active": "1" + } + } + } + }, + "187": { + "attributes": { + "label": "CiviContribute", + "name": "CiviContribute", + "url": null, + "icon": null, + "permission": "access CiviContribute,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "110", + "navID": "187", + "active": "1" + }, + "child": { + "188": { + "attributes": { + "label": "New Contribution Page", + "name": "New Contribution Page", + "url": "civicrm/admin/contribute?reset=1&action=add", + "icon": null, + "permission": "access CiviContribute,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "187", + "navID": "188", + "active": "1" + } + }, + "189": { + "attributes": { + "label": "Manage Contribution Pages", + "name": "Manage Contribution Pages", + "url": "civicrm/admin/contribute?reset=1", + "icon": null, + "permission": "access CiviContribute,administer CiviCRM", + "operator": "AND", + "separator": "1", + "parentID": "187", + "navID": "189", + "active": "1" + } + }, + "190": { + "attributes": { + "label": "Personal Campaign Pages", + "name": "Personal Campaign Pages", + "url": "civicrm/admin/pcp?reset=1&page_type=contribute", + "icon": null, + "permission": "access CiviContribute,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "187", + "navID": "190", + "active": "1" + } + }, + "191": { + "attributes": { + "label": "Premiums (Thank-you Gifts)", + "name": "Premiums", + "url": "civicrm/admin/contribute/managePremiums?reset=1", + "icon": null, + "permission": "access CiviContribute,administer CiviCRM", + "operator": "AND", + "separator": "1", + "parentID": "187", + "navID": "191", + "active": "1" + } + }, + "192": { + "attributes": { + "label": "Financial Types", + "name": "Financial Types", + "url": "civicrm/admin/financial/financialType?reset=1", + "icon": null, + "permission": "access CiviContribute,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "187", + "navID": "192", + "active": "1" + } + }, + "193": { + "attributes": { + "label": "Financial Accounts", + "name": "Financial Accounts", + "url": "civicrm/admin/financial/financialAccount?reset=1", + "icon": null, + "permission": "access CiviContribute,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "187", + "navID": "193", + "active": "1" + } + }, + "194": { + "attributes": { + "label": "Payment Methods", + "name": "Payment Instruments", + "url": "civicrm/admin/options/payment_instrument?reset=1", + "icon": null, + "permission": "access CiviContribute,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "187", + "navID": "194", + "active": "1" + } + }, + "195": { + "attributes": { + "label": "Accepted Credit Cards", + "name": "Accepted Credit Cards", + "url": "civicrm/admin/options/accept_creditcard?reset=1", + "icon": null, + "permission": "access CiviContribute,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "187", + "navID": "195", + "active": "1" + } + }, + "196": { + "attributes": { + "label": "Soft Credit Types", + "name": "Soft Credit Types", + "url": "civicrm/admin/options/soft_credit_type?reset=1", + "icon": null, + "permission": "access CiviContribute,administer CiviCRM", + "operator": "AND", + "separator": "1", + "parentID": "187", + "navID": "196", + "active": "1" + } + }, + "197": { + "attributes": { + "label": "New Price Set", + "name": "New Price Set", + "url": "civicrm/admin/price?reset=1&action=add", + "icon": null, + "permission": "access CiviContribute,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "187", + "navID": "197", + "active": "1" + } + }, + "198": { + "attributes": { + "label": "Manage Price Sets", + "name": "Manage Price Sets", + "url": "civicrm/admin/price?reset=1", + "icon": null, + "permission": "access CiviContribute,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "187", + "navID": "198", + "active": "1" + } + }, + "199": { + "attributes": { + "label": "Payment Processors", + "name": "Payment Processors", + "url": "civicrm/admin/paymentProcessor?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "187", + "navID": "199", + "active": "1" + } + }, + "200": { + "attributes": { + "label": "CiviContribute Component Settings", + "name": "CiviContribute Component Settings", + "url": "civicrm/admin/setting/preferences/contribute?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "187", + "navID": "200", + "active": "1" + } + } + } + }, + "201": { + "attributes": { + "label": "CiviEvent", + "name": "CiviEvent", + "url": null, + "icon": null, + "permission": "access CiviEvent,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "110", + "navID": "201", + "active": "1" + }, + "child": { + "202": { + "attributes": { + "label": "New Event", + "name": "New Event", + "url": "civicrm/event/add?reset=1&action=add", + "icon": null, + "permission": "access CiviEvent,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "201", + "navID": "202", + "active": "1" + } + }, + "203": { + "attributes": { + "label": "Manage Events", + "name": "Manage Events", + "url": "civicrm/event/manage?reset=1", + "icon": null, + "permission": "access CiviEvent,administer CiviCRM", + "operator": "AND", + "separator": "1", + "parentID": "201", + "navID": "203", + "active": "1" + } + }, + "204": { + "attributes": { + "label": "Personal Campaign Pages", + "name": "Personal Campaign Pages", + "url": "civicrm/admin/pcp?reset=1&page_type=event", + "icon": null, + "permission": "access CiviEvent,administer CiviCRM", + "operator": "AND", + "separator": "1", + "parentID": "201", + "navID": "204", + "active": "1" + } + }, + "205": { + "attributes": { + "label": "Event Templates", + "name": "Event Templates", + "url": "civicrm/admin/eventTemplate?reset=1", + "icon": null, + "permission": "access CiviEvent,administer CiviCRM", + "operator": "AND", + "separator": "1", + "parentID": "201", + "navID": "205", + "active": "1" + } + }, + "206": { + "attributes": { + "label": "New Price Set", + "name": "New Price Set", + "url": "civicrm/admin/price?reset=1&action=add", + "icon": null, + "permission": "access CiviEvent,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "201", + "navID": "206", + "active": "1" + } + }, + "207": { + "attributes": { + "label": "Manage Price Sets", + "name": "Manage Price Sets", + "url": "civicrm/admin/price?reset=1", + "icon": null, + "permission": "access CiviEvent,administer CiviCRM", + "operator": "AND", + "separator": "1", + "parentID": "201", + "navID": "207", + "active": "1" + } + }, + "208": { + "attributes": { + "label": "Event Types", + "name": "Event Types", + "url": "civicrm/admin/options/event_type?reset=1", + "icon": null, + "permission": "access CiviEvent,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "201", + "navID": "208", + "active": "1" + } + }, + "209": { + "attributes": { + "label": "Participant Statuses", + "name": "Participant Statuses", + "url": "civicrm/admin/participant_status?reset=1", + "icon": null, + "permission": "access CiviEvent,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "201", + "navID": "209", + "active": "1" + } + }, + "210": { + "attributes": { + "label": "Participant Roles", + "name": "Participant Roles", + "url": "civicrm/admin/options/participant_role?reset=1", + "icon": null, + "permission": "access CiviEvent,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "201", + "navID": "210", + "active": "1" + } + }, + "211": { + "attributes": { + "label": "Participant Listing Options", + "name": "Participant Listing Options", + "url": "civicrm/admin/options/participant_listing?reset=1", + "icon": null, + "permission": "access CiviEvent,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "201", + "navID": "211", + "active": "1" + } + }, + "212": { + "attributes": { + "label": "Event Name Badge Layouts", + "name": "Event Name Badge Layouts", + "url": "civicrm/admin/badgelayout?reset=1", + "icon": null, + "permission": "access CiviEvent,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "201", + "navID": "212", + "active": "1" + } + }, + "213": { + "attributes": { + "label": "Payment Processors", + "name": "Payment Processors", + "url": "civicrm/admin/paymentProcessor?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "201", + "navID": "213", + "active": "1" + } + }, + "214": { + "attributes": { + "label": "CiviEvent Component Settings", + "name": "CiviEvent Component Settings", + "url": "civicrm/admin/setting/preferences/event?reset=1", + "icon": null, + "permission": "access CiviEvent,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "201", + "navID": "214", + "active": "1" + } + } + } + }, + "215": { + "attributes": { + "label": "CiviGrant", + "name": "CiviGrant", + "url": null, + "icon": null, + "permission": "access CiviGrant,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "110", + "navID": "215", + "active": "1" + }, + "child": { + "216": { + "attributes": { + "label": "Grant Types", + "name": "Grant Types", + "url": "civicrm/admin/options/grant_type?reset=1", + "icon": null, + "permission": "access CiviGrant,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "215", + "navID": "216", + "active": "1" + } + }, + "217": { + "attributes": { + "label": "Grant Status", + "name": "Grant Status", + "url": "civicrm/admin/options/grant_status?reset=1", + "icon": null, + "permission": "access CiviGrant,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "215", + "navID": "217", + "active": "1" + } + } + } + }, + "218": { + "attributes": { + "label": "CiviMail", + "name": "CiviMail", + "url": null, + "icon": null, + "permission": "access CiviMail,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "110", + "navID": "218", + "active": "1" + }, + "child": { + "219": { + "attributes": { + "label": "Headers, Footers, and Automated Messages", + "name": "Headers, Footers, and Automated Messages", + "url": "civicrm/admin/component?reset=1", + "icon": null, + "permission": "access CiviMail,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "218", + "navID": "219", + "active": "1" + } + }, + "220": { + "attributes": { + "label": "Message Templates", + "name": "Message Templates", + "url": "civicrm/admin/messageTemplates?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "218", + "navID": "220", + "active": "1" + } + }, + "221": { + "attributes": { + "label": "From Email Addresses", + "name": "From Email Addresses", + "url": "civicrm/admin/options/from_email_address?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "218", + "navID": "221", + "active": "1" + } + }, + "222": { + "attributes": { + "label": "Mail Accounts", + "name": "Mail Accounts", + "url": "civicrm/admin/mailSettings?reset=1", + "icon": null, + "permission": "access CiviMail,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "218", + "navID": "222", + "active": "1" + } + }, + "223": { + "attributes": { + "label": "Mailer Settings", + "name": "Mailer Settings", + "url": "civicrm/admin/mail?reset=1", + "icon": null, + "permission": "access CiviMail,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "218", + "navID": "223", + "active": "1" + } + }, + "224": { + "attributes": { + "label": "CiviMail Component Settings", + "name": "CiviMail Component Settings", + "url": "civicrm/admin/setting/preferences/mailing?reset=1", + "icon": null, + "permission": "access CiviMail,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "218", + "navID": "224", + "active": "1" + } + } + } + }, + "225": { + "attributes": { + "label": "CiviMember", + "name": "CiviMember", + "url": null, + "icon": null, + "permission": "access CiviMember,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "110", + "navID": "225", + "active": "1" + }, + "child": { + "226": { + "attributes": { + "label": "Membership Types", + "name": "Membership Types", + "url": "civicrm/admin/member/membershipType?reset=1", + "icon": null, + "permission": "access CiviMember,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "225", + "navID": "226", + "active": "1" + } + }, + "227": { + "attributes": { + "label": "Membership Status Rules", + "name": "Membership Status Rules", + "url": "civicrm/admin/member/membershipStatus?reset=1", + "icon": null, + "permission": "access CiviMember,administer CiviCRM", + "operator": "AND", + "separator": "1", + "parentID": "225", + "navID": "227", + "active": "1" + } + }, + "228": { + "attributes": { + "label": "New Price Set", + "name": "New Price Set", + "url": "civicrm/admin/price?reset=1&action=add", + "icon": null, + "permission": "access CiviMember,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "225", + "navID": "228", + "active": "1" + } + }, + "229": { + "attributes": { + "label": "Manage Price Sets", + "name": "Manage Price Sets", + "url": "civicrm/admin/price?reset=1", + "icon": null, + "permission": "access CiviMember,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "225", + "navID": "229", + "active": "1" + } + }, + "230": { + "attributes": { + "label": "CiviMember Component Settings", + "name": "CiviMember Component Settings", + "url": "civicrm/admin/setting/preferences/member?reset=1", + "icon": null, + "permission": "access CiviMember,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "225", + "navID": "230", + "active": "1" + } + } + } + }, + "231": { + "attributes": { + "label": "CiviReport", + "name": "CiviReport", + "url": null, + "icon": null, + "permission": "access CiviReport,administer CiviCRM", + "operator": "AND", + "separator": null, + "parentID": "110", + "navID": "231", + "active": "1" + }, + "child": { + "232": { + "attributes": { + "label": "All Reports", + "name": "All Reports", + "url": "civicrm/report/list?reset=1", + "icon": null, + "permission": "access CiviReport", + "operator": "", + "separator": null, + "parentID": "231", + "navID": "232", + "active": "1" + } + }, + "233": { + "attributes": { + "label": "Create New Report from Template", + "name": "Create New Report from Template", + "url": "civicrm/admin/report/template/list?reset=1", + "icon": null, + "permission": "administer Reports", + "operator": "", + "separator": null, + "parentID": "231", + "navID": "233", + "active": "1" + } + }, + "234": { + "attributes": { + "label": "Manage Templates", + "name": "Manage Templates", + "url": "civicrm/admin/report/options/report_template?reset=1", + "icon": null, + "permission": "administer Reports", + "operator": "", + "separator": null, + "parentID": "231", + "navID": "234", + "active": "1" + } + }, + "235": { + "attributes": { + "label": "Register Report", + "name": "Register Report", + "url": "civicrm/admin/report/register?reset=1", + "icon": null, + "permission": "administer Reports", + "operator": "", + "separator": null, + "parentID": "231", + "navID": "235", + "active": "1" + } + } + } + }, + "286": { + "attributes": { + "label": "Tasks", + "name": "tasksassignments_administer", + "url": null, + "icon": null, + "permission": null, + "operator": null, + "separator": null, + "parentID": "110", + "navID": "286", + "active": "1" + }, + "child": { + "285": { + "attributes": { + "label": "Tasks Settings", + "name": "ta_settings", + "url": "civicrm/tasksassignments/settings", + "icon": null, + "permission": null, + "operator": null, + "separator": "0", + "parentID": "286", + "navID": "285", + "active": "1" + } + } + } + }, + "292": { + "attributes": { + "label": "Leave", + "name": "leave_and_absences", + "url": null, + "icon": null, + "permission": "administer leave and absences", + "operator": null, + "separator": null, + "parentID": "110", + "navID": "292", + "active": "1" + }, + "child": { + "293": { + "attributes": { + "label": "Leave/Absence Types", + "name": "leave_and_absence_types", + "url": "civicrm/admin/leaveandabsences/types?action=browse&reset=1", + "icon": null, + "permission": "administer leave and absences", + "operator": null, + "separator": "0", + "parentID": "292", + "navID": "293", + "active": "1" + } + }, + "294": { + "attributes": { + "label": "Leave/Absence Periods", + "name": "leave_and_absence_periods", + "url": "civicrm/admin/leaveandabsences/periods?action=browse&reset=1", + "icon": null, + "permission": "administer leave and absences", + "operator": null, + "separator": "0", + "parentID": "292", + "navID": "294", + "active": "1" + } + }, + "295": { + "attributes": { + "label": "Public Holidays", + "name": "leave_and_absence_public_holidays", + "url": "civicrm/admin/leaveandabsences/public_holidays?action=browse&reset=1", + "icon": null, + "permission": "administer leave and absences", + "operator": null, + "separator": "0", + "parentID": "292", + "navID": "295", + "active": "1" + } + }, + "296": { + "attributes": { + "label": "Manage Work Patterns", + "name": "leave_and_absence_manage_work_patterns", + "url": "civicrm/admin/leaveandabsences/work_patterns?action=browse&reset=1", + "icon": null, + "permission": "administer leave and absences", + "operator": null, + "separator": "0", + "parentID": "292", + "navID": "296", + "active": "1" + } + }, + "297": { + "attributes": { + "label": "General Settings", + "name": "leave_and_absence_general_settings", + "url": "civicrm/admin/leaveandabsences/general_settings", + "icon": null, + "permission": "administer leave and absences", + "operator": null, + "separator": "0", + "parentID": "292", + "navID": "297", + "active": "1" + } + }, + "298": { + "attributes": { + "label": "Import Leave/Absence Requests", + "name": "leave_and_absences_import", + "url": "civicrm/admin/leaveandabsences/import", + "icon": null, + "permission": "administer leave and absences", + "operator": null, + "separator": "0", + "parentID": "292", + "navID": "298", + "active": "1" + } + } + } + } + } + }, + "236": { + "attributes": { + "label": "Support", + "name": "Support", + "url": null, + "icon": null, + "permission": null, + "operator": "", + "separator": null, + "parentID": null, + "navID": "236", + "active": "1" + }, + "child": { + "237": { + "attributes": { + "label": "Get started", + "name": "Get started", + "url": "https://civicrm.org/get-started?src=iam", + "icon": null, + "permission": null, + "operator": "AND", + "separator": null, + "parentID": "236", + "navID": "237", + "active": "1" + } + }, + "238": { + "attributes": { + "label": "Documentation", + "name": "Documentation", + "url": "https://civicrm.org/documentation?src=iam", + "icon": null, + "permission": null, + "operator": "AND", + "separator": null, + "parentID": "236", + "navID": "238", + "active": "1" + } + }, + "239": { + "attributes": { + "label": "Ask a question", + "name": "Ask a question", + "url": "https://civicrm.org/ask-a-question?src=iam", + "icon": null, + "permission": null, + "operator": "AND", + "separator": null, + "parentID": "236", + "navID": "239", + "active": "1" + } + }, + "240": { + "attributes": { + "label": "Get expert help", + "name": "Get expert help", + "url": "https://civicrm.org/experts?src=iam", + "icon": null, + "permission": null, + "operator": "AND", + "separator": null, + "parentID": "236", + "navID": "240", + "active": "1" + } + }, + "241": { + "attributes": { + "label": "About CiviCRM", + "name": "About CiviCRM", + "url": "https://civicrm.org/about?src=iam", + "icon": null, + "permission": null, + "operator": "AND", + "separator": "1", + "parentID": "236", + "navID": "241", + "active": "1" + } + }, + "242": { + "attributes": { + "label": "Register your site", + "name": "Register your site", + "url": "https://civicrm.org/register-your-site?src=iam&sid={sid}", + "icon": null, + "permission": null, + "operator": "AND", + "separator": null, + "parentID": "236", + "navID": "242", + "active": "1" + } + }, + "243": { + "attributes": { + "label": "Join CiviCRM", + "name": "Join CiviCRM", + "url": "https://civicrm.org/become-a-member?src=iam&sid={sid}", + "icon": null, + "permission": null, + "operator": "AND", + "separator": null, + "parentID": "236", + "navID": "243", + "active": "1" + } + }, + "244": { + "attributes": { + "label": "Developer", + "name": "Developer", + "url": null, + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": "1", + "parentID": "236", + "navID": "244", + "active": "1" + }, + "child": { + "245": { + "attributes": { + "label": "API Explorer", + "name": "API Explorer", + "url": "civicrm/api", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "244", + "navID": "245", + "active": "1" + } + }, + "246": { + "attributes": { + "label": "Developer Docs", + "name": "Developer Docs", + "url": "https://civicrm.org/developer-documentation?src=iam", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "244", + "navID": "246", + "active": "1" + } + } + } + } + } + }, + "247": { + "attributes": { + "label": "Reports", + "name": "Reports", + "url": null, + "icon": null, + "permission": "access CiviReport", + "operator": "", + "separator": null, + "parentID": null, + "navID": "247", + "active": "1" + }, + "child": { + "248": { + "attributes": { + "label": "Contact Reports", + "name": "Contact Reports", + "url": "civicrm/report/list?compid=99&reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": "0", + "parentID": "247", + "navID": "248", + "active": "1" + } + }, + "249": { + "attributes": { + "label": "Contribution Reports", + "name": "Contribution Reports", + "url": "civicrm/report/list?compid=2&reset=1", + "icon": null, + "permission": "access CiviContribute", + "operator": "", + "separator": "0", + "parentID": "247", + "navID": "249", + "active": "1" + } + }, + "250": { + "attributes": { + "label": "Pledge Reports", + "name": "Pledge Reports", + "url": "civicrm/report/list?compid=6&reset=1", + "icon": null, + "permission": "access CiviPledge", + "operator": "", + "separator": "0", + "parentID": "247", + "navID": "250", + "active": "1" + } + }, + "251": { + "attributes": { + "label": "Event Reports", + "name": "Event Reports", + "url": "civicrm/report/list?compid=1&reset=1", + "icon": null, + "permission": "access CiviEvent", + "operator": "", + "separator": "0", + "parentID": "247", + "navID": "251", + "active": "1" + } + }, + "252": { + "attributes": { + "label": "Mailing Reports", + "name": "Mailing Reports", + "url": "civicrm/report/list?compid=4&reset=1", + "icon": null, + "permission": "access CiviMail", + "operator": "", + "separator": "0", + "parentID": "247", + "navID": "252", + "active": "1" + } + }, + "253": { + "attributes": { + "label": "Membership Reports", + "name": "Membership Reports", + "url": "civicrm/report/list?compid=3&reset=1", + "icon": null, + "permission": "access CiviMember", + "operator": "", + "separator": "0", + "parentID": "247", + "navID": "253", + "active": "1" + } + }, + "254": { + "attributes": { + "label": "Campaign Reports", + "name": "Campaign Reports", + "url": "civicrm/report/list?compid=9&reset=1", + "icon": null, + "permission": "interview campaign contacts,release campaign contacts,reserve campaign contacts,manage campaign,administer CiviCampaign,gotv campaign contacts", + "operator": "OR", + "separator": "0", + "parentID": "247", + "navID": "254", + "active": "1" + } + }, + "255": { + "attributes": { + "label": "Case Reports", + "name": "Case Reports", + "url": "civicrm/report/list?compid=7&reset=1", + "icon": null, + "permission": "access my cases and activities,access all cases and activities,administer CiviCase", + "operator": "OR", + "separator": "0", + "parentID": "247", + "navID": "255", + "active": "1" + } + }, + "256": { + "attributes": { + "label": "Grant Reports", + "name": "Grant Reports", + "url": "civicrm/report/list?compid=5&reset=1", + "icon": null, + "permission": "access CiviGrant", + "operator": "", + "separator": "0", + "parentID": "247", + "navID": "256", + "active": "1" + } + }, + "257": { + "attributes": { + "label": "All Reports", + "name": "All Reports", + "url": "civicrm/report/list?reset=1", + "icon": null, + "permission": "access CiviReport", + "operator": "", + "separator": "1", + "parentID": "247", + "navID": "257", + "active": "1" + } + }, + "258": { + "attributes": { + "label": "My Reports", + "name": "My Reports", + "url": "civicrm/report/list?myreports=1&reset=1", + "icon": null, + "permission": "access CiviReport", + "operator": "", + "separator": "1", + "parentID": "247", + "navID": "258", + "active": "1" + } + } + } + }, + "264": { + "attributes": { + "label": "Reports", + "name": "hr-reports", + "url": "civicrm/reports", + "icon": "fa fa-table", + "permission": "access hrreports", + "operator": null, + "separator": null, + "parentID": null, + "navID": "264", + "active": "1" + } + }, + "283": { + "attributes": { + "label": "Tasks", + "name": "tasksassignments", + "url": "", + "icon": "crm-i fa-list-ul", + "permission": "access Tasks and Assignments", + "operator": null, + "separator": null, + "parentID": null, + "navID": "283", + "active": "1" + }, + "child": { + "287": { + "attributes": { + "label": "Tasks", + "name": "ta_dashboard_tasks", + "url": "civicrm/tasksassignments/dashboard#/tasks", + "icon": null, + "permission": null, + "operator": null, + "separator": "0", + "parentID": "283", + "navID": "287", + "active": "1" + } + }, + "288": { + "attributes": { + "label": "Documents", + "name": "ta_dashboard_documents", + "url": "civicrm/tasksassignments/dashboard#/documents", + "icon": null, + "permission": null, + "operator": null, + "separator": "0", + "parentID": "283", + "navID": "288", + "active": "1" + } + }, + "289": { + "attributes": { + "label": "Calendar", + "name": "ta_dashboard_calendar", + "url": "civicrm/tasksassignments/dashboard#/calendar", + "icon": null, + "permission": null, + "operator": null, + "separator": "0", + "parentID": "283", + "navID": "289", + "active": "1" + } + }, + "290": { + "attributes": { + "label": "Key Dates", + "name": "ta_dashboard_keydates", + "url": "civicrm/tasksassignments/dashboard#/key-dates", + "icon": null, + "permission": null, + "operator": null, + "separator": "0", + "parentID": "283", + "navID": "290", + "active": "1" + } + } + } + }, + "291": { + "attributes": { + "label": "Leave", + "name": "leave_and_absences_dashboard", + "url": null, + "icon": "crm-i fa-briefcase", + "permission": "access leave and absences", + "operator": null, + "separator": null, + "parentID": null, + "navID": "291", + "active": "1" + }, + "child": { + "299": { + "attributes": { + "label": "Leave Requests", + "name": "leave_and_absences_leave_requests", + "url": "civicrm/leaveandabsences/dashboard#/requests", + "icon": null, + "permission": null, + "operator": null, + "separator": "0", + "parentID": "291", + "navID": "299", + "active": "1" + } + }, + "300": { + "attributes": { + "label": "Leave Calendar", + "name": "leave_and_absences_leave_calendar", + "url": "civicrm/leaveandabsences/dashboard#/calendar", + "icon": null, + "permission": null, + "operator": null, + "separator": "0", + "parentID": "291", + "navID": "300", + "active": "1" + } + }, + "301": { + "attributes": { + "label": "Leave Balances", + "name": "leave_and_absences_leave_balances", + "url": "civicrm/leaveandabsences/dashboard#/leave-balances", + "icon": null, + "permission": null, + "operator": null, + "separator": "0", + "parentID": "291", + "navID": "301", + "active": "1" + } + } + } + }, + "303": { + "attributes": { + "label": "Recruitment", + "name": "Vacancies", + "url": null, + "icon": "crm-i fa-user-plus", + "permission": null, + "operator": null, + "separator": null, + "parentID": null, + "navID": "303", + "active": "1" + }, + "child": { + "304": { + "attributes": { + "label": "Dashboard", + "name": "dashboard", + "url": "civicrm/vacancy/dashboard?reset=1", + "icon": null, + "permission": "view Applicants, manage Applicants, evaluate Applicants, administer Vacancy, administer CiviCRM", + "operator": "OR", + "separator": "0", + "parentID": "303", + "navID": "304", + "active": "1" + } + }, + "305": { + "attributes": { + "label": "Public Vacancy List", + "name": "public_list", + "url": "civicrm/vacancy/publiclisting?reset=1", + "icon": null, + "permission": null, + "operator": null, + "separator": "1", + "parentID": "303", + "navID": "305", + "active": "1" + } + }, + "306": { + "attributes": { + "label": "New Vacancy", + "name": "new_vacancy", + "url": "civicrm/vacancy/add?reset=1", + "icon": null, + "permission": "administer Vacancy, administer CiviCRM", + "operator": "OR", + "separator": "0", + "parentID": "303", + "navID": "306", + "active": "1" + } + }, + "307": { + "attributes": { + "label": "New Template", + "name": "new_template", + "url": "civicrm/vacancy/add?reset=1&template=1", + "icon": null, + "permission": "administer Vacancy, administer CiviCRM", + "operator": "OR", + "separator": "0", + "parentID": "303", + "navID": "307", + "active": "1" + } + }, + "308": { + "attributes": { + "label": "New Applicant", + "name": "new_applicant", + "url": null, + "icon": null, + "permission": null, + "operator": null, + "separator": "1", + "parentID": "303", + "navID": "308", + "active": "1" + } + }, + "309": { + "attributes": { + "label": "Find Vacancies", + "name": "find_vacancies", + "url": "civicrm/vacancy/find?reset=1", + "icon": null, + "permission": "view Applicants, manage Applicants, evaluate Applicants, administer Vacancy, administer CiviCRM", + "operator": "OR", + "separator": "0", + "parentID": "303", + "navID": "309", + "active": "1" + } + }, + "310": { + "attributes": { + "label": "Find Templates", + "name": "find_templates", + "url": "civicrm/vacancy/find?reset=1&template=1", + "icon": null, + "permission": "view Applicants, manage Applicants, evaluate Applicants, administer Vacancy, administer CiviCRM", + "operator": "OR", + "separator": "0", + "parentID": "303", + "navID": "310", + "active": "1" + } + }, + "311": { + "attributes": { + "label": "Search by Application Form Fields", + "name": "find_application", + "url": "civicrm/case/search?force=1&type=5&reset=1", + "icon": null, + "permission": "view Applicants, manage Applicants, evaluate Applicants, administer Vacancy, administer CiviCRM", + "operator": "OR", + "separator": "0", + "parentID": "303", + "navID": "311", + "active": "1" + } + }, + "312": { + "attributes": { + "label": "Search by Evaluation Criteria", + "name": "find_evaluation", + "url": "civicrm/activity/search?force=1&type=114&reset=1", + "icon": null, + "permission": "view Applicants, manage Applicants, evaluate Applicants, administer Vacancy, administer CiviCRM", + "operator": "OR", + "separator": "0", + "parentID": "303", + "navID": "312", + "active": "1" + } + } + } + } +} diff --git a/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php new file mode 100644 index 00000000000..f85222fd447 --- /dev/null +++ b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php @@ -0,0 +1,208 @@ +getSampleMenu(); + $result = NavigationMenuHelper::findMenuItemByName($menu, $name); + + if ($exists) { + $foundName = $result['attributes']['name']; + $this->assertEquals($name, $foundName); + } + else { + $this->assertNull($result); + } + } + + public function testInsertionWillAddChildMenuItem() { + $menu = $this->getSampleMenu(); + $name = 'Test Item'; + $newItem = ['name' => $name]; + $parent = 'Dropdown Options'; + NavigationMenuHelper::insertChild($menu, $parent, $newItem); + + $added = NavigationMenuHelper::findMenuItemByName($menu, $name); + $this->assertNotNull($added); + + $parent = NavigationMenuHelper::findMenuItemByName($menu, 'Dropdown Options'); + $children = $parent['child']; + $matchingChildItems = array_filter($children, function ($item) use ($name) { + return $item['attributes']['name'] === $name; + }); + + $this->assertCount(1, $matchingChildItems); + $matchingItem = reset($matchingChildItems); + $this->assertEquals($name, $matchingItem['attributes']['name']); + } + + public function testInsertionWillThrowExceptionWithInvalidPath() { + $expectedError = 'Cannot find parent item "Bar"'; + $this->setExpectedException(\Exception::class, $expectedError); + $menu = []; + $parent = 'Bar'; + NavigationMenuHelper::insertChild($menu, $parent, []); + } + + public function testSettingPermissionWillUpdateItInMenu() { + $menu = $this->getSampleMenu(); + $name = 'System Status'; + NavigationMenuHelper::updatePermissionByName($menu, $name, 'foo'); + $item = NavigationMenuHelper::findMenuItemByName($menu, $name); + + $this->assertEquals('foo', $item['attributes']['permission']); + } + + public function testFetchingWillNotReturnAReference() { + $menu = $this->getSampleMenu(); + $name = 'System Status'; + $item = NavigationMenuHelper::findMenuItemByName($menu, $name); + $item['foo'] = 'bar'; + $sameItem = NavigationMenuHelper::findMenuItemByName($menu, $name); + + $this->assertArrayNotHasKey('foo', $sameItem); + } + + public function testMovingTopLevelMenuItemsWillChangeTheirPositions() { + $menu = $this->getSampleMenu(); + $first = 'Home'; + $second = 'Search...'; + NavigationMenuHelper::relocateAfter($menu, $first, $second); + + $newFirst = reset($menu); + $newSecond = next($menu); + + $this->assertEquals($second, $newFirst['attributes']['name']); + $this->assertEquals($first, $newSecond['attributes']['name']); + } + + public function testMovingNestedItemsWillChangeTheirPositions() { + $nestedName = 'Activity Types'; + $nestedParent = 'Customize Data and Screens'; + $moveAfter = 'Membership Status Rules'; + $targetParent = 'CiviMember'; + + $menu = $this->getSampleMenu(); + NavigationMenuHelper::relocateAfter($menu, $nestedName, $moveAfter); + + $origParent = NavigationMenuHelper::findMenuItemByName($menu, $nestedParent); + $newParent = NavigationMenuHelper::findMenuItemByName($menu, $targetParent); + + $origChildren = $origParent['child']; + $newChildren = $newParent['child']; + $finderFunc = function ($child) use ($nestedName) { + return $child['attributes']['name'] === $nestedName; + }; + $matchingOriginalChildren = array_filter($origChildren, $finderFunc); + $matchingNewChildren = array_filter($newChildren, $finderFunc); + + $this->assertCount(0, $matchingOriginalChildren); + $this->assertCount(1, $matchingNewChildren); + + $newChildrenNames = array_map(function ($item) { + return $item['attributes']['name']; + }, $newChildren); + + $moveAfterPosition = array_search($moveAfter, $newChildrenNames); + $movedItemPosition = array_search($nestedName, $newChildrenNames); + $this->assertEquals($moveAfterPosition + 1, $movedItemPosition); + } + + public function testRemovalWillUnsetElementAndChildren() { + $menu = $this->getSampleMenu(); + $rootElement = 'Administer'; + $childElement = 'Custom Fields'; + NavigationMenuHelper::remove($menu, $rootElement); + + $foundRoot = NavigationMenuHelper::findParentItemName($menu, $rootElement); + $foundChild = NavigationMenuHelper::findParentItemName($menu, $childElement); + $this->assertNull($foundRoot); + $this->assertNull($foundChild); + } + + /** + * @dataProvider menuItemParentNameProvider + * + * @param string $child + * @param string $expected + */ + public function testFetchingParentItemNameWillReturnParentName($child, $expected) { + $menu = $this->getSampleMenu(); + $parentName = NavigationMenuHelper::findParentItemName($menu, $child); + + $this->assertEquals($expected, $parentName); + } + + public function menuItemParentNameProvider() { + return [ + [ + 'Home', + 'root' + ], + [ + 'ta_dashboard_tasks', + 'tasksassignments' + ], + [ + 'hrjc_revision_change_reason', + 'Dropdown Options' + ], + [ + 'I_DO_NOT_EXIST', + NULL + ], + [ + 'Administer', + 'root' + ] + ]; + } + + /** + * @return array + */ + public function menuItemNameProvider() { + return [ + [ + 'Home', + TRUE + ], + [ + 'I_DO_NOT_EXIST', + FALSE + ], + [ + 'About CiviCRM', + TRUE + ], + [ + 'New Life_Insurance_Provider', + TRUE + ] + ]; + } + + /** + * Get a sample navigation menu array + * + * @return array + */ + private function getSampleMenu() { + $jsonFile = __DIR__ . '/../Files/sample_navigation_menu.json'; + $contents = file_get_contents($jsonFile); + + return json_decode($contents, TRUE); + } + +} From 029d27d0c33d73d0d7f079f18374da07ba5d643e Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Wed, 28 Feb 2018 18:25:16 +0000 Subject: [PATCH 013/203] PCHR-3374: Cleanup --- .../HRCore/Helper/NavigationMenuHelper.php | 222 ++++++++++-------- .../Helper/NavigationMenuHelperTest.php | 18 +- 2 files changed, 139 insertions(+), 101 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php index 2b9c8f7f860..b77d27112e4 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php @@ -6,14 +6,27 @@ class CRM_HRCore_Helper_NavigationMenuHelper { /** - * Inserts a navigation menu item at a given place in the hierarchy. + * Recursively search for a menu item by its name + * + * @param array $menu + * @param string $name + * + * @return array|null + * The menu item, if found, or null otherwise + */ + public static function findMenuItemByName($menu, $name) { + return self::findMenuItemReferenceByName($menu, $name); + } + + /** + * Inserts a navigation menu item as a child of the given parent * * @param array $menu * menu hierarchy * @param string $parentName * Name of the parent menu item * @param array $itemAttributes - * Menu you need to insert + * Attributes of item to insert, e.g. ['name' => 'New Item'] */ public static function insertChild(&$menu, $parentName, $itemAttributes) { $parent = &self::findMenuItemReferenceByName($menu, $parentName); @@ -31,63 +44,51 @@ public static function insertChild(&$menu, $parentName, $itemAttributes) { } /** - * @param $menu - * @param $nameOfItemToMove - * @param $nameOfItemBefore - * @throws Exception + * Moves a menu item to after another specified menu item + * + * @param array $menu + * The full menu structure + * @param string $itemToMoveName + * The name of the menu item we want to move + * @param string $precedingItemName + * The name of the item that the target should be inserted after */ - public static function relocateAfter(&$menu, $nameOfItemToMove, $nameOfItemBefore) { - $parentName = self::findParentItemName($menu, $nameOfItemBefore); - - if ($parentName === 'root') { - $children = &$menu; - } - else { - $parent = &self::findMenuItemReferenceByName($menu, $parentName); - $children = &$parent['child']; - } + public static function relocateAfter( + &$menu, + $itemToMoveName, + $precedingItemName + ) { + $siblings = &self::getSiblingsReference($menu, $precedingItemName); + $itemToMove = self::findMenuItemByName($menu, $itemToMoveName); - $itemToMove = self::findMenuItemByName($menu, $nameOfItemToMove); - self::remove($menu, $nameOfItemToMove); + // remove original from the menu + self::remove($menu, $itemToMoveName); - $targetIndex = NULL; - $offset = 1; // because we want to insert it after - $found = FALSE; - foreach ($children as $index => $child) { - if ($child['attributes']['name'] === $nameOfItemBefore) { - $found = TRUE; - break; - } - $offset++; - } + // re-index and find point to insert the new item + $siblings = array_values($siblings); + $insertionIndex = self::getMenuItemIndex($siblings, $precedingItemName); - if (!$found) { - $err = sprintf('Could not find menu item "%s"', $nameOfItemBefore); + if (NULL === $insertionIndex) { + $err = sprintf('Could not find menu item "%s"', $precedingItemName); throw new \Exception($err); } - array_splice($children, $offset, 0, [$itemToMove]); + $insertionIndex++; // we want to insert it after + array_splice($siblings, $insertionIndex, 0, [$itemToMove]); } + /** + * Removes an item from the menu by name + * + * @param array $menu + * @param string $name + */ public static function remove(&$menu, $name) { - $parentName = self::findParentItemName($menu, $name); + $siblings = &self::getSiblingsReference($menu, $name); - if ($parentName === NULL) { - $err = sprintf('Cannot find parent of menu item "%s"', $name); - throw new \Exception($err); - } - - if ($parentName === 'root') { - $children = &$menu; - } - else { - $parent = &self::findMenuItemReferenceByName($menu, $parentName); - $children = &$parent['child']; - } - - foreach ($children as $index => $child) { - if ($child['attributes']['name'] === $name) { - unset($children[$index]); + foreach ($siblings as $index => $sibling) { + if ($sibling['attributes']['name'] === $name) { + unset($siblings[$index]); return; } } @@ -115,16 +116,59 @@ public static function updatePermissionByName(&$menu, $name, $newPermission) { } /** - * Recursively search for a menu item by its name + * Recursively search for a menu item's parent name by the child name + * + * This is a wrapper for a private function that requires a third argument. * * @param array $menu - * @param string $name + * @param string $childName * - * @return array|null - * The menu item, if found, or null otherwise + * @return string|null + * The parent item name, if found, or null otherwise. + * If item is at top level parent name will be 'root' */ - public static function findMenuItemByName($menu, $name) { - return self::findMenuItemReferenceByName($menu, $name); + public static function findParentItemName($menu, $childName) { + return self::findNestedItemParentName($menu, $childName, 'root'); + } + + /** + * Recursively search for a menu item's parent name by the child name + * + * @param array $menu + * The full menu structure + * @param string $childName + * The name of the child we are searching for + * @param string $parentAtThisLevel + * The name of the parent at the current level of nesting + * + * @return string|null + * The parent item name, if found, or null otherwise. + * If item is at top level parent name will be 'root' + */ + private static function findNestedItemParentName( + $menu, + $childName, + $parentAtThisLevel + ) { + foreach ($menu as $item) { + if ($item['attributes']['name'] === $childName) { + return $parentAtThisLevel; + } + if (!empty($item['child'])) { + $children = $item['child']; + $found = self::findNestedItemParentName( + $children, + $childName, + $item['attributes']['name'] + ); + + if ($found) { + return $found; + } + } + } + + return NULL; } /** @@ -158,57 +202,51 @@ private static function &findMenuItemReferenceByName(&$menu, $name) { } /** - * Recursively search for a menu item's parent name by the child name - * - * This is a wrapper for a private function that requires a third argument. + * Returns an array containing all sibling items on the same menu level. + * This includes the target item. * * @param array $menu - * @param string $childName + * The full menu structure + * @param string $name + * The name of the menu item whose siblings we want * - * @return string|null - * The parent item name, if found, or null otherwise. - * If item is at top level parent name will be 'root' + * @return array */ - public static function findParentItemName($menu, $childName - ) { - return self::findParentItemNameFromRoot($menu, $childName, 'root'); + private static function &getSiblingsReference(&$menu, $name) { + $parentName = self::findParentItemName($menu, $name); + + if ($parentName === NULL) { + $err = sprintf('Cannot find parent of menu item "%s"', $name); + throw new \Exception($err); + } + + if ($parentName === 'root') { + $siblings = &$menu; + } + else { + $parent = &self::findMenuItemReferenceByName($menu, $parentName); + $siblings = &$parent['child']; + } + + return $siblings; } /** - * Recursively search for a menu item's parent name by the child name + * Like array_search, but for menu items * - * @param array $menu - * @param string $childName - * @param string $parentName + * @param array $items + * @param string $name * - * @return string|null - * The parent item name, if found, or null otherwise. - * If item is at top level parent name will be 'root' + * @return bool|int */ - private static function findParentItemNameFromRoot( - $menu, - $childName, - $parentName - ) { - foreach ($menu as $item) { - if ($item['attributes']['name'] === $childName) { - return $parentName; - } - if (!empty($item['child'])) { - $children = $item['child']; - $found = self::findParentItemNameFromRoot( - $children, - $childName, - $item['attributes']['name'] - ); - - if ($found) { - return $found; - } + private static function getMenuItemIndex($items, $name) { + foreach ($items as $index => $sibling) { + if ($sibling['attributes']['name'] === $name) { + return $index; } } - return NULL; + return FALSE; } } diff --git a/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php index f85222fd447..752e4235008 100644 --- a/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php +++ b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php @@ -88,21 +88,21 @@ public function testMovingTopLevelMenuItemsWillChangeTheirPositions() { } public function testMovingNestedItemsWillChangeTheirPositions() { - $nestedName = 'Activity Types'; - $nestedParent = 'Customize Data and Screens'; + $itemName = 'Activity Types'; + $originalParent = 'Customize Data and Screens'; $moveAfter = 'Membership Status Rules'; $targetParent = 'CiviMember'; $menu = $this->getSampleMenu(); - NavigationMenuHelper::relocateAfter($menu, $nestedName, $moveAfter); + NavigationMenuHelper::relocateAfter($menu, $itemName, $moveAfter); - $origParent = NavigationMenuHelper::findMenuItemByName($menu, $nestedParent); + $origParent = NavigationMenuHelper::findMenuItemByName($menu, $originalParent); $newParent = NavigationMenuHelper::findMenuItemByName($menu, $targetParent); $origChildren = $origParent['child']; $newChildren = $newParent['child']; - $finderFunc = function ($child) use ($nestedName) { - return $child['attributes']['name'] === $nestedName; + $finderFunc = function ($child) use ($itemName) { + return $child['attributes']['name'] === $itemName; }; $matchingOriginalChildren = array_filter($origChildren, $finderFunc); $matchingNewChildren = array_filter($newChildren, $finderFunc); @@ -115,7 +115,7 @@ public function testMovingNestedItemsWillChangeTheirPositions() { }, $newChildren); $moveAfterPosition = array_search($moveAfter, $newChildrenNames); - $movedItemPosition = array_search($nestedName, $newChildrenNames); + $movedItemPosition = array_search($itemName, $newChildrenNames); $this->assertEquals($moveAfterPosition + 1, $movedItemPosition); } @@ -125,8 +125,8 @@ public function testRemovalWillUnsetElementAndChildren() { $childElement = 'Custom Fields'; NavigationMenuHelper::remove($menu, $rootElement); - $foundRoot = NavigationMenuHelper::findParentItemName($menu, $rootElement); - $foundChild = NavigationMenuHelper::findParentItemName($menu, $childElement); + $foundRoot = NavigationMenuHelper::findMenuItemByName($menu, $rootElement); + $foundChild = NavigationMenuHelper::findMenuItemByName($menu, $childElement); $this->assertNull($foundRoot); $this->assertNull($foundChild); } From d9495d7657f022cd64bab1a108dd1d26c2d01abb Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Tue, 6 Mar 2018 14:09:23 +0000 Subject: [PATCH 014/203] PCHR-3374: Changes to use path instead of item name I realized (too late) that civicrm_navigation does not use any unique constraint on menu item name, so a lot of the functions I had prepared would be unpredictable when the item name was duplicated. I changed all functions to use path instead of item name. Path is still not unique, but it's much less likely to be duplicated (having the same item name in the same submenu doesn't really make sense) --- .../HRCore/Helper/NavigationMenuHelper.php | 176 ++++++++---------- .../Helper/NavigationMenuHelperTest.php | 93 +++++---- 2 files changed, 125 insertions(+), 144 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php index b77d27112e4..69f094e0e7f 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php @@ -9,13 +9,15 @@ class CRM_HRCore_Helper_NavigationMenuHelper { * Recursively search for a menu item by its name * * @param array $menu - * @param string $name + * The menu array to search in + * @param string $path + * The path to the item, e.g. "Events/Dashboard" * * @return array|null * The menu item, if found, or null otherwise */ - public static function findMenuItemByName($menu, $name) { - return self::findMenuItemReferenceByName($menu, $name); + public static function findMenuItemByPath($menu, $path) { + return self::findMenuItemReferenceByPath($menu, $path); } /** @@ -23,16 +25,16 @@ public static function findMenuItemByName($menu, $name) { * * @param array $menu * menu hierarchy - * @param string $parentName - * Name of the parent menu item + * @param string $parentPath + * Path to the parent menu item, e.g. "Events/Dashboard" * @param array $itemAttributes * Attributes of item to insert, e.g. ['name' => 'New Item'] */ - public static function insertChild(&$menu, $parentName, $itemAttributes) { - $parent = &self::findMenuItemReferenceByName($menu, $parentName); + public static function insertChild(&$menu, $parentPath, $itemAttributes) { + $parent = &self::findMenuItemReferenceByPath($menu, $parentPath); if (!$parent) { - $err = sprintf('Cannot find parent item "%s"', $parentName); + $err = sprintf('Cannot find parent item "%s"', $parentPath); throw new \Exception($err); } @@ -48,28 +50,29 @@ public static function insertChild(&$menu, $parentName, $itemAttributes) { * * @param array $menu * The full menu structure - * @param string $itemToMoveName - * The name of the menu item we want to move - * @param string $precedingItemName - * The name of the item that the target should be inserted after + * @param string $itemToMovePath + * The path to the menu item we want to move + * @param string $precedingItemPath + * The path to the item that the target should be inserted after */ public static function relocateAfter( &$menu, - $itemToMoveName, - $precedingItemName + $itemToMovePath, + $precedingItemPath ) { - $siblings = &self::getSiblingsReference($menu, $precedingItemName); - $itemToMove = self::findMenuItemByName($menu, $itemToMoveName); + $siblings = &self::getSiblingsReference($menu, $precedingItemPath); + $itemToMove = self::findMenuItemByPath($menu, $itemToMovePath); // remove original from the menu - self::remove($menu, $itemToMoveName); + self::remove($menu, $itemToMovePath); // re-index and find point to insert the new item $siblings = array_values($siblings); + $precedingItemName = self::getItemNameFromPath($precedingItemPath); $insertionIndex = self::getMenuItemIndex($siblings, $precedingItemName); if (NULL === $insertionIndex) { - $err = sprintf('Could not find menu item "%s"', $precedingItemName); + $err = sprintf('Could not find menu item "%s"', $precedingItemPath); throw new \Exception($err); } @@ -78,16 +81,17 @@ public static function relocateAfter( } /** - * Removes an item from the menu by name + * Removes an item from the menu by path * * @param array $menu - * @param string $name + * @param string $path */ - public static function remove(&$menu, $name) { - $siblings = &self::getSiblingsReference($menu, $name); + public static function remove(&$menu, $path) { + $siblings = &self::getSiblingsReference($menu, $path); + $itemName = self::getItemNameFromPath($path); foreach ($siblings as $index => $sibling) { - if ($sibling['attributes']['name'] === $name) { + if ($sibling['attributes']['name'] === $itemName) { unset($siblings[$index]); return; } @@ -99,84 +103,60 @@ public static function remove(&$menu, $name) { * * @param array $menu * The full menu - * @param string $name - * The name of the target menu item + * @param string $path + * The path to the item, e.g. "Events/Dashboard" * @param string $newPermission * The new permission for accessing this item */ - public static function updatePermissionByName(&$menu, $name, $newPermission) { - $item = &self::findMenuItemReferenceByName($menu, $name); + public static function updatePermissionByPath(&$menu, $path, $newPermission) { + $item = &self::findMenuItemReferenceByPath($menu, $path); if (!$item) { - $err = sprintf('Cannot find menu item with name "%s"', $name); + $err = sprintf('Cannot find menu item with path "%s"', $path); throw new \Exception($err); } $item['attributes']['permission'] = $newPermission; } - /** - * Recursively search for a menu item's parent name by the child name - * - * This is a wrapper for a private function that requires a third argument. - * - * @param array $menu - * @param string $childName - * - * @return string|null - * The parent item name, if found, or null otherwise. - * If item is at top level parent name will be 'root' - */ - public static function findParentItemName($menu, $childName) { - return self::findNestedItemParentName($menu, $childName, 'root'); - } /** - * Recursively search for a menu item's parent name by the child name - * * @param array $menu - * The full menu structure - * @param string $childName - * The name of the child we are searching for - * @param string $parentAtThisLevel - * The name of the parent at the current level of nesting + * The menu array to search in + * @param string $path + * The path to the item, e.g. "Events/Dashboard" * - * @return string|null - * The parent item name, if found, or null otherwise. - * If item is at top level parent name will be 'root' + * @return array|null + * The menu item if found, or NULL if not */ - private static function findNestedItemParentName( - $menu, - $childName, - $parentAtThisLevel - ) { - foreach ($menu as $item) { - if ($item['attributes']['name'] === $childName) { - return $parentAtThisLevel; - } - if (!empty($item['child'])) { - $children = $item['child']; - $found = self::findNestedItemParentName( - $children, - $childName, - $item['attributes']['name'] - ); - - if ($found) { - return $found; - } + private static function &findMenuItemReferenceByPath(&$menu, $path) { + $path = explode('/', $path); + $submenu = &$menu; + + while (count($path) > 1) { + $parentName = array_shift($path); + $submenu = &self::findMenuItemReferenceByName($submenu, $parentName); + if (!isset($submenu['child'])) { + $null = NULL; // must return reference to variable + + return $null; } + $submenu = &$submenu['child']; } - return NULL; + $itemName = array_shift($path); + $item = &self::findMenuItemReferenceByName($submenu, $itemName); + + return $item; } /** - * Recursively search for a menu item by its name. Returns a reference to - * the item. + * Search for a menu item by its name. Returns a reference to the item. * * @param array $menu + * The menu to search, can be a submenu of the full structure * @param string $name + * The name of the item to search for * * @return array|null * The referenced menu item, if found, or null otherwise @@ -186,13 +166,6 @@ private static function &findMenuItemReferenceByName(&$menu, $name) { if ($item['attributes']['name'] === $name) { return $item; } - if (!empty($item['child'])) { - $found = &self::findMenuItemReferenceByName($item['child'], $name); - - if ($found) { - return $found; - } - } } // must return reference to variable @@ -207,25 +180,21 @@ private static function &findMenuItemReferenceByName(&$menu, $name) { * * @param array $menu * The full menu structure - * @param string $name - * The name of the menu item whose siblings we want + * @param string $path + * The path of the menu item whose siblings we want * * @return array */ - private static function &getSiblingsReference(&$menu, $name) { - $parentName = self::findParentItemName($menu, $name); + private static function &getSiblingsReference(&$menu, $path) { + $finalForwardSlashPos = strrpos($path, '/'); - if ($parentName === NULL) { - $err = sprintf('Cannot find parent of menu item "%s"', $name); - throw new \Exception($err); - } - - if ($parentName === 'root') { - $siblings = &$menu; + if (FALSE !== $finalForwardSlashPos) { + $parentPath = substr($path, 0, $finalForwardSlashPos); + $parent = &self::findMenuItemReferenceByPath($menu, $parentPath); + $siblings = &$parent['child']; } else { - $parent = &self::findMenuItemReferenceByName($menu, $parentName); - $siblings = &$parent['child']; + $siblings = &$menu; } return $siblings; @@ -249,4 +218,19 @@ private static function getMenuItemIndex($items, $name) { return FALSE; } + /** + * Gets the last item name in a menu item path + * + * @param string $path + * The path of the menu item, e.g. "Events/Dashboard" + * + * @return string + * The final item in the path, e.g. "Dashboard" + */ + private static function getItemNameFromPath($path) { + $path = explode('/', $path); + + return end($path); + } + } diff --git a/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php index 752e4235008..2663bb38836 100644 --- a/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php +++ b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php @@ -10,16 +10,18 @@ class NavigationMenuHelperTest extends CRM_HRCore_Test_BaseHeadlessTest { /** * @dataProvider menuItemNameProvider * - * @param string $name + * @param string $path * @param bool $exists */ - public function testFindingMenuItemWillReturnExpectedResult($name, $exists) { + public function testFindingMenuItemWillReturnExpectedResult($path, $exists) { $menu = $this->getSampleMenu(); - $result = NavigationMenuHelper::findMenuItemByName($menu, $name); + $result = NavigationMenuHelper::findMenuItemByPath($menu, $path); + $parts = explode('/', $path); + $expectedName = end($parts); if ($exists) { $foundName = $result['attributes']['name']; - $this->assertEquals($name, $foundName); + $this->assertEquals($expectedName, $foundName); } else { $this->assertNull($result); @@ -28,23 +30,25 @@ public function testFindingMenuItemWillReturnExpectedResult($name, $exists) { public function testInsertionWillAddChildMenuItem() { $menu = $this->getSampleMenu(); - $name = 'Test Item'; - $newItem = ['name' => $name]; - $parent = 'Dropdown Options'; - NavigationMenuHelper::insertChild($menu, $parent, $newItem); - - $added = NavigationMenuHelper::findMenuItemByName($menu, $name); + $childName = 'Test Item'; + $newItem = ['name' => $childName]; + $parentName = 'Dropdown Options'; + $parentPath = 'Administer/Customize Data and Screens/' . $parentName; + $childPath = $parentPath . '/' . $childName; + NavigationMenuHelper::insertChild($menu, $parentPath, $newItem); + + $added = NavigationMenuHelper::findMenuItemByPath($menu, $childPath); $this->assertNotNull($added); - $parent = NavigationMenuHelper::findMenuItemByName($menu, 'Dropdown Options'); - $children = $parent['child']; - $matchingChildItems = array_filter($children, function ($item) use ($name) { - return $item['attributes']['name'] === $name; + $parentPath = NavigationMenuHelper::findMenuItemByPath($menu, $parentPath); + $children = $parentPath['child']; + $childMatches = array_filter($children, function ($item) use ($childName) { + return $item['attributes']['name'] === $childName; }); - $this->assertCount(1, $matchingChildItems); - $matchingItem = reset($matchingChildItems); - $this->assertEquals($name, $matchingItem['attributes']['name']); + $this->assertCount(1, $childMatches); + $matchingItem = reset($childMatches); + $this->assertEquals($childName, $matchingItem['attributes']['name']); } public function testInsertionWillThrowExceptionWithInvalidPath() { @@ -57,19 +61,19 @@ public function testInsertionWillThrowExceptionWithInvalidPath() { public function testSettingPermissionWillUpdateItInMenu() { $menu = $this->getSampleMenu(); - $name = 'System Status'; - NavigationMenuHelper::updatePermissionByName($menu, $name, 'foo'); - $item = NavigationMenuHelper::findMenuItemByName($menu, $name); + $path = 'Administer/Administration Console/System Status'; + NavigationMenuHelper::updatePermissionByPath($menu, $path, 'foo'); + $item = NavigationMenuHelper::findMenuItemByPath($menu, $path); $this->assertEquals('foo', $item['attributes']['permission']); } public function testFetchingWillNotReturnAReference() { $menu = $this->getSampleMenu(); - $name = 'System Status'; - $item = NavigationMenuHelper::findMenuItemByName($menu, $name); + $name = 'Administer/Administration Console/System Status'; + $item = NavigationMenuHelper::findMenuItemByPath($menu, $name); $item['foo'] = 'bar'; - $sameItem = NavigationMenuHelper::findMenuItemByName($menu, $name); + $sameItem = NavigationMenuHelper::findMenuItemByPath($menu, $name); $this->assertArrayNotHasKey('foo', $sameItem); } @@ -89,15 +93,17 @@ public function testMovingTopLevelMenuItemsWillChangeTheirPositions() { public function testMovingNestedItemsWillChangeTheirPositions() { $itemName = 'Activity Types'; - $originalParent = 'Customize Data and Screens'; - $moveAfter = 'Membership Status Rules'; - $targetParent = 'CiviMember'; + $originalParentPath = 'Administer/Customize Data and Screens'; + $itemPath = $originalParentPath . '/' . $itemName; + $targetParentPath = 'Administer/CiviMember'; + $precedingItemName = 'Membership Status Rules'; + $moveAfterPath = $targetParentPath . '/' . $precedingItemName; $menu = $this->getSampleMenu(); - NavigationMenuHelper::relocateAfter($menu, $itemName, $moveAfter); + NavigationMenuHelper::relocateAfter($menu, $itemPath, $moveAfterPath); - $origParent = NavigationMenuHelper::findMenuItemByName($menu, $originalParent); - $newParent = NavigationMenuHelper::findMenuItemByName($menu, $targetParent); + $origParent = NavigationMenuHelper::findMenuItemByPath($menu, $originalParentPath); + $newParent = NavigationMenuHelper::findMenuItemByPath($menu, $targetParentPath); $origChildren = $origParent['child']; $newChildren = $newParent['child']; @@ -114,7 +120,7 @@ public function testMovingNestedItemsWillChangeTheirPositions() { return $item['attributes']['name']; }, $newChildren); - $moveAfterPosition = array_search($moveAfter, $newChildrenNames); + $moveAfterPosition = array_search($precedingItemName, $newChildrenNames); $movedItemPosition = array_search($itemName, $newChildrenNames); $this->assertEquals($moveAfterPosition + 1, $movedItemPosition); } @@ -122,28 +128,15 @@ public function testMovingNestedItemsWillChangeTheirPositions() { public function testRemovalWillUnsetElementAndChildren() { $menu = $this->getSampleMenu(); $rootElement = 'Administer'; - $childElement = 'Custom Fields'; + $childElement = 'Administer/Custom Fields'; NavigationMenuHelper::remove($menu, $rootElement); - $foundRoot = NavigationMenuHelper::findMenuItemByName($menu, $rootElement); - $foundChild = NavigationMenuHelper::findMenuItemByName($menu, $childElement); + $foundRoot = NavigationMenuHelper::findMenuItemByPath($menu, $rootElement); + $foundChild = NavigationMenuHelper::findMenuItemByPath($menu, $childElement); $this->assertNull($foundRoot); $this->assertNull($foundChild); } - /** - * @dataProvider menuItemParentNameProvider - * - * @param string $child - * @param string $expected - */ - public function testFetchingParentItemNameWillReturnParentName($child, $expected) { - $menu = $this->getSampleMenu(); - $parentName = NavigationMenuHelper::findParentItemName($menu, $child); - - $this->assertEquals($expected, $parentName); - } - public function menuItemParentNameProvider() { return [ [ @@ -183,11 +176,15 @@ public function menuItemNameProvider() { FALSE ], [ - 'About CiviCRM', + 'Support/About CiviCRM', + TRUE + ], + [ + 'Contacts/New Organization/New Life_Insurance_Provider', TRUE ], [ - 'New Life_Insurance_Provider', + 'Events/Register Event Participant', TRUE ] ]; From cfd7ec8a9161610ad808c150e19dd595d14f40ed Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Wed, 7 Mar 2018 10:33:42 +0000 Subject: [PATCH 015/203] PCHR-3374: Add "relocateBefore" helper function --- .../HRCore/Helper/NavigationMenuHelper.php | 38 +++++ .../Helper/NavigationMenuHelperTest.php | 142 +++++++++++++++--- 2 files changed, 158 insertions(+), 22 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php index 69f094e0e7f..6afcb65480e 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php @@ -45,6 +45,40 @@ public static function insertChild(&$menu, $parentPath, $itemAttributes) { $parent['child'][] = $newItem; } + /** + * Moves a menu item to before another specified menu item + * + * @param $menu + * The full menu structure + * @param $itemToMovePath + * The path to the menu item we want to move + * @param $followingItemPath + * The path to the item that the target should be inserted before + */ + public static function relocateBefore( + &$menu, + $itemToMovePath, + $followingItemPath + ) { + $siblings = &self::getSiblingsReference($menu, $followingItemPath); + $itemToMove = self::findMenuItemByPath($menu, $itemToMovePath); + + // remove original from the menu + self::remove($menu, $itemToMovePath); + + // re-index and find point to insert the new item + $siblings = array_values($siblings); + $followingItemName = self::getItemNameFromPath($followingItemPath); + $insertionIndex = self::getMenuItemIndex($siblings, $followingItemName); + + if (NULL === $insertionIndex) { + $err = sprintf('Could not find menu item "%s"', $followingItemPath); + throw new \Exception($err); + } + + array_splice($siblings, $insertionIndex, 0, [$itemToMove]); + } + /** * Moves a menu item to after another specified menu item * @@ -130,6 +164,10 @@ public static function updatePermissionByPath(&$menu, $path, $newPermission) { * The menu item if found, or NULL if not */ private static function &findMenuItemReferenceByPath(&$menu, $path) { + if ($path === '') { + return $menu; + } + $path = explode('/', $path); $submenu = &$menu; diff --git a/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php index 2663bb38836..6bc8f44bb36 100644 --- a/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php +++ b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php @@ -91,38 +91,116 @@ public function testMovingTopLevelMenuItemsWillChangeTheirPositions() { $this->assertEquals($first, $newSecond['attributes']['name']); } - public function testMovingNestedItemsWillChangeTheirPositions() { - $itemName = 'Activity Types'; - $originalParentPath = 'Administer/Customize Data and Screens'; - $itemPath = $originalParentPath . '/' . $itemName; - $targetParentPath = 'Administer/CiviMember'; - $precedingItemName = 'Membership Status Rules'; - $moveAfterPath = $targetParentPath . '/' . $precedingItemName; + /** + * @dataProvider itemsToMoveProvider + * + * @param string $pathToMove + * @param string $pathBefore + */ + public function testInsertingAfterWillPlaceAfterNamedItem( + $pathToMove, + $pathBefore + ) { + $menu = $this->getSampleMenu(); + $parts = explode('/', $pathToMove); + $itemName = array_pop($parts); + $originalParentPath = implode('/', $parts); + $newParentParts = explode('/', $pathBefore); + $insertBeforeName = array_pop($newParentParts); + $newParentPath = implode('/', $newParentParts); + + NavigationMenuHelper::relocateAfter($menu, $pathToMove, $pathBefore); + $matcherFunc = function ($child) use ($itemName) { + return $child['attributes']['name'] === $itemName; + }; + + if ($originalParentPath !== '') { + $originalParent = NavigationMenuHelper::findMenuItemByPath($menu, $originalParentPath); + $originalChildren = $originalParent['child']; + } else { + $originalChildren = $menu; + } + + if ($newParentPath !== '') { + $newParent = NavigationMenuHelper::findMenuItemByPath($menu, $newParentPath); + $newParentChildren = $newParent['child']; + } else { + $newParentChildren = $menu; + } + + // If it was moved to a different menu, check that it doesn't exist in old + if ($originalParentPath !== $newParentPath) { + $matchingOriginalChildren = array_filter($originalChildren, $matcherFunc); + $matchingNewChildren = array_filter($newParentChildren, $matcherFunc); + + $this->assertCount(0, $matchingOriginalChildren); + $this->assertCount(1, $matchingNewChildren); + } + + $moveTargetMenuNames = array_map(function ($item) { + return $item['attributes']['name']; + }, $newParentChildren); + + $moveBeforePosition = array_search($insertBeforeName, $moveTargetMenuNames); + $movedItemPosition = array_search($itemName, $moveTargetMenuNames); + $this->assertEquals($moveBeforePosition + 1, $movedItemPosition); + } + + /** + * @dataProvider itemsToMoveProvider + * + * @param string $pathToMove + * @param string $pathAfter + */ + public function testInsertingBeforeWillPlaceBeforeNamedItem( + $pathToMove, + $pathAfter + ) { $menu = $this->getSampleMenu(); - NavigationMenuHelper::relocateAfter($menu, $itemPath, $moveAfterPath); + $parts = explode('/', $pathToMove); + $itemName = array_pop($parts); + $originalParentPath = implode('/', $parts); + $newParentParts = explode('/', $pathAfter); + $insertBeforeName = array_pop($newParentParts); + $newParentPath = implode('/', $newParentParts); - $origParent = NavigationMenuHelper::findMenuItemByPath($menu, $originalParentPath); - $newParent = NavigationMenuHelper::findMenuItemByPath($menu, $targetParentPath); + NavigationMenuHelper::relocateBefore($menu, $pathToMove, $pathAfter); - $origChildren = $origParent['child']; - $newChildren = $newParent['child']; - $finderFunc = function ($child) use ($itemName) { + $matcherFunc = function ($child) use ($itemName) { return $child['attributes']['name'] === $itemName; }; - $matchingOriginalChildren = array_filter($origChildren, $finderFunc); - $matchingNewChildren = array_filter($newChildren, $finderFunc); - $this->assertCount(0, $matchingOriginalChildren); - $this->assertCount(1, $matchingNewChildren); + if ($originalParentPath !== '') { + $originalParent = NavigationMenuHelper::findMenuItemByPath($menu, $originalParentPath); + $originalChildren = $originalParent['child']; + } else { + $originalChildren = $menu; + } + + if ($newParentPath !== '') { + $newParent = NavigationMenuHelper::findMenuItemByPath($menu, $newParentPath); + $newParentChildren = $newParent['child']; + } else { + $newParentChildren = $menu; + } + + // If it was moved to a different menu, check that it doesn't exist in old + if ($originalParentPath !== $newParentPath) { + $matchingOriginalChildren = array_filter($originalChildren, $matcherFunc); + $matchingNewChildren = array_filter($newParentChildren, $matcherFunc); - $newChildrenNames = array_map(function ($item) { + $this->assertCount(0, $matchingOriginalChildren); + $this->assertCount(1, $matchingNewChildren); + } + + $moveTargetMenuNames = array_map(function ($item) { return $item['attributes']['name']; - }, $newChildren); + }, $newParentChildren); - $moveAfterPosition = array_search($precedingItemName, $newChildrenNames); - $movedItemPosition = array_search($itemName, $newChildrenNames); - $this->assertEquals($moveAfterPosition + 1, $movedItemPosition); + $moveBeforePosition = array_search($insertBeforeName, $moveTargetMenuNames); + $movedItemPosition = array_search($itemName, $moveTargetMenuNames); + $this->assertEquals($moveBeforePosition - 1, $movedItemPosition); } public function testRemovalWillUnsetElementAndChildren() { @@ -190,6 +268,26 @@ public function menuItemNameProvider() { ]; } + /** + * @return array + */ + public function itemsToMoveProvider() { + return [ + [ + 'Vacancies/new_vacancy', + 'Home' + ], + [ + 'Home', + 'Administer' + ], + [ + 'Administer/Customize Data and Screens/Custom Fields', + 'Contacts/New Organization' + ] + ]; + } + /** * Get a sample navigation menu array * From 3df4aee1c63a73c9df16c3e7e70136d9dfe27ebd Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Wed, 7 Mar 2018 10:49:19 +0000 Subject: [PATCH 016/203] PCHR-3374: Refactoring --- .../HRCore/Helper/NavigationMenuHelper.php | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php index 6afcb65480e..8d2dcde5d12 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php @@ -60,23 +60,7 @@ public static function relocateBefore( $itemToMovePath, $followingItemPath ) { - $siblings = &self::getSiblingsReference($menu, $followingItemPath); - $itemToMove = self::findMenuItemByPath($menu, $itemToMovePath); - - // remove original from the menu - self::remove($menu, $itemToMovePath); - - // re-index and find point to insert the new item - $siblings = array_values($siblings); - $followingItemName = self::getItemNameFromPath($followingItemPath); - $insertionIndex = self::getMenuItemIndex($siblings, $followingItemName); - - if (NULL === $insertionIndex) { - $err = sprintf('Could not find menu item "%s"', $followingItemPath); - throw new \Exception($err); - } - - array_splice($siblings, $insertionIndex, 0, [$itemToMove]); + self::relocateWithOffset($menu, $itemToMovePath, $followingItemPath, -1); } /** @@ -94,7 +78,27 @@ public static function relocateAfter( $itemToMovePath, $precedingItemPath ) { - $siblings = &self::getSiblingsReference($menu, $precedingItemPath); + self::relocateWithOffset($menu, $itemToMovePath, $precedingItemPath); + } + + /** + * @param $menu + * The full menu structure + * @param $itemToMovePath + * The path to the menu item we want to move + * @param $targetSiblingPath + * The path to the sibling the item will be moved next to + * @param int $offset + * How many places the item should be before / after the sibling item. Use + * 0 to place it right after it. + */ + private static function relocateWithOffset( + &$menu, + $itemToMovePath, + $targetSiblingPath, + $offset = 0 + ) { + $siblings = &self::getSiblingsReference($menu, $targetSiblingPath); $itemToMove = self::findMenuItemByPath($menu, $itemToMovePath); // remove original from the menu @@ -102,15 +106,19 @@ public static function relocateAfter( // re-index and find point to insert the new item $siblings = array_values($siblings); - $precedingItemName = self::getItemNameFromPath($precedingItemPath); + $precedingItemName = self::getItemNameFromPath($targetSiblingPath); $insertionIndex = self::getMenuItemIndex($siblings, $precedingItemName); if (NULL === $insertionIndex) { - $err = sprintf('Could not find menu item "%s"', $precedingItemPath); + $err = sprintf('Could not find menu item "%s"', $targetSiblingPath); throw new \Exception($err); } - $insertionIndex++; // we want to insert it after + // array_splice offset should be 1 greater than the target index +/- the + // offset, i.e. if we want to inset 2 after 1 in [1,3] the + // target index is 0, offset is 0 (right after) so insertion index is 1 + $insertionIndex += ($offset + 1); + array_splice($siblings, $insertionIndex, 0, [$itemToMove]); } From 64b141d28b2afc7f1e1a7525cc6c2f31f2404501 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Wed, 7 Mar 2018 11:41:44 +0000 Subject: [PATCH 017/203] PCHR-3374: Reduce size of sample menu JSON file. Update tests --- .../HRCore/Files/sample_navigation_menu.json | 4332 +---------------- .../Helper/NavigationMenuHelperTest.php | 16 +- 2 files changed, 93 insertions(+), 4255 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Files/sample_navigation_menu.json b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Files/sample_navigation_menu.json index e5d18f90d3f..70046e26207 100644 --- a/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Files/sample_navigation_menu.json +++ b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Files/sample_navigation_menu.json @@ -13,190 +13,6 @@ "active": "1" } }, - "2": { - "attributes": { - "label": "Search", - "name": "Search...", - "url": null, - "icon": "crm-i fa-search", - "permission": null, - "operator": "", - "separator": null, - "parentID": null, - "navID": "2", - "active": "1" - }, - "child": { - "3": { - "attributes": { - "label": "Find Contacts", - "name": "Find Contacts", - "url": "civicrm/contact/search?reset=1", - "icon": null, - "permission": null, - "operator": "", - "separator": null, - "parentID": "2", - "navID": "3", - "active": "1" - } - }, - "4": { - "attributes": { - "label": "Advanced Search", - "name": "Advanced Search", - "url": "civicrm/contact/search/advanced?reset=1", - "icon": null, - "permission": null, - "operator": "", - "separator": null, - "parentID": "2", - "navID": "4", - "active": "1" - } - }, - "5": { - "attributes": { - "label": "Full-text Search", - "name": "Full-text Search", - "url": "civicrm/contact/search/custom?csid=15&reset=1", - "icon": null, - "permission": null, - "operator": "", - "separator": null, - "parentID": "2", - "navID": "5", - "active": "1" - } - }, - "6": { - "attributes": { - "label": "Search Builder", - "name": "Search Builder", - "url": "civicrm/contact/search/builder?reset=1", - "icon": null, - "permission": null, - "operator": "", - "separator": "1", - "parentID": "2", - "navID": "6", - "active": "1" - } - }, - "7": { - "attributes": { - "label": "Find Cases", - "name": "Find Cases", - "url": "civicrm/case/search?reset=1", - "icon": null, - "permission": "access my cases and activities,access all cases and activities", - "operator": "OR", - "separator": null, - "parentID": "2", - "navID": "7", - "active": "1" - } - }, - "8": { - "attributes": { - "label": "Find Contributions", - "name": "Find Contributions", - "url": "civicrm/contribute/search?reset=1", - "icon": null, - "permission": "access CiviContribute", - "operator": "", - "separator": null, - "parentID": "2", - "navID": "8", - "active": "1" - } - }, - "9": { - "attributes": { - "label": "Find Mailings", - "name": "Find Mailings", - "url": "civicrm/mailing?reset=1", - "icon": null, - "permission": "access CiviMail", - "operator": "", - "separator": null, - "parentID": "2", - "navID": "9", - "active": "1" - } - }, - "10": { - "attributes": { - "label": "Find Memberships", - "name": "Find Memberships", - "url": "civicrm/member/search?reset=1", - "icon": null, - "permission": "access CiviMember", - "operator": "", - "separator": null, - "parentID": "2", - "navID": "10", - "active": "1" - } - }, - "11": { - "attributes": { - "label": "Find Participants", - "name": "Find Participants", - "url": "civicrm/event/search?reset=1", - "icon": null, - "permission": "access CiviEvent", - "operator": "", - "separator": null, - "parentID": "2", - "navID": "11", - "active": "1" - } - }, - "12": { - "attributes": { - "label": "Find Pledges", - "name": "Find Pledges", - "url": "civicrm/pledge/search?reset=1", - "icon": null, - "permission": "access CiviPledge", - "operator": "", - "separator": null, - "parentID": "2", - "navID": "12", - "active": "1" - } - }, - "13": { - "attributes": { - "label": "Find Activities", - "name": "Find Activities", - "url": "civicrm/activity/search?reset=1", - "icon": null, - "permission": null, - "operator": "", - "separator": "1", - "parentID": "2", - "navID": "13", - "active": "1" - } - }, - "14": { - "attributes": { - "label": "Custom Searches", - "name": "Custom Searches", - "url": "civicrm/contact/search/custom/list?reset=1", - "icon": null, - "permission": null, - "operator": "", - "separator": null, - "parentID": "2", - "navID": "14", - "active": "1" - } - } - } - }, "15": { "attributes": { "label": "Contacts", @@ -211,34 +27,6 @@ "active": "1" }, "child": { - "16": { - "attributes": { - "label": "New Individual", - "name": "New Individual", - "url": "civicrm/contact/add?reset=1&ct=Individual", - "icon": null, - "permission": "add contacts", - "operator": "", - "separator": null, - "parentID": "15", - "navID": "16", - "active": "1" - } - }, - "17": { - "attributes": { - "label": "New Household", - "name": "New Household", - "url": "civicrm/contact/add?reset=1&ct=Household", - "icon": null, - "permission": "add contacts", - "operator": "", - "separator": null, - "parentID": "15", - "navID": "17", - "active": "0" - } - }, "18": { "attributes": { "label": "New Organization", @@ -266,4083 +54,129 @@ "navID": "265", "active": "1" } - }, - "266": { - "attributes": { - "label": "New Life Insurance Provider", - "name": "New Life_Insurance_Provider", - "url": "civicrm/contact/add?ct=Organization&cst=Life_Insurance_Provider&reset=1", - "icon": null, - "permission": "add contacts", - "operator": null, - "separator": "0", - "parentID": "18", - "navID": "266", - "active": "1" - } - }, - "282": { - "attributes": { - "label": "New Pension Provider", - "name": "New Pension_Provider", - "url": "civicrm/contact/add?ct=Organization&cst=Pension_Provider&reset=1", - "icon": null, - "permission": "add contacts", - "operator": null, - "separator": "0", - "parentID": "18", - "navID": "282", - "active": "1" - } } } - }, - "19": { - "attributes": { - "label": "Contact Reports", - "name": "Contact Reports", - "url": "civicrm/report/list?compid=99&reset=1", - "icon": null, - "permission": "access CiviReport", - "operator": "", - "separator": "1", - "parentID": "15", - "navID": "19", - "active": "1" - } - }, - "20": { - "attributes": { - "label": "New Activity", - "name": "New Activity", - "url": "civicrm/activity?reset=1&action=add&context=standalone", - "icon": null, - "permission": null, - "operator": "", - "separator": null, - "parentID": "15", - "navID": "20", - "active": "1" - } - }, - "21": { - "attributes": { - "label": "New Email", - "name": "New Email", - "url": "civicrm/activity/email/add?atype=3&action=add&reset=1&context=standalone", - "icon": null, - "permission": null, - "operator": "", - "separator": "1", - "parentID": "15", - "navID": "21", - "active": "1" - } - }, - "22": { - "attributes": { - "label": "Import Contacts", - "name": "Import Contacts", - "url": "civicrm/import/contact?reset=1", - "icon": null, - "permission": "import contacts", - "operator": "", - "separator": null, - "parentID": "15", - "navID": "22", - "active": "1" - } - }, - "23": { - "attributes": { - "label": "Import Activities", - "name": "Import Activities", - "url": "civicrm/import/activity?reset=1", - "icon": null, - "permission": "import contacts", - "operator": "", - "separator": "1", - "parentID": "15", - "navID": "23", - "active": "1" - } - }, - "24": { - "attributes": { - "label": "New Group", - "name": "New Group", - "url": "civicrm/group/add?reset=1", - "icon": null, - "permission": "edit groups", - "operator": "", - "separator": null, - "parentID": "15", - "navID": "24", - "active": "1" - } - }, - "25": { - "attributes": { - "label": "Manage Groups", - "name": "Manage Groups", - "url": "civicrm/group?reset=1", - "icon": null, - "permission": "access CiviCRM", - "operator": "", - "separator": "1", - "parentID": "15", - "navID": "25", - "active": "1" - } - }, - "26": { - "attributes": { - "label": "New Tag", - "name": "New Tag", - "url": "civicrm/tag?reset=1&action=add", - "icon": null, - "permission": "manage tags", - "operator": "", - "separator": null, - "parentID": "15", - "navID": "26", - "active": "1" - } - }, - "27": { + } + } + }, + "110": { + "attributes": { + "label": "Administer", + "name": "Administer", + "url": null, + "icon": "crm-i fa-cog", + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": null, + "navID": "110", + "active": "1" + }, + "child": { + "111": { "attributes": { - "label": "Manage Tags (Categories)", - "name": "Manage Tags (Categories)", - "url": "civicrm/tag?reset=1", + "label": "Administration Console", + "name": "Administration Console", + "url": "civicrm/admin?reset=1", "icon": null, - "permission": "manage tags", + "permission": "administer CiviCRM", "operator": "", - "separator": "1", - "parentID": "15", - "navID": "27", - "active": "1" - } - }, - "28": { - "attributes": { - "label": "Find and Merge Duplicate Contacts", - "name": "Find and Merge Duplicate Contacts", - "url": "civicrm/contact/deduperules?reset=1", - "icon": null, - "permission": "administer dedupe rules,merge duplicate contacts", - "operator": "OR", - "separator": null, - "parentID": "15", - "navID": "28", - "active": "1" - } - }, - "280": { - "attributes": { - "label": "Import / Export", - "name": "import_export_job_contracts", - "url": null, - "icon": null, - "permission": "access HRJobs", - "operator": null, "separator": null, - "parentID": "15", - "navID": "280", + "parentID": "110", + "navID": "111", "active": "1" }, "child": { - "281": { + "112": { "attributes": { - "label": "Import Job Contracts", - "name": "import_job_contracts", - "url": "civicrm/job/import", + "label": "System Status", + "name": "System Status", + "url": "civicrm/a/#/status", "icon": null, - "permission": "access HRJobs", - "operator": null, - "separator": "0", - "parentID": "280", - "navID": "281", + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "111", + "navID": "112", "active": "1" } } } }, - "302": { + "114": { "attributes": { - "label": "Import Custom Fields", - "name": "import_custom_fields", - "url": "civicrm/import/custom?reset=1", + "label": "Customize Data and Screens", + "name": "Customize Data and Screens", + "url": null, "icon": null, - "permission": "access CiviCRM", - "operator": null, + "permission": "administer CiviCRM", + "operator": "", "separator": null, - "parentID": "15", - "navID": "302", - "active": "1" - } - } - } - }, - "29": { - "attributes": { - "label": "Contributions", - "name": "Contributions", - "url": null, - "icon": null, - "permission": "access CiviContribute", - "operator": "", - "separator": null, - "parentID": null, - "navID": "29", - "active": "1" - }, - "child": { - "30": { - "attributes": { - "label": "Dashboard", - "name": "Dashboard", - "url": "civicrm/contribute?reset=1", - "icon": null, - "permission": "access CiviContribute", - "operator": "", - "separator": null, - "parentID": "29", - "navID": "30", - "active": "1" - } - }, - "31": { - "attributes": { - "label": "New Contribution", - "name": "New Contribution", - "url": "civicrm/contribute/add?reset=1&action=add&context=standalone", - "icon": null, - "permission": "access CiviContribute,edit contributions", - "operator": "AND", - "separator": null, - "parentID": "29", - "navID": "31", - "active": "1" - } - }, - "32": { - "attributes": { - "label": "Find Contributions", - "name": "Find Contributions", - "url": "civicrm/contribute/search?reset=1", - "icon": null, - "permission": "access CiviContribute", - "operator": "", - "separator": null, - "parentID": "29", - "navID": "32", - "active": "1" - } - }, - "33": { - "attributes": { - "label": "Contribution Reports", - "name": "Contribution Reports", - "url": "civicrm/report/list?compid=2&reset=1", - "icon": null, - "permission": "access CiviContribute", - "operator": "", - "separator": "1", - "parentID": "29", - "navID": "33", - "active": "1" - } - }, - "34": { - "attributes": { - "label": "Import Contributions", - "name": "Import Contributions", - "url": "civicrm/contribute/import?reset=1", - "icon": null, - "permission": "access CiviContribute,edit contributions", - "operator": "AND", - "separator": "1", - "parentID": "29", - "navID": "34", - "active": "1" - } - }, - "35": { - "attributes": { - "label": "Batch Data Entry", - "name": "Batch Data Entry", - "url": "civicrm/batch?reset=1", - "icon": null, - "permission": "access CiviContribute", - "operator": "", - "separator": null, - "parentID": "29", - "navID": "35", - "active": "1" - } - }, - "36": { - "attributes": { - "label": "Pledges", - "name": "Pledges", - "url": null, - "icon": null, - "permission": "access CiviPledge", - "operator": "", - "separator": "1", - "parentID": "29", - "navID": "36", - "active": "1" - }, - "child": { - "38": { - "attributes": { - "label": "Dashboard", - "name": "Dashboard", - "url": "civicrm/pledge?reset=1", - "icon": null, - "permission": "access CiviPledge", - "operator": "", - "separator": null, - "parentID": "36", - "navID": "38", - "active": "1" - } - }, - "39": { - "attributes": { - "label": "New Pledge", - "name": "New Pledge", - "url": "civicrm/pledge/add?reset=1&action=add&context=standalone", - "icon": null, - "permission": "access CiviPledge,edit pledges", - "operator": "AND", - "separator": null, - "parentID": "36", - "navID": "39", - "active": "1" - } - }, - "40": { - "attributes": { - "label": "Find Pledges", - "name": "Find Pledges", - "url": "civicrm/pledge/search?reset=1", - "icon": null, - "permission": "access CiviPledge", - "operator": "", - "separator": null, - "parentID": "36", - "navID": "40", - "active": "1" - } - }, - "41": { - "attributes": { - "label": "Pledge Reports", - "name": "Pledge Reports", - "url": "civicrm/report/list?compid=6&reset=1", - "icon": null, - "permission": "access CiviPledge", - "operator": "", - "separator": "0", - "parentID": "36", - "navID": "41", - "active": "1" - } - } - } - }, - "37": { - "attributes": { - "label": "Accounting Batches", - "name": "Accounting Batches", - "url": null, - "icon": null, - "permission": "view own manual batches,view all manual batches", - "operator": "OR", - "separator": "1", - "parentID": "29", - "navID": "37", - "active": "1" - }, - "child": { - "48": { - "attributes": { - "label": "New Batch", - "name": "New Batch", - "url": "civicrm/financial/batch?reset=1&action=add", - "icon": null, - "permission": "create manual batch", - "operator": "AND", - "separator": null, - "parentID": "37", - "navID": "48", - "active": "1" - } - }, - "49": { - "attributes": { - "label": "Open Batches", - "name": "Open Batches", - "url": "civicrm/financial/financialbatches?reset=1&batchStatus=1", - "icon": null, - "permission": "view own manual batches,view all manual batches", - "operator": "OR", - "separator": null, - "parentID": "37", - "navID": "49", - "active": "1" - } - }, - "50": { - "attributes": { - "label": "Closed Batches", - "name": "Closed Batches", - "url": "civicrm/financial/financialbatches?reset=1&batchStatus=2", - "icon": null, - "permission": "view own manual batches,view all manual batches", - "operator": "OR", - "separator": null, - "parentID": "37", - "navID": "50", - "active": "1" - } - }, - "51": { - "attributes": { - "label": "Exported Batches", - "name": "Exported Batches", - "url": "civicrm/financial/financialbatches?reset=1&batchStatus=5", - "icon": null, - "permission": "view own manual batches,view all manual batches", - "operator": "OR", - "separator": null, - "parentID": "37", - "navID": "51", - "active": "1" - } - } - } - }, - "42": { - "attributes": { - "label": "New Contribution Page", - "name": "New Contribution Page", - "url": "civicrm/admin/contribute/add?reset=1&action=add", - "icon": null, - "permission": "access CiviContribute,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "29", - "navID": "42", - "active": "1" - } - }, - "43": { - "attributes": { - "label": "Manage Contribution Pages", - "name": "Manage Contribution Pages", - "url": "civicrm/admin/contribute?reset=1", - "icon": null, - "permission": "access CiviContribute,administer CiviCRM", - "operator": "AND", - "separator": "1", - "parentID": "29", - "navID": "43", - "active": "1" - } - }, - "44": { - "attributes": { - "label": "Personal Campaign Pages", - "name": "Personal Campaign Pages", - "url": "civicrm/admin/pcp?reset=1&page_type=contribute", - "icon": null, - "permission": "access CiviContribute,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "29", - "navID": "44", - "active": "1" - } - }, - "45": { - "attributes": { - "label": "Premiums (Thank-you Gifts)", - "name": "Premiums", - "url": "civicrm/admin/contribute/managePremiums?reset=1", - "icon": null, - "permission": "access CiviContribute,administer CiviCRM", - "operator": "AND", - "separator": "1", - "parentID": "29", - "navID": "45", - "active": "1" - } - }, - "46": { - "attributes": { - "label": "New Price Set", - "name": "New Price Set", - "url": "civicrm/admin/price?reset=1&action=add", - "icon": null, - "permission": "access CiviContribute,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "29", - "navID": "46", - "active": "1" - } - }, - "47": { - "attributes": { - "label": "Manage Price Sets", - "name": "Manage Price Sets", - "url": "civicrm/admin/price?reset=1", - "icon": null, - "permission": "access CiviContribute,administer CiviCRM", - "operator": "AND", - "separator": "1", - "parentID": "29", - "navID": "47", - "active": "1" - } - } - } - }, - "52": { - "attributes": { - "label": "Events", - "name": "Events", - "url": null, - "icon": null, - "permission": "access CiviEvent", - "operator": "", - "separator": null, - "parentID": null, - "navID": "52", - "active": "1" - }, - "child": { - "53": { - "attributes": { - "label": "Dashboard", - "name": "CiviEvent Dashboard", - "url": "civicrm/event?reset=1", - "icon": null, - "permission": "access CiviEvent", - "operator": "", - "separator": null, - "parentID": "52", - "navID": "53", - "active": "1" - } - }, - "54": { - "attributes": { - "label": "Register Event Participant", - "name": "Register Event Participant", - "url": "civicrm/participant/add?reset=1&action=add&context=standalone", - "icon": null, - "permission": "access CiviEvent,edit event participants", - "operator": "AND", - "separator": null, - "parentID": "52", - "navID": "54", - "active": "1" - } - }, - "55": { - "attributes": { - "label": "Find Participants", - "name": "Find Participants", - "url": "civicrm/event/search?reset=1", - "icon": null, - "permission": "access CiviEvent", - "operator": "", - "separator": null, - "parentID": "52", - "navID": "55", - "active": "1" - } - }, - "56": { - "attributes": { - "label": "Event Reports", - "name": "Event Reports", - "url": "civicrm/report/list?compid=1&reset=1", - "icon": null, - "permission": "access CiviEvent", - "operator": "", - "separator": "1", - "parentID": "52", - "navID": "56", - "active": "1" - } - }, - "57": { - "attributes": { - "label": "Import Participants", - "name": "Import Participants", - "url": "civicrm/event/import?reset=1", - "icon": null, - "permission": "access CiviEvent,edit event participants", - "operator": "AND", - "separator": "1", - "parentID": "52", - "navID": "57", - "active": "1" - } - }, - "58": { - "attributes": { - "label": "New Event", - "name": "New Event", - "url": "civicrm/event/add?reset=1&action=add", - "icon": null, - "permission": "access CiviEvent,edit all events", - "operator": "AND", - "separator": null, - "parentID": "52", - "navID": "58", - "active": "1" - } - }, - "59": { - "attributes": { - "label": "Manage Events", - "name": "Manage Events", - "url": "civicrm/event/manage?reset=1", - "icon": null, - "permission": "access CiviEvent,edit all events", - "operator": "AND", - "separator": "1", - "parentID": "52", - "navID": "59", - "active": "1" - } - }, - "60": { - "attributes": { - "label": "Personal Campaign Pages", - "name": "Personal Campaign Pages", - "url": "civicrm/admin/pcp?reset=1&page_type=event", - "icon": null, - "permission": "access CiviEvent,administer CiviCRM", - "operator": "AND", - "separator": "1", - "parentID": "52", - "navID": "60", - "active": "1" - } - }, - "61": { - "attributes": { - "label": "Event Templates", - "name": "Event Templates", - "url": "civicrm/admin/eventTemplate?reset=1", - "icon": null, - "permission": "access CiviEvent,edit all events", - "operator": "AND", - "separator": "1", - "parentID": "52", - "navID": "61", - "active": "1" - } - }, - "62": { - "attributes": { - "label": "New Price Set", - "name": "New Price Set", - "url": "civicrm/admin/price?reset=1&action=add", - "icon": null, - "permission": "access CiviEvent,edit all events", - "operator": "AND", - "separator": null, - "parentID": "52", - "navID": "62", - "active": "1" - } - }, - "63": { - "attributes": { - "label": "Manage Price Sets", - "name": "Manage Price Sets", - "url": "civicrm/admin/price?reset=1", - "icon": null, - "permission": "access CiviEvent,edit all events", - "operator": "AND", - "separator": null, - "parentID": "52", - "navID": "63", - "active": "1" - } - } - } - }, - "64": { - "attributes": { - "label": "Mailings", - "name": "Mailings", - "url": null, - "icon": null, - "permission": "access CiviMail,create mailings,approve mailings,schedule mailings", - "operator": "OR", - "separator": null, - "parentID": null, - "navID": "64", - "active": "1" - }, - "child": { - "65": { - "attributes": { - "label": "New Mailing", - "name": "New Mailing", - "url": "civicrm/mailing/send?reset=1", - "icon": null, - "permission": "access CiviMail,create mailings", - "operator": "OR", - "separator": null, - "parentID": "64", - "navID": "65", - "active": "1" - } - }, - "66": { - "attributes": { - "label": "Draft and Unscheduled Mailings", - "name": "Draft and Unscheduled Mailings", - "url": "civicrm/mailing/browse/unscheduled?reset=1&scheduled=false", - "icon": null, - "permission": "access CiviMail,create mailings,schedule mailings", - "operator": "OR", - "separator": null, - "parentID": "64", - "navID": "66", - "active": "1" - } - }, - "67": { - "attributes": { - "label": "Scheduled and Sent Mailings", - "name": "Scheduled and Sent Mailings", - "url": "civicrm/mailing/browse/scheduled?reset=1&scheduled=true", - "icon": null, - "permission": "access CiviMail,approve mailings,create mailings,schedule mailings", - "operator": "OR", - "separator": null, - "parentID": "64", - "navID": "67", - "active": "1" - } - }, - "68": { - "attributes": { - "label": "Archived Mailings", - "name": "Archived Mailings", - "url": "civicrm/mailing/browse/archived?reset=1", - "icon": null, - "permission": "access CiviMail,create mailings", - "operator": "OR", - "separator": null, - "parentID": "64", - "navID": "68", - "active": "1" - } - }, - "69": { - "attributes": { - "label": "Mailing Reports", - "name": "Mailing Reports", - "url": "civicrm/report/list?compid=4&reset=1", - "icon": null, - "permission": "access CiviMail", - "operator": "", - "separator": "1", - "parentID": "64", - "navID": "69", - "active": "1" - } - }, - "70": { - "attributes": { - "label": "Headers, Footers, and Automated Messages", - "name": "Headers, Footers, and Automated Messages", - "url": "civicrm/admin/component?reset=1", - "icon": null, - "permission": "access CiviMail,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "64", - "navID": "70", - "active": "1" - } - }, - "71": { - "attributes": { - "label": "Message Templates", - "name": "Message Templates", - "url": "civicrm/admin/messageTemplates?reset=1", - "icon": null, - "permission": "edit message templates", - "operator": "", - "separator": null, - "parentID": "64", - "navID": "71", - "active": "1" - } - }, - "72": { - "attributes": { - "label": "From Email Addresses", - "name": "From Email Addresses", - "url": "civicrm/admin/options/from_email_address?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": "1", - "parentID": "64", - "navID": "72", - "active": "1" - } - }, - "73": { - "attributes": { - "label": "New SMS", - "name": "New SMS", - "url": "civicrm/sms/send?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": null, - "separator": null, - "parentID": "64", - "navID": "73", - "active": "1" - } - }, - "74": { - "attributes": { - "label": "Find Mass SMS", - "name": "Find Mass SMS", - "url": "civicrm/mailing/browse?reset=1&sms=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": null, - "separator": "1", - "parentID": "64", - "navID": "74", - "active": "1" - } - }, - "75": { - "attributes": { - "label": "New A/B Test", - "name": "New A/B Test", - "url": "civicrm/a/#/abtest/new", - "icon": null, - "permission": "access CiviMail", - "operator": "", - "separator": null, - "parentID": "64", - "navID": "75", - "active": "1" - } - }, - "76": { - "attributes": { - "label": "Manage A/B Tests", - "name": "Manage A/B Tests", - "url": "civicrm/a/#/abtest", - "icon": null, - "permission": "access CiviMail", - "operator": "", - "separator": "1", - "parentID": "64", - "navID": "76", - "active": "1" - } - } - } - }, - "77": { - "attributes": { - "label": "Memberships", - "name": "Memberships", - "url": null, - "icon": null, - "permission": "access CiviMember", - "operator": "", - "separator": null, - "parentID": null, - "navID": "77", - "active": "1" - }, - "child": { - "78": { - "attributes": { - "label": "Dashboard", - "name": "Dashboard", - "url": "civicrm/member?reset=1", - "icon": null, - "permission": "access CiviMember", - "operator": "", - "separator": null, - "parentID": "77", - "navID": "78", - "active": "1" - } - }, - "79": { - "attributes": { - "label": "New Membership", - "name": "New Membership", - "url": "civicrm/member/add?reset=1&action=add&context=standalone", - "icon": null, - "permission": "access CiviMember,edit memberships", - "operator": "AND", - "separator": null, - "parentID": "77", - "navID": "79", - "active": "1" - } - }, - "80": { - "attributes": { - "label": "Find Memberships", - "name": "Find Memberships", - "url": "civicrm/member/search?reset=1", - "icon": null, - "permission": "access CiviMember", - "operator": "", - "separator": null, - "parentID": "77", - "navID": "80", - "active": "1" - } - }, - "81": { - "attributes": { - "label": "Membership Reports", - "name": "Membership Reports", - "url": "civicrm/report/list?compid=3&reset=1", - "icon": null, - "permission": "access CiviMember", - "operator": "", - "separator": "1", - "parentID": "77", - "navID": "81", - "active": "1" - } - }, - "82": { - "attributes": { - "label": "Batch Data Entry", - "name": "Batch Data Entry", - "url": "civicrm/batch?reset=1", - "icon": null, - "permission": "access CiviContribute", - "operator": "", - "separator": null, - "parentID": "77", - "navID": "82", - "active": "1" - } - }, - "83": { - "attributes": { - "label": "Import Memberships", - "name": "Import Members", - "url": "civicrm/member/import?reset=1", - "icon": null, - "permission": "access CiviMember,edit memberships", - "operator": "AND", - "separator": "1", - "parentID": "77", - "navID": "83", - "active": "1" - } - }, - "84": { - "attributes": { - "label": "New Price Set", - "name": "New Price Set", - "url": "civicrm/admin/price?reset=1&action=add", - "icon": null, - "permission": "access CiviMember,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "77", - "navID": "84", - "active": "1" - } - }, - "85": { - "attributes": { - "label": "Manage Price Sets", - "name": "Manage Price Sets", - "url": "civicrm/admin/price?reset=1", - "icon": null, - "permission": "access CiviMember,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "77", - "navID": "85", - "active": "1" - } - } - } - }, - "86": { - "attributes": { - "label": "Campaigns", - "name": "Campaigns", - "url": null, - "icon": null, - "permission": "interview campaign contacts,release campaign contacts,reserve campaign contacts,manage campaign,administer CiviCampaign,gotv campaign contacts", - "operator": "OR", - "separator": null, - "parentID": null, - "navID": "86", - "active": "1" - }, - "child": { - "87": { - "attributes": { - "label": "Dashboard", - "name": "Dashboard", - "url": "civicrm/campaign?reset=1", - "icon": null, - "permission": "manage campaign,administer CiviCampaign", - "operator": "OR", - "separator": null, - "parentID": "86", - "navID": "87", - "active": "1" - }, - "child": { - "88": { - "attributes": { - "label": "Surveys", - "name": "Survey Dashboard", - "url": "civicrm/campaign?reset=1&subPage=survey", - "icon": null, - "permission": "manage campaign,administer CiviCampaign", - "operator": "OR", - "separator": null, - "parentID": "87", - "navID": "88", - "active": "1" - } - }, - "89": { - "attributes": { - "label": "Petitions", - "name": "Petition Dashboard", - "url": "civicrm/campaign?reset=1&subPage=petition", - "icon": null, - "permission": "manage campaign,administer CiviCampaign", - "operator": "OR", - "separator": null, - "parentID": "87", - "navID": "89", - "active": "1" - } - }, - "90": { - "attributes": { - "label": "Campaigns", - "name": "Campaign Dashboard", - "url": "civicrm/campaign?reset=1&subPage=campaign", - "icon": null, - "permission": "manage campaign,administer CiviCampaign", - "operator": "OR", - "separator": null, - "parentID": "87", - "navID": "90", - "active": "1" - } - } - } - }, - "91": { - "attributes": { - "label": "New Campaign", - "name": "New Campaign", - "url": "civicrm/campaign/add?reset=1", - "icon": null, - "permission": "manage campaign,administer CiviCampaign", - "operator": "OR", - "separator": null, - "parentID": "86", - "navID": "91", - "active": "1" - } - }, - "92": { - "attributes": { - "label": "New Survey", - "name": "New Survey", - "url": "civicrm/survey/add?reset=1", - "icon": null, - "permission": "manage campaign,administer CiviCampaign", - "operator": "OR", - "separator": null, - "parentID": "86", - "navID": "92", - "active": "1" - } - }, - "93": { - "attributes": { - "label": "New Petition", - "name": "New Petition", - "url": "civicrm/petition/add?reset=1", - "icon": null, - "permission": "manage campaign,administer CiviCampaign", - "operator": "OR", - "separator": null, - "parentID": "86", - "navID": "93", - "active": "1" - } - }, - "94": { - "attributes": { - "label": "Reserve Respondents", - "name": "Reserve Respondents", - "url": "civicrm/survey/search?reset=1&op=reserve", - "icon": null, - "permission": "administer CiviCampaign,manage campaign,reserve campaign contacts", - "operator": "OR", - "separator": null, - "parentID": "86", - "navID": "94", - "active": "1" - } - }, - "95": { - "attributes": { - "label": "Interview Respondents", - "name": "Interview Respondents", - "url": "civicrm/survey/search?reset=1&op=interview", - "icon": null, - "permission": "administer CiviCampaign,manage campaign,interview campaign contacts", - "operator": "OR", - "separator": null, - "parentID": "86", - "navID": "95", - "active": "1" - } - }, - "96": { - "attributes": { - "label": "Release Respondents", - "name": "Release Respondents", - "url": "civicrm/survey/search?reset=1&op=release", - "icon": null, - "permission": "administer CiviCampaign,manage campaign,release campaign contacts", - "operator": "OR", - "separator": null, - "parentID": "86", - "navID": "96", - "active": "1" - } - }, - "97": { - "attributes": { - "label": "Campaign Reports", - "name": "Campaign Reports", - "url": "civicrm/report/list?compid=9&reset=1", - "icon": null, - "permission": "interview campaign contacts,release campaign contacts,reserve campaign contacts,manage campaign,administer CiviCampaign,gotv campaign contacts", - "operator": "OR", - "separator": "1", - "parentID": "86", - "navID": "97", - "active": "1" - } - }, - "98": { - "attributes": { - "label": "Conduct Survey", - "name": "Conduct Survey", - "url": "civicrm/campaign/vote?reset=1", - "icon": null, - "permission": "administer CiviCampaign,manage campaign,reserve campaign contacts,interview campaign contacts", - "operator": "OR", - "separator": null, - "parentID": "86", - "navID": "98", - "active": "1" - } - }, - "99": { - "attributes": { - "label": "GOTV (Voter Tracking)", - "name": "Voter Listing", - "url": "civicrm/campaign/gotv?reset=1", - "icon": null, - "permission": "administer CiviCampaign,manage campaign,release campaign contacts,gotv campaign contacts", - "operator": "OR", - "separator": null, - "parentID": "86", - "navID": "99", - "active": "1" - } - } - } - }, - "100": { - "attributes": { - "label": "Cases", - "name": "Cases", - "url": null, - "icon": null, - "permission": "access my cases and activities,access all cases and activities", - "operator": "OR", - "separator": null, - "parentID": null, - "navID": "100", - "active": "0" - }, - "child": { - "101": { - "attributes": { - "label": "Dashboard", - "name": "Dashboard", - "url": "civicrm/case?reset=1", - "icon": null, - "permission": "access my cases and activities,access all cases and activities", - "operator": "OR", - "separator": null, - "parentID": "100", - "navID": "101", - "active": "1" - } - }, - "102": { - "attributes": { - "label": "New Case", - "name": "New Case", - "url": "civicrm/case/add?reset=1&action=add&atype=13&context=standalone", - "icon": null, - "permission": "add cases,access all cases and activities", - "operator": "OR", - "separator": null, - "parentID": "100", - "navID": "102", - "active": "1" - } - }, - "103": { - "attributes": { - "label": "Find Cases", - "name": "Find Cases", - "url": "civicrm/case/search?reset=1", - "icon": null, - "permission": "access my cases and activities,access all cases and activities", - "operator": "OR", - "separator": "1", - "parentID": "100", - "navID": "103", - "active": "1" - } - }, - "104": { - "attributes": { - "label": "Case Reports", - "name": "Case Reports", - "url": "civicrm/report/list?compid=7&reset=1", - "icon": null, - "permission": "access my cases and activities,access all cases and activities,administer CiviCase", - "operator": "OR", - "separator": "0", - "parentID": "100", - "navID": "104", - "active": "1" - } - } - } - }, - "105": { - "attributes": { - "label": "Grants", - "name": "Grants", - "url": null, - "icon": null, - "permission": "access CiviGrant", - "operator": "", - "separator": null, - "parentID": null, - "navID": "105", - "active": "1" - }, - "child": { - "106": { - "attributes": { - "label": "Dashboard", - "name": "Dashboard", - "url": "civicrm/grant?reset=1", - "icon": null, - "permission": "access CiviGrant", - "operator": "", - "separator": null, - "parentID": "105", - "navID": "106", - "active": "1" - } - }, - "107": { - "attributes": { - "label": "New Grant", - "name": "New Grant", - "url": "civicrm/grant/add?reset=1&action=add&context=standalone", - "icon": null, - "permission": "access CiviGrant,edit grants", - "operator": "AND", - "separator": null, - "parentID": "105", - "navID": "107", - "active": "1" - } - }, - "108": { - "attributes": { - "label": "Find Grants", - "name": "Find Grants", - "url": "civicrm/grant/search?reset=1", - "icon": null, - "permission": "access CiviGrant", - "operator": "", - "separator": "1", - "parentID": "105", - "navID": "108", - "active": "1" - } - }, - "109": { - "attributes": { - "label": "Grant Reports", - "name": "Grant Reports", - "url": "civicrm/report/list?compid=5&reset=1", - "icon": null, - "permission": "access CiviGrant", - "operator": "", - "separator": "0", - "parentID": "105", - "navID": "109", - "active": "1" - } - } - } - }, - "110": { - "attributes": { - "label": "Administer", - "name": "Administer", - "url": null, - "icon": "crm-i fa-cog", - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": null, - "navID": "110", - "active": "1" - }, - "child": { - "111": { - "attributes": { - "label": "Administration Console", - "name": "Administration Console", - "url": "civicrm/admin?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "110", - "navID": "111", - "active": "1" - }, - "child": { - "112": { - "attributes": { - "label": "System Status", - "name": "System Status", - "url": "civicrm/a/#/status", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "111", - "navID": "112", - "active": "1" - } - }, - "113": { - "attributes": { - "label": "Configuration Checklist", - "name": "Configuration Checklist", - "url": "civicrm/admin/configtask?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "111", - "navID": "113", - "active": "1" - } - } - } - }, - "114": { - "attributes": { - "label": "Customize Data and Screens", - "name": "Customize Data and Screens", - "url": null, - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "110", - "navID": "114", - "active": "1" - }, - "child": { - "115": { - "attributes": { - "label": "Custom Fields", - "name": "Custom Fields", - "url": "civicrm/admin/custom/group?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "114", - "navID": "115", - "active": "1" - } - }, - "116": { - "attributes": { - "label": "Profiles", - "name": "Profiles", - "url": "civicrm/admin/uf/group?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "114", - "navID": "116", - "active": "1" - } - }, - "117": { - "attributes": { - "label": "Tags (Categories)", - "name": "Tags (Categories)", - "url": "civicrm/tag?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "114", - "navID": "117", - "active": "1" - } - }, - "118": { - "attributes": { - "label": "Activity Types", - "name": "Activity Types", - "url": "civicrm/admin/options/activity_type?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "114", - "navID": "118", - "active": "1" - } - }, - "119": { - "attributes": { - "label": "Relationship Types", - "name": "Relationship Types", - "url": "civicrm/admin/reltype?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "114", - "navID": "119", - "active": "1" - } - }, - "120": { - "attributes": { - "label": "Contact Types", - "name": "Contact Types", - "url": "civicrm/admin/options/subtype?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "114", - "navID": "120", - "active": "1" - } - }, - "121": { - "attributes": { - "label": "Display Preferences", - "name": "Display Preferences", - "url": "civicrm/admin/setting/preferences/display?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "114", - "navID": "121", - "active": "1" - } - }, - "122": { - "attributes": { - "label": "Search Preferences", - "name": "Search Preferences", - "url": "civicrm/admin/setting/search?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "114", - "navID": "122", - "active": "1" - } - }, - "123": { - "attributes": { - "label": "Date Preferences", - "name": "Date Preferences", - "url": "civicrm/admin/setting/preferences/date?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "114", - "navID": "123", - "active": "1" - } - }, - "124": { - "attributes": { - "label": "Navigation Menu", - "name": "Navigation Menu", - "url": "civicrm/admin/menu?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "114", - "navID": "124", - "active": "1" - } - }, - "125": { - "attributes": { - "label": "Word Replacements", - "name": "Word Replacements", - "url": "civicrm/admin/options/wordreplacements?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "114", - "navID": "125", - "active": "1" - } - }, - "126": { - "attributes": { - "label": "Manage Custom Searches", - "name": "Manage Custom Searches", - "url": "civicrm/admin/options/custom_search?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "114", - "navID": "126", - "active": "1" - } - }, - "127": { - "attributes": { - "label": "Dropdown Options", - "name": "Dropdown Options", - "url": null, - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "114", - "navID": "127", - "active": "1" - }, - "child": { - "128": { - "attributes": { - "label": "Gender Options", - "name": "Gender Options", - "url": "civicrm/admin/options/gender?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "127", - "navID": "128", - "active": "1" - } - }, - "129": { - "attributes": { - "label": "Individual Prefixes (Ms, Mr...)", - "name": "Individual Prefixes (Ms, Mr...)", - "url": "civicrm/admin/options/individual_prefix?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "127", - "navID": "129", - "active": "1" - } - }, - "130": { - "attributes": { - "label": "Individual Suffixes (Jr, Sr...)", - "name": "Individual Suffixes (Jr, Sr...)", - "url": "civicrm/admin/options/individual_suffix?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "127", - "navID": "130", - "active": "1" - } - }, - "131": { - "attributes": { - "label": "Instant Messenger Services", - "name": "Instant Messenger Services", - "url": "civicrm/admin/options/instant_messenger_service?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "127", - "navID": "131", - "active": "1" - } - }, - "132": { - "attributes": { - "label": "Location Types (Home, Work...)", - "name": "Location Types (Home, Work...)", - "url": "civicrm/admin/locationType?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "127", - "navID": "132", - "active": "1" - } - }, - "133": { - "attributes": { - "label": "Mobile Phone Providers", - "name": "Mobile Phone Providers", - "url": "civicrm/admin/options/mobile_provider?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "127", - "navID": "133", - "active": "1" - } - }, - "134": { - "attributes": { - "label": "Phone Types", - "name": "Phone Types", - "url": "civicrm/admin/options/phone_type?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "127", - "navID": "134", - "active": "1" - } - }, - "135": { - "attributes": { - "label": "Website Types", - "name": "Website Types", - "url": "civicrm/admin/options/website_type?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "127", - "navID": "135", - "active": "1" - } - }, - "267": { - "attributes": { - "label": "Hours Types", - "name": "hoursType", - "url": "civicrm/hour/editoption", - "icon": null, - "permission": "administer CiviCRM", - "operator": null, - "separator": "0", - "parentID": "127", - "navID": "267", - "active": "1" - } - }, - "268": { - "attributes": { - "label": "Job Contract Pay Scale", - "name": "pay_scale", - "url": "civicrm/pay_scale", - "icon": null, - "permission": "administer CiviCRM", - "operator": null, - "separator": "0", - "parentID": "127", - "navID": "268", - "active": "1" - } - }, - "269": { - "attributes": { - "label": "Job Contract Hours/Location", - "name": "hours_location", - "url": "civicrm/hours_location", - "icon": null, - "permission": "administer CiviCRM", - "operator": null, - "separator": "0", - "parentID": "127", - "navID": "269", - "active": "1" - } - }, - "270": { - "attributes": { - "label": "Contract Type", - "name": "hrjc_contract_type", - "url": "civicrm/admin/options/hrjc_contract_type?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": null, - "separator": "0", - "parentID": "127", - "navID": "270", - "active": "1" - } - }, - "271": { - "attributes": { - "label": "Normal place of work", - "name": "hrjc_location", - "url": "civicrm/admin/options/hrjc_location?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": null, - "separator": "0", - "parentID": "127", - "navID": "271", - "active": "1" - } - }, - "272": { - "attributes": { - "label": "Pay cycle", - "name": "hrjc_pay_cycle", - "url": "civicrm/admin/options/hrjc_pay_cycle?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": null, - "separator": "0", - "parentID": "127", - "navID": "272", - "active": "1" - } - }, - "273": { - "attributes": { - "label": "Benefits", - "name": "hrjc_benefit_name", - "url": "civicrm/admin/options/hrjc_benefit_name?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": null, - "separator": "0", - "parentID": "127", - "navID": "273", - "active": "1" - } - }, - "274": { - "attributes": { - "label": "Benefit type", - "name": "hrjc_benefit_type", - "url": "civicrm/admin/options/hrjc_benefit_type?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": null, - "separator": "0", - "parentID": "127", - "navID": "274", - "active": "1" - } - }, - "275": { - "attributes": { - "label": "Deductions", - "name": "hrjc_deduction_name", - "url": "civicrm/admin/options/hrjc_deduction_name?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": null, - "separator": "0", - "parentID": "127", - "navID": "275", - "active": "1" - } - }, - "276": { - "attributes": { - "label": "Deduction type", - "name": "hrjc_deduction_type", - "url": "civicrm/admin/options/hrjc_deduction_type?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": null, - "separator": "0", - "parentID": "127", - "navID": "276", - "active": "1" - } - }, - "278": { - "attributes": { - "label": "Reason for change", - "name": "hrjc_revision_change_reason", - "url": "civicrm/admin/options/hrjc_revision_change_reason?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": null, - "separator": "0", - "parentID": "127", - "navID": "278", - "active": "1" - } - }, - "279": { - "attributes": { - "label": "Reason for Job Contract end", - "name": "hrjc_contract_end_reason", - "url": "civicrm/admin/options/hrjc_contract_end_reason?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": null, - "separator": "0", - "parentID": "127", - "navID": "279", - "active": "1" - } - } - } - } - } - }, - "136": { - "attributes": { - "label": "Communications", - "name": "Communications", - "url": null, - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "110", - "navID": "136", - "active": "1" - }, - "child": { - "137": { - "attributes": { - "label": "Organization Address and Contact Info", - "name": "Organization Address and Contact Info", - "url": "civicrm/admin/domain?action=update&reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "136", - "navID": "137", - "active": "1" - } - }, - "138": { - "attributes": { - "label": "FROM Email Addresses", - "name": "FROM Email Addresses", - "url": "civicrm/admin/options/from_email_address?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "136", - "navID": "138", - "active": "1" - } - }, - "139": { - "attributes": { - "label": "Message Templates", - "name": "Message Templates", - "url": "civicrm/admin/messageTemplates?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "136", - "navID": "139", - "active": "1" - } - }, - "140": { - "attributes": { - "label": "Schedule Reminders", - "name": "Schedule Reminders", - "url": "civicrm/admin/scheduleReminders?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "136", - "navID": "140", - "active": "1" - } - }, - "141": { - "attributes": { - "label": "Preferred Communication Methods", - "name": "Preferred Communication Methods", - "url": "civicrm/admin/options/preferred_communication_method?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "136", - "navID": "141", - "active": "1" - } - }, - "142": { - "attributes": { - "label": "Label Formats", - "name": "Label Formats", - "url": "civicrm/admin/labelFormats?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "136", - "navID": "142", - "active": "1" - } - }, - "143": { - "attributes": { - "label": "Print Page (PDF) Formats", - "name": "Print Page (PDF) Formats", - "url": "civicrm/admin/pdfFormats?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "136", - "navID": "143", - "active": "1" - } - }, - "144": { - "attributes": { - "label": "Communication Style Options", - "name": "Communication Style Options", - "url": "civicrm/admin/options/communication_style?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "136", - "navID": "144", - "active": "1" - } - }, - "145": { - "attributes": { - "label": "Email Greeting Formats", - "name": "Email Greeting Formats", - "url": "civicrm/admin/options/email_greeting?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "136", - "navID": "145", - "active": "1" - } - }, - "146": { - "attributes": { - "label": "Postal Greeting Formats", - "name": "Postal Greeting Formats", - "url": "civicrm/admin/options/postal_greeting?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "136", - "navID": "146", - "active": "1" - } - }, - "147": { - "attributes": { - "label": "Addressee Formats", - "name": "Addressee Formats", - "url": "civicrm/admin/options/addressee?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "136", - "navID": "147", - "active": "1" - } - } - } - }, - "148": { - "attributes": { - "label": "Localization", - "name": "Localization", - "url": null, - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "110", - "navID": "148", - "active": "1" - }, - "child": { - "149": { - "attributes": { - "label": "Languages, Currency, Locations", - "name": "Languages, Currency, Locations", - "url": "civicrm/admin/setting/localization?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "148", - "navID": "149", - "active": "1" - } - }, - "150": { - "attributes": { - "label": "Address Settings", - "name": "Address Settings", - "url": "civicrm/admin/setting/preferences/address?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "148", - "navID": "150", - "active": "1" - } - }, - "151": { - "attributes": { - "label": "Date Formats", - "name": "Date Formats", - "url": "civicrm/admin/setting/date?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "148", - "navID": "151", - "active": "1" - } - }, - "152": { - "attributes": { - "label": "Preferred Language Options", - "name": "Preferred Language Options", - "url": "civicrm/admin/options/languages?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "148", - "navID": "152", - "active": "1" - } - } - } - }, - "153": { - "attributes": { - "label": "Users and Permissions", - "name": "Users and Permissions", - "url": null, - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "110", - "navID": "153", - "active": "1" - }, - "child": { - "154": { - "attributes": { - "label": "Permissions (Access Control)", - "name": "Permissions (Access Control)", - "url": "civicrm/admin/access?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "153", - "navID": "154", - "active": "1" - } - }, - "155": { - "attributes": { - "label": "Synchronize Users to Contacts", - "name": "Synchronize Users to Contacts", - "url": "civicrm/admin/synchUser?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "153", - "navID": "155", - "active": "1" - } - } - } - }, - "156": { - "attributes": { - "label": "System Settings", - "name": "System Settings", - "url": null, - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "110", - "navID": "156", - "active": "1" - }, - "child": { - "157": { - "attributes": { - "label": "Components", - "name": "Enable Components", - "url": "civicrm/admin/setting/component?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "156", - "navID": "157", - "active": "1" - } - }, - "158": { - "attributes": { - "label": "Connections", - "name": "Connections", - "url": "civicrm/a/#/cxn", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "156", - "navID": "158", - "active": "1" - } - }, - "159": { - "attributes": { - "label": "Extensions", - "name": "Manage Extensions", - "url": "civicrm/admin/extensions?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": "1", - "parentID": "156", - "navID": "159", - "active": "1" - } - }, - "160": { - "attributes": { - "label": "Cleanup Caches and Update Paths", - "name": "Cleanup Caches and Update Paths", - "url": "civicrm/admin/setting/updateConfigBackend?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "156", - "navID": "160", - "active": "1" - } - }, - "161": { - "attributes": { - "label": "CMS Database Integration", - "name": "CMS Integration", - "url": "civicrm/admin/setting/uf?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "156", - "navID": "161", - "active": "1" - } - }, - "162": { - "attributes": { - "label": "Debugging and Error Handling", - "name": "Debugging and Error Handling", - "url": "civicrm/admin/setting/debug?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "156", - "navID": "162", - "active": "1" - } - }, - "163": { - "attributes": { - "label": "Directories", - "name": "Directories", - "url": "civicrm/admin/setting/path?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "156", - "navID": "163", - "active": "1" - } - }, - "164": { - "attributes": { - "label": "Import/Export Mappings", - "name": "Import/Export Mappings", - "url": "civicrm/admin/mapping?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "156", - "navID": "164", - "active": "1" - } - }, - "165": { - "attributes": { - "label": "Mapping and Geocoding", - "name": "Mapping and Geocoding", - "url": "civicrm/admin/setting/mapping?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "156", - "navID": "165", - "active": "1" - } - }, - "166": { - "attributes": { - "label": "Misc (Undelete, PDFs, Limits, Logging, Captcha, etc.)", - "name": "Misc (Undelete, PDFs, Limits, Logging, Captcha, etc.)", - "url": "civicrm/admin/setting/misc?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "156", - "navID": "166", - "active": "1" - } - }, - "167": { - "attributes": { - "label": "Multi Site Settings", - "name": "Multi Site Settings", - "url": "civicrm/admin/setting/preferences/multisite?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "156", - "navID": "167", - "active": "1" - } - }, - "168": { - "attributes": { - "label": "Option Groups", - "name": "Option Groups", - "url": "civicrm/admin/options?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "156", - "navID": "168", - "active": "1" - } - }, - "169": { - "attributes": { - "label": "Outbound Email (SMTP/Sendmail)", - "name": "Outbound Email", - "url": "civicrm/admin/setting/smtp?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "156", - "navID": "169", - "active": "1" - } - }, - "170": { - "attributes": { - "label": "Payment Processors", - "name": "Payment Processors", - "url": "civicrm/admin/paymentProcessor?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "156", - "navID": "170", - "active": "1" - } - }, - "171": { - "attributes": { - "label": "Resource URLs", - "name": "Resource URLs", - "url": "civicrm/admin/setting/url?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "156", - "navID": "171", - "active": "1" - } - }, - "172": { - "attributes": { - "label": "Safe File Extensions", - "name": "Safe File Extensions", - "url": "civicrm/admin/options/safe_file_extension?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "156", - "navID": "172", - "active": "1" - } - }, - "173": { - "attributes": { - "label": "Scheduled Jobs", - "name": "Scheduled Jobs", - "url": "civicrm/admin/job?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "156", - "navID": "173", - "active": "1" - } - }, - "174": { - "attributes": { - "label": "SMS Providers", - "name": "SMS Providers", - "url": "civicrm/admin/sms/provider?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "156", - "navID": "174", - "active": "1" - } - } - } - }, - "175": { - "attributes": { - "label": "CiviCampaign", - "name": "CiviCampaign", - "url": null, - "icon": null, - "permission": "administer CiviCampaign,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "110", - "navID": "175", - "active": "1" - }, - "child": { - "176": { - "attributes": { - "label": "Survey Types", - "name": "Survey Types", - "url": "civicrm/admin/campaign/surveyType?reset=1", - "icon": null, - "permission": "administer CiviCampaign", - "operator": "", - "separator": null, - "parentID": "175", - "navID": "176", - "active": "1" - } - }, - "177": { - "attributes": { - "label": "Campaign Types", - "name": "Campaign Types", - "url": "civicrm/admin/options/campaign_type?reset=1", - "icon": null, - "permission": "administer CiviCampaign", - "operator": "", - "separator": null, - "parentID": "175", - "navID": "177", - "active": "1" - } - }, - "178": { - "attributes": { - "label": "Campaign Status", - "name": "Campaign Status", - "url": "civicrm/admin/options/campaign_status?reset=1", - "icon": null, - "permission": "administer CiviCampaign", - "operator": "", - "separator": null, - "parentID": "175", - "navID": "178", - "active": "1" - } - }, - "179": { - "attributes": { - "label": "Engagement Index", - "name": "Engagement Index", - "url": "civicrm/admin/options/engagement_index?reset=1", - "icon": null, - "permission": "administer CiviCampaign", - "operator": "", - "separator": null, - "parentID": "175", - "navID": "179", - "active": "1" - } - }, - "180": { - "attributes": { - "label": "CiviCampaign Component Settings", - "name": "CiviCampaign Component Settings", - "url": "civicrm/admin/setting/preferences/campaign?reset=1", - "icon": null, - "permission": "administer CiviCampaign", - "operator": "", - "separator": null, - "parentID": "175", - "navID": "180", - "active": "1" - } - } - } - }, - "181": { - "attributes": { - "label": "CiviCase", - "name": "CiviCase", - "url": null, - "icon": null, - "permission": "administer CiviCase", - "operator": null, - "separator": null, - "parentID": "110", - "navID": "181", - "active": "1" - }, - "child": { - "182": { - "attributes": { - "label": "CiviCase Settings", - "name": "CiviCase Settings", - "url": "civicrm/admin/setting/case?reset=1", - "icon": null, - "permission": "administer CiviCase", - "operator": null, - "separator": null, - "parentID": "181", - "navID": "182", - "active": "1" - } - }, - "183": { - "attributes": { - "label": "Case Types", - "name": "Case Types", - "url": "civicrm/a/#/caseType", - "icon": null, - "permission": "administer CiviCase", - "operator": null, - "separator": null, - "parentID": "181", - "navID": "183", - "active": "1" - } - }, - "184": { - "attributes": { - "label": "Redaction Rules", - "name": "Redaction Rules", - "url": "civicrm/admin/options/redaction_rule?reset=1", - "icon": null, - "permission": "administer CiviCase", - "operator": null, - "separator": null, - "parentID": "181", - "navID": "184", - "active": "1" - } - }, - "185": { - "attributes": { - "label": "Case Statuses", - "name": "Case Statuses", - "url": "civicrm/admin/options/case_status?reset=1", - "icon": null, - "permission": "administer CiviCase", - "operator": null, - "separator": null, - "parentID": "181", - "navID": "185", - "active": "1" - } - }, - "186": { - "attributes": { - "label": "Encounter Medium", - "name": "Encounter Medium", - "url": "civicrm/admin/options/encounter_medium?reset=1", - "icon": null, - "permission": "administer CiviCase", - "operator": null, - "separator": null, - "parentID": "181", - "navID": "186", - "active": "1" - } - } - } - }, - "187": { - "attributes": { - "label": "CiviContribute", - "name": "CiviContribute", - "url": null, - "icon": null, - "permission": "access CiviContribute,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "110", - "navID": "187", - "active": "1" - }, - "child": { - "188": { - "attributes": { - "label": "New Contribution Page", - "name": "New Contribution Page", - "url": "civicrm/admin/contribute?reset=1&action=add", - "icon": null, - "permission": "access CiviContribute,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "187", - "navID": "188", - "active": "1" - } - }, - "189": { - "attributes": { - "label": "Manage Contribution Pages", - "name": "Manage Contribution Pages", - "url": "civicrm/admin/contribute?reset=1", - "icon": null, - "permission": "access CiviContribute,administer CiviCRM", - "operator": "AND", - "separator": "1", - "parentID": "187", - "navID": "189", - "active": "1" - } - }, - "190": { - "attributes": { - "label": "Personal Campaign Pages", - "name": "Personal Campaign Pages", - "url": "civicrm/admin/pcp?reset=1&page_type=contribute", - "icon": null, - "permission": "access CiviContribute,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "187", - "navID": "190", - "active": "1" - } - }, - "191": { - "attributes": { - "label": "Premiums (Thank-you Gifts)", - "name": "Premiums", - "url": "civicrm/admin/contribute/managePremiums?reset=1", - "icon": null, - "permission": "access CiviContribute,administer CiviCRM", - "operator": "AND", - "separator": "1", - "parentID": "187", - "navID": "191", - "active": "1" - } - }, - "192": { - "attributes": { - "label": "Financial Types", - "name": "Financial Types", - "url": "civicrm/admin/financial/financialType?reset=1", - "icon": null, - "permission": "access CiviContribute,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "187", - "navID": "192", - "active": "1" - } - }, - "193": { - "attributes": { - "label": "Financial Accounts", - "name": "Financial Accounts", - "url": "civicrm/admin/financial/financialAccount?reset=1", - "icon": null, - "permission": "access CiviContribute,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "187", - "navID": "193", - "active": "1" - } - }, - "194": { - "attributes": { - "label": "Payment Methods", - "name": "Payment Instruments", - "url": "civicrm/admin/options/payment_instrument?reset=1", - "icon": null, - "permission": "access CiviContribute,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "187", - "navID": "194", - "active": "1" - } - }, - "195": { - "attributes": { - "label": "Accepted Credit Cards", - "name": "Accepted Credit Cards", - "url": "civicrm/admin/options/accept_creditcard?reset=1", - "icon": null, - "permission": "access CiviContribute,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "187", - "navID": "195", - "active": "1" - } - }, - "196": { - "attributes": { - "label": "Soft Credit Types", - "name": "Soft Credit Types", - "url": "civicrm/admin/options/soft_credit_type?reset=1", - "icon": null, - "permission": "access CiviContribute,administer CiviCRM", - "operator": "AND", - "separator": "1", - "parentID": "187", - "navID": "196", - "active": "1" - } - }, - "197": { - "attributes": { - "label": "New Price Set", - "name": "New Price Set", - "url": "civicrm/admin/price?reset=1&action=add", - "icon": null, - "permission": "access CiviContribute,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "187", - "navID": "197", - "active": "1" - } - }, - "198": { - "attributes": { - "label": "Manage Price Sets", - "name": "Manage Price Sets", - "url": "civicrm/admin/price?reset=1", - "icon": null, - "permission": "access CiviContribute,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "187", - "navID": "198", - "active": "1" - } - }, - "199": { - "attributes": { - "label": "Payment Processors", - "name": "Payment Processors", - "url": "civicrm/admin/paymentProcessor?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "187", - "navID": "199", - "active": "1" - } - }, - "200": { - "attributes": { - "label": "CiviContribute Component Settings", - "name": "CiviContribute Component Settings", - "url": "civicrm/admin/setting/preferences/contribute?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "187", - "navID": "200", - "active": "1" - } - } - } - }, - "201": { - "attributes": { - "label": "CiviEvent", - "name": "CiviEvent", - "url": null, - "icon": null, - "permission": "access CiviEvent,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "110", - "navID": "201", - "active": "1" - }, - "child": { - "202": { - "attributes": { - "label": "New Event", - "name": "New Event", - "url": "civicrm/event/add?reset=1&action=add", - "icon": null, - "permission": "access CiviEvent,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "201", - "navID": "202", - "active": "1" - } - }, - "203": { - "attributes": { - "label": "Manage Events", - "name": "Manage Events", - "url": "civicrm/event/manage?reset=1", - "icon": null, - "permission": "access CiviEvent,administer CiviCRM", - "operator": "AND", - "separator": "1", - "parentID": "201", - "navID": "203", - "active": "1" - } - }, - "204": { - "attributes": { - "label": "Personal Campaign Pages", - "name": "Personal Campaign Pages", - "url": "civicrm/admin/pcp?reset=1&page_type=event", - "icon": null, - "permission": "access CiviEvent,administer CiviCRM", - "operator": "AND", - "separator": "1", - "parentID": "201", - "navID": "204", - "active": "1" - } - }, - "205": { - "attributes": { - "label": "Event Templates", - "name": "Event Templates", - "url": "civicrm/admin/eventTemplate?reset=1", - "icon": null, - "permission": "access CiviEvent,administer CiviCRM", - "operator": "AND", - "separator": "1", - "parentID": "201", - "navID": "205", - "active": "1" - } - }, - "206": { - "attributes": { - "label": "New Price Set", - "name": "New Price Set", - "url": "civicrm/admin/price?reset=1&action=add", - "icon": null, - "permission": "access CiviEvent,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "201", - "navID": "206", - "active": "1" - } - }, - "207": { - "attributes": { - "label": "Manage Price Sets", - "name": "Manage Price Sets", - "url": "civicrm/admin/price?reset=1", - "icon": null, - "permission": "access CiviEvent,administer CiviCRM", - "operator": "AND", - "separator": "1", - "parentID": "201", - "navID": "207", - "active": "1" - } - }, - "208": { - "attributes": { - "label": "Event Types", - "name": "Event Types", - "url": "civicrm/admin/options/event_type?reset=1", - "icon": null, - "permission": "access CiviEvent,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "201", - "navID": "208", - "active": "1" - } - }, - "209": { - "attributes": { - "label": "Participant Statuses", - "name": "Participant Statuses", - "url": "civicrm/admin/participant_status?reset=1", - "icon": null, - "permission": "access CiviEvent,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "201", - "navID": "209", - "active": "1" - } - }, - "210": { - "attributes": { - "label": "Participant Roles", - "name": "Participant Roles", - "url": "civicrm/admin/options/participant_role?reset=1", - "icon": null, - "permission": "access CiviEvent,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "201", - "navID": "210", - "active": "1" - } - }, - "211": { - "attributes": { - "label": "Participant Listing Options", - "name": "Participant Listing Options", - "url": "civicrm/admin/options/participant_listing?reset=1", - "icon": null, - "permission": "access CiviEvent,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "201", - "navID": "211", - "active": "1" - } - }, - "212": { - "attributes": { - "label": "Event Name Badge Layouts", - "name": "Event Name Badge Layouts", - "url": "civicrm/admin/badgelayout?reset=1", - "icon": null, - "permission": "access CiviEvent,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "201", - "navID": "212", - "active": "1" - } - }, - "213": { - "attributes": { - "label": "Payment Processors", - "name": "Payment Processors", - "url": "civicrm/admin/paymentProcessor?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "201", - "navID": "213", - "active": "1" - } - }, - "214": { - "attributes": { - "label": "CiviEvent Component Settings", - "name": "CiviEvent Component Settings", - "url": "civicrm/admin/setting/preferences/event?reset=1", - "icon": null, - "permission": "access CiviEvent,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "201", - "navID": "214", - "active": "1" - } - } - } - }, - "215": { - "attributes": { - "label": "CiviGrant", - "name": "CiviGrant", - "url": null, - "icon": null, - "permission": "access CiviGrant,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "110", - "navID": "215", - "active": "1" - }, - "child": { - "216": { - "attributes": { - "label": "Grant Types", - "name": "Grant Types", - "url": "civicrm/admin/options/grant_type?reset=1", - "icon": null, - "permission": "access CiviGrant,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "215", - "navID": "216", - "active": "1" - } - }, - "217": { - "attributes": { - "label": "Grant Status", - "name": "Grant Status", - "url": "civicrm/admin/options/grant_status?reset=1", - "icon": null, - "permission": "access CiviGrant,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "215", - "navID": "217", - "active": "1" - } - } - } - }, - "218": { - "attributes": { - "label": "CiviMail", - "name": "CiviMail", - "url": null, - "icon": null, - "permission": "access CiviMail,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "110", - "navID": "218", - "active": "1" - }, - "child": { - "219": { - "attributes": { - "label": "Headers, Footers, and Automated Messages", - "name": "Headers, Footers, and Automated Messages", - "url": "civicrm/admin/component?reset=1", - "icon": null, - "permission": "access CiviMail,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "218", - "navID": "219", - "active": "1" - } - }, - "220": { - "attributes": { - "label": "Message Templates", - "name": "Message Templates", - "url": "civicrm/admin/messageTemplates?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "218", - "navID": "220", - "active": "1" - } - }, - "221": { - "attributes": { - "label": "From Email Addresses", - "name": "From Email Addresses", - "url": "civicrm/admin/options/from_email_address?reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": null, - "parentID": "218", - "navID": "221", - "active": "1" - } - }, - "222": { - "attributes": { - "label": "Mail Accounts", - "name": "Mail Accounts", - "url": "civicrm/admin/mailSettings?reset=1", - "icon": null, - "permission": "access CiviMail,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "218", - "navID": "222", - "active": "1" - } - }, - "223": { - "attributes": { - "label": "Mailer Settings", - "name": "Mailer Settings", - "url": "civicrm/admin/mail?reset=1", - "icon": null, - "permission": "access CiviMail,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "218", - "navID": "223", - "active": "1" - } - }, - "224": { - "attributes": { - "label": "CiviMail Component Settings", - "name": "CiviMail Component Settings", - "url": "civicrm/admin/setting/preferences/mailing?reset=1", - "icon": null, - "permission": "access CiviMail,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "218", - "navID": "224", - "active": "1" - } - } - } - }, - "225": { - "attributes": { - "label": "CiviMember", - "name": "CiviMember", - "url": null, - "icon": null, - "permission": "access CiviMember,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "110", - "navID": "225", - "active": "1" - }, - "child": { - "226": { - "attributes": { - "label": "Membership Types", - "name": "Membership Types", - "url": "civicrm/admin/member/membershipType?reset=1", - "icon": null, - "permission": "access CiviMember,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "225", - "navID": "226", - "active": "1" - } - }, - "227": { - "attributes": { - "label": "Membership Status Rules", - "name": "Membership Status Rules", - "url": "civicrm/admin/member/membershipStatus?reset=1", - "icon": null, - "permission": "access CiviMember,administer CiviCRM", - "operator": "AND", - "separator": "1", - "parentID": "225", - "navID": "227", - "active": "1" - } - }, - "228": { - "attributes": { - "label": "New Price Set", - "name": "New Price Set", - "url": "civicrm/admin/price?reset=1&action=add", - "icon": null, - "permission": "access CiviMember,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "225", - "navID": "228", - "active": "1" - } - }, - "229": { - "attributes": { - "label": "Manage Price Sets", - "name": "Manage Price Sets", - "url": "civicrm/admin/price?reset=1", - "icon": null, - "permission": "access CiviMember,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "225", - "navID": "229", - "active": "1" - } - }, - "230": { - "attributes": { - "label": "CiviMember Component Settings", - "name": "CiviMember Component Settings", - "url": "civicrm/admin/setting/preferences/member?reset=1", - "icon": null, - "permission": "access CiviMember,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "225", - "navID": "230", - "active": "1" - } - } - } - }, - "231": { - "attributes": { - "label": "CiviReport", - "name": "CiviReport", - "url": null, - "icon": null, - "permission": "access CiviReport,administer CiviCRM", - "operator": "AND", - "separator": null, - "parentID": "110", - "navID": "231", - "active": "1" - }, - "child": { - "232": { - "attributes": { - "label": "All Reports", - "name": "All Reports", - "url": "civicrm/report/list?reset=1", - "icon": null, - "permission": "access CiviReport", - "operator": "", - "separator": null, - "parentID": "231", - "navID": "232", - "active": "1" - } - }, - "233": { - "attributes": { - "label": "Create New Report from Template", - "name": "Create New Report from Template", - "url": "civicrm/admin/report/template/list?reset=1", - "icon": null, - "permission": "administer Reports", - "operator": "", - "separator": null, - "parentID": "231", - "navID": "233", - "active": "1" - } - }, - "234": { - "attributes": { - "label": "Manage Templates", - "name": "Manage Templates", - "url": "civicrm/admin/report/options/report_template?reset=1", - "icon": null, - "permission": "administer Reports", - "operator": "", - "separator": null, - "parentID": "231", - "navID": "234", - "active": "1" - } - }, - "235": { - "attributes": { - "label": "Register Report", - "name": "Register Report", - "url": "civicrm/admin/report/register?reset=1", - "icon": null, - "permission": "administer Reports", - "operator": "", - "separator": null, - "parentID": "231", - "navID": "235", - "active": "1" - } - } - } - }, - "286": { - "attributes": { - "label": "Tasks", - "name": "tasksassignments_administer", - "url": null, - "icon": null, - "permission": null, - "operator": null, - "separator": null, - "parentID": "110", - "navID": "286", - "active": "1" - }, - "child": { - "285": { - "attributes": { - "label": "Tasks Settings", - "name": "ta_settings", - "url": "civicrm/tasksassignments/settings", - "icon": null, - "permission": null, - "operator": null, - "separator": "0", - "parentID": "286", - "navID": "285", - "active": "1" - } - } - } - }, - "292": { - "attributes": { - "label": "Leave", - "name": "leave_and_absences", - "url": null, - "icon": null, - "permission": "administer leave and absences", - "operator": null, - "separator": null, - "parentID": "110", - "navID": "292", - "active": "1" - }, - "child": { - "293": { - "attributes": { - "label": "Leave/Absence Types", - "name": "leave_and_absence_types", - "url": "civicrm/admin/leaveandabsences/types?action=browse&reset=1", - "icon": null, - "permission": "administer leave and absences", - "operator": null, - "separator": "0", - "parentID": "292", - "navID": "293", - "active": "1" - } - }, - "294": { - "attributes": { - "label": "Leave/Absence Periods", - "name": "leave_and_absence_periods", - "url": "civicrm/admin/leaveandabsences/periods?action=browse&reset=1", - "icon": null, - "permission": "administer leave and absences", - "operator": null, - "separator": "0", - "parentID": "292", - "navID": "294", - "active": "1" - } - }, - "295": { - "attributes": { - "label": "Public Holidays", - "name": "leave_and_absence_public_holidays", - "url": "civicrm/admin/leaveandabsences/public_holidays?action=browse&reset=1", - "icon": null, - "permission": "administer leave and absences", - "operator": null, - "separator": "0", - "parentID": "292", - "navID": "295", - "active": "1" - } - }, - "296": { - "attributes": { - "label": "Manage Work Patterns", - "name": "leave_and_absence_manage_work_patterns", - "url": "civicrm/admin/leaveandabsences/work_patterns?action=browse&reset=1", - "icon": null, - "permission": "administer leave and absences", - "operator": null, - "separator": "0", - "parentID": "292", - "navID": "296", - "active": "1" - } - }, - "297": { - "attributes": { - "label": "General Settings", - "name": "leave_and_absence_general_settings", - "url": "civicrm/admin/leaveandabsences/general_settings", - "icon": null, - "permission": "administer leave and absences", - "operator": null, - "separator": "0", - "parentID": "292", - "navID": "297", - "active": "1" - } - }, - "298": { - "attributes": { - "label": "Import Leave/Absence Requests", - "name": "leave_and_absences_import", - "url": "civicrm/admin/leaveandabsences/import", - "icon": null, - "permission": "administer leave and absences", - "operator": null, - "separator": "0", - "parentID": "292", - "navID": "298", - "active": "1" - } - } - } - } - } - }, - "236": { - "attributes": { - "label": "Support", - "name": "Support", - "url": null, - "icon": null, - "permission": null, - "operator": "", - "separator": null, - "parentID": null, - "navID": "236", - "active": "1" - }, - "child": { - "237": { - "attributes": { - "label": "Get started", - "name": "Get started", - "url": "https://civicrm.org/get-started?src=iam", - "icon": null, - "permission": null, - "operator": "AND", - "separator": null, - "parentID": "236", - "navID": "237", - "active": "1" - } - }, - "238": { - "attributes": { - "label": "Documentation", - "name": "Documentation", - "url": "https://civicrm.org/documentation?src=iam", - "icon": null, - "permission": null, - "operator": "AND", - "separator": null, - "parentID": "236", - "navID": "238", - "active": "1" - } - }, - "239": { - "attributes": { - "label": "Ask a question", - "name": "Ask a question", - "url": "https://civicrm.org/ask-a-question?src=iam", - "icon": null, - "permission": null, - "operator": "AND", - "separator": null, - "parentID": "236", - "navID": "239", - "active": "1" - } - }, - "240": { - "attributes": { - "label": "Get expert help", - "name": "Get expert help", - "url": "https://civicrm.org/experts?src=iam", - "icon": null, - "permission": null, - "operator": "AND", - "separator": null, - "parentID": "236", - "navID": "240", - "active": "1" - } - }, - "241": { - "attributes": { - "label": "About CiviCRM", - "name": "About CiviCRM", - "url": "https://civicrm.org/about?src=iam", - "icon": null, - "permission": null, - "operator": "AND", - "separator": "1", - "parentID": "236", - "navID": "241", - "active": "1" - } - }, - "242": { - "attributes": { - "label": "Register your site", - "name": "Register your site", - "url": "https://civicrm.org/register-your-site?src=iam&sid={sid}", - "icon": null, - "permission": null, - "operator": "AND", - "separator": null, - "parentID": "236", - "navID": "242", - "active": "1" - } - }, - "243": { - "attributes": { - "label": "Join CiviCRM", - "name": "Join CiviCRM", - "url": "https://civicrm.org/become-a-member?src=iam&sid={sid}", - "icon": null, - "permission": null, - "operator": "AND", - "separator": null, - "parentID": "236", - "navID": "243", - "active": "1" - } - }, - "244": { - "attributes": { - "label": "Developer", - "name": "Developer", - "url": null, - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": "1", - "parentID": "236", - "navID": "244", + "parentID": "110", + "navID": "114", "active": "1" }, "child": { - "245": { + "115": { "attributes": { - "label": "API Explorer", - "name": "API Explorer", - "url": "civicrm/api", + "label": "Custom Fields", + "name": "Custom Fields", + "url": "civicrm/admin/custom/group?reset=1", "icon": null, "permission": "administer CiviCRM", "operator": "", "separator": null, - "parentID": "244", - "navID": "245", + "parentID": "114", + "navID": "115", "active": "1" } }, - "246": { + "127": { "attributes": { - "label": "Developer Docs", - "name": "Developer Docs", - "url": "https://civicrm.org/developer-documentation?src=iam", + "label": "Dropdown Options", + "name": "Dropdown Options", + "url": null, "icon": null, "permission": "administer CiviCRM", "operator": "", "separator": null, - "parentID": "244", - "navID": "246", + "parentID": "114", + "navID": "127", "active": "1" + }, + "child": { + "128": { + "attributes": { + "label": "Gender Options", + "name": "Gender Options", + "url": "civicrm/admin/options/gender?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "127", + "navID": "128", + "active": "1" + } + }, + "129": { + "attributes": { + "label": "Individual Prefixes (Ms, Mr...)", + "name": "Individual Prefixes (Ms, Mr...)", + "url": "civicrm/admin/options/individual_prefix?reset=1", + "icon": null, + "permission": "administer CiviCRM", + "operator": "", + "separator": null, + "parentID": "127", + "navID": "129", + "active": "1" + } + } } } } } } - }, - "247": { - "attributes": { - "label": "Reports", - "name": "Reports", - "url": null, - "icon": null, - "permission": "access CiviReport", - "operator": "", - "separator": null, - "parentID": null, - "navID": "247", - "active": "1" - }, - "child": { - "248": { - "attributes": { - "label": "Contact Reports", - "name": "Contact Reports", - "url": "civicrm/report/list?compid=99&reset=1", - "icon": null, - "permission": "administer CiviCRM", - "operator": "", - "separator": "0", - "parentID": "247", - "navID": "248", - "active": "1" - } - }, - "249": { - "attributes": { - "label": "Contribution Reports", - "name": "Contribution Reports", - "url": "civicrm/report/list?compid=2&reset=1", - "icon": null, - "permission": "access CiviContribute", - "operator": "", - "separator": "0", - "parentID": "247", - "navID": "249", - "active": "1" - } - }, - "250": { - "attributes": { - "label": "Pledge Reports", - "name": "Pledge Reports", - "url": "civicrm/report/list?compid=6&reset=1", - "icon": null, - "permission": "access CiviPledge", - "operator": "", - "separator": "0", - "parentID": "247", - "navID": "250", - "active": "1" - } - }, - "251": { - "attributes": { - "label": "Event Reports", - "name": "Event Reports", - "url": "civicrm/report/list?compid=1&reset=1", - "icon": null, - "permission": "access CiviEvent", - "operator": "", - "separator": "0", - "parentID": "247", - "navID": "251", - "active": "1" - } - }, - "252": { - "attributes": { - "label": "Mailing Reports", - "name": "Mailing Reports", - "url": "civicrm/report/list?compid=4&reset=1", - "icon": null, - "permission": "access CiviMail", - "operator": "", - "separator": "0", - "parentID": "247", - "navID": "252", - "active": "1" - } - }, - "253": { - "attributes": { - "label": "Membership Reports", - "name": "Membership Reports", - "url": "civicrm/report/list?compid=3&reset=1", - "icon": null, - "permission": "access CiviMember", - "operator": "", - "separator": "0", - "parentID": "247", - "navID": "253", - "active": "1" - } - }, - "254": { - "attributes": { - "label": "Campaign Reports", - "name": "Campaign Reports", - "url": "civicrm/report/list?compid=9&reset=1", - "icon": null, - "permission": "interview campaign contacts,release campaign contacts,reserve campaign contacts,manage campaign,administer CiviCampaign,gotv campaign contacts", - "operator": "OR", - "separator": "0", - "parentID": "247", - "navID": "254", - "active": "1" - } - }, - "255": { - "attributes": { - "label": "Case Reports", - "name": "Case Reports", - "url": "civicrm/report/list?compid=7&reset=1", - "icon": null, - "permission": "access my cases and activities,access all cases and activities,administer CiviCase", - "operator": "OR", - "separator": "0", - "parentID": "247", - "navID": "255", - "active": "1" - } - }, - "256": { - "attributes": { - "label": "Grant Reports", - "name": "Grant Reports", - "url": "civicrm/report/list?compid=5&reset=1", - "icon": null, - "permission": "access CiviGrant", - "operator": "", - "separator": "0", - "parentID": "247", - "navID": "256", - "active": "1" - } - }, - "257": { - "attributes": { - "label": "All Reports", - "name": "All Reports", - "url": "civicrm/report/list?reset=1", - "icon": null, - "permission": "access CiviReport", - "operator": "", - "separator": "1", - "parentID": "247", - "navID": "257", - "active": "1" - } - }, - "258": { - "attributes": { - "label": "My Reports", - "name": "My Reports", - "url": "civicrm/report/list?myreports=1&reset=1", - "icon": null, - "permission": "access CiviReport", - "operator": "", - "separator": "1", - "parentID": "247", - "navID": "258", - "active": "1" - } - } - } - }, - "264": { - "attributes": { - "label": "Reports", - "name": "hr-reports", - "url": "civicrm/reports", - "icon": "fa fa-table", - "permission": "access hrreports", - "operator": null, - "separator": null, - "parentID": null, - "navID": "264", - "active": "1" - } - }, - "283": { - "attributes": { - "label": "Tasks", - "name": "tasksassignments", - "url": "", - "icon": "crm-i fa-list-ul", - "permission": "access Tasks and Assignments", - "operator": null, - "separator": null, - "parentID": null, - "navID": "283", - "active": "1" - }, - "child": { - "287": { - "attributes": { - "label": "Tasks", - "name": "ta_dashboard_tasks", - "url": "civicrm/tasksassignments/dashboard#/tasks", - "icon": null, - "permission": null, - "operator": null, - "separator": "0", - "parentID": "283", - "navID": "287", - "active": "1" - } - }, - "288": { - "attributes": { - "label": "Documents", - "name": "ta_dashboard_documents", - "url": "civicrm/tasksassignments/dashboard#/documents", - "icon": null, - "permission": null, - "operator": null, - "separator": "0", - "parentID": "283", - "navID": "288", - "active": "1" - } - }, - "289": { - "attributes": { - "label": "Calendar", - "name": "ta_dashboard_calendar", - "url": "civicrm/tasksassignments/dashboard#/calendar", - "icon": null, - "permission": null, - "operator": null, - "separator": "0", - "parentID": "283", - "navID": "289", - "active": "1" - } - }, - "290": { - "attributes": { - "label": "Key Dates", - "name": "ta_dashboard_keydates", - "url": "civicrm/tasksassignments/dashboard#/key-dates", - "icon": null, - "permission": null, - "operator": null, - "separator": "0", - "parentID": "283", - "navID": "290", - "active": "1" - } - } - } - }, - "291": { - "attributes": { - "label": "Leave", - "name": "leave_and_absences_dashboard", - "url": null, - "icon": "crm-i fa-briefcase", - "permission": "access leave and absences", - "operator": null, - "separator": null, - "parentID": null, - "navID": "291", - "active": "1" - }, - "child": { - "299": { - "attributes": { - "label": "Leave Requests", - "name": "leave_and_absences_leave_requests", - "url": "civicrm/leaveandabsences/dashboard#/requests", - "icon": null, - "permission": null, - "operator": null, - "separator": "0", - "parentID": "291", - "navID": "299", - "active": "1" - } - }, - "300": { - "attributes": { - "label": "Leave Calendar", - "name": "leave_and_absences_leave_calendar", - "url": "civicrm/leaveandabsences/dashboard#/calendar", - "icon": null, - "permission": null, - "operator": null, - "separator": "0", - "parentID": "291", - "navID": "300", - "active": "1" - } - }, - "301": { - "attributes": { - "label": "Leave Balances", - "name": "leave_and_absences_leave_balances", - "url": "civicrm/leaveandabsences/dashboard#/leave-balances", - "icon": null, - "permission": null, - "operator": null, - "separator": "0", - "parentID": "291", - "navID": "301", - "active": "1" - } - } - } - }, - "303": { - "attributes": { - "label": "Recruitment", - "name": "Vacancies", - "url": null, - "icon": "crm-i fa-user-plus", - "permission": null, - "operator": null, - "separator": null, - "parentID": null, - "navID": "303", - "active": "1" - }, - "child": { - "304": { - "attributes": { - "label": "Dashboard", - "name": "dashboard", - "url": "civicrm/vacancy/dashboard?reset=1", - "icon": null, - "permission": "view Applicants, manage Applicants, evaluate Applicants, administer Vacancy, administer CiviCRM", - "operator": "OR", - "separator": "0", - "parentID": "303", - "navID": "304", - "active": "1" - } - }, - "305": { - "attributes": { - "label": "Public Vacancy List", - "name": "public_list", - "url": "civicrm/vacancy/publiclisting?reset=1", - "icon": null, - "permission": null, - "operator": null, - "separator": "1", - "parentID": "303", - "navID": "305", - "active": "1" - } - }, - "306": { - "attributes": { - "label": "New Vacancy", - "name": "new_vacancy", - "url": "civicrm/vacancy/add?reset=1", - "icon": null, - "permission": "administer Vacancy, administer CiviCRM", - "operator": "OR", - "separator": "0", - "parentID": "303", - "navID": "306", - "active": "1" - } - }, - "307": { - "attributes": { - "label": "New Template", - "name": "new_template", - "url": "civicrm/vacancy/add?reset=1&template=1", - "icon": null, - "permission": "administer Vacancy, administer CiviCRM", - "operator": "OR", - "separator": "0", - "parentID": "303", - "navID": "307", - "active": "1" - } - }, - "308": { - "attributes": { - "label": "New Applicant", - "name": "new_applicant", - "url": null, - "icon": null, - "permission": null, - "operator": null, - "separator": "1", - "parentID": "303", - "navID": "308", - "active": "1" - } - }, - "309": { - "attributes": { - "label": "Find Vacancies", - "name": "find_vacancies", - "url": "civicrm/vacancy/find?reset=1", - "icon": null, - "permission": "view Applicants, manage Applicants, evaluate Applicants, administer Vacancy, administer CiviCRM", - "operator": "OR", - "separator": "0", - "parentID": "303", - "navID": "309", - "active": "1" - } - }, - "310": { - "attributes": { - "label": "Find Templates", - "name": "find_templates", - "url": "civicrm/vacancy/find?reset=1&template=1", - "icon": null, - "permission": "view Applicants, manage Applicants, evaluate Applicants, administer Vacancy, administer CiviCRM", - "operator": "OR", - "separator": "0", - "parentID": "303", - "navID": "310", - "active": "1" - } - }, - "311": { - "attributes": { - "label": "Search by Application Form Fields", - "name": "find_application", - "url": "civicrm/case/search?force=1&type=5&reset=1", - "icon": null, - "permission": "view Applicants, manage Applicants, evaluate Applicants, administer Vacancy, administer CiviCRM", - "operator": "OR", - "separator": "0", - "parentID": "303", - "navID": "311", - "active": "1" - } - }, - "312": { - "attributes": { - "label": "Search by Evaluation Criteria", - "name": "find_evaluation", - "url": "civicrm/activity/search?force=1&type=114&reset=1", - "icon": null, - "permission": "view Applicants, manage Applicants, evaluate Applicants, administer Vacancy, administer CiviCRM", - "operator": "OR", - "separator": "0", - "parentID": "303", - "navID": "312", - "active": "1" - } - } - } } } diff --git a/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php index 6bc8f44bb36..26683ab9f59 100644 --- a/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php +++ b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php @@ -68,7 +68,7 @@ public function testSettingPermissionWillUpdateItInMenu() { $this->assertEquals('foo', $item['attributes']['permission']); } - public function testFetchingWillNotReturnAReference() { + public function testFindMenuItemByNameWillNotReturnAReference() { $menu = $this->getSampleMenu(); $name = 'Administer/Administration Console/System Status'; $item = NavigationMenuHelper::findMenuItemByPath($menu, $name); @@ -81,7 +81,7 @@ public function testFetchingWillNotReturnAReference() { public function testMovingTopLevelMenuItemsWillChangeTheirPositions() { $menu = $this->getSampleMenu(); $first = 'Home'; - $second = 'Search...'; + $second = 'Contacts'; NavigationMenuHelper::relocateAfter($menu, $first, $second); $newFirst = reset($menu); @@ -254,15 +254,15 @@ public function menuItemNameProvider() { FALSE ], [ - 'Support/About CiviCRM', + 'Contacts/New Organization/New Health_Insurance_Provider', TRUE ], [ - 'Contacts/New Organization/New Life_Insurance_Provider', + 'Administer/Administration Console', TRUE ], [ - 'Events/Register Event Participant', + 'Administer/Customize Data and Screens/Dropdown Options/Gender Options', TRUE ] ]; @@ -274,7 +274,7 @@ public function menuItemNameProvider() { public function itemsToMoveProvider() { return [ [ - 'Vacancies/new_vacancy', + 'Administer/Administration Console', 'Home' ], [ @@ -284,6 +284,10 @@ public function itemsToMoveProvider() { [ 'Administer/Customize Data and Screens/Custom Fields', 'Contacts/New Organization' + ], + [ + 'Administer/Customize Data and Screens/Dropdown Options/Gender Options', + 'Administer/Administration Console', ] ]; } From c23b3195db7a0eb22de997d18372b25e776ce33d Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Wed, 7 Mar 2018 13:41:01 +0000 Subject: [PATCH 018/203] PCHR-3374: Disallow zero offset in function to improve readability --- .../HRCore/Helper/NavigationMenuHelper.php | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php index 8d2dcde5d12..1387c937bb2 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php @@ -78,10 +78,13 @@ public static function relocateAfter( $itemToMovePath, $precedingItemPath ) { - self::relocateWithOffset($menu, $itemToMovePath, $precedingItemPath); + self::relocateWithOffset($menu, $itemToMovePath, $precedingItemPath, 1); } /** + * Moves a given item to the same submenu as another target item. Can be + * placed before or after the target item using an offset. + * * @param $menu * The full menu structure * @param $itemToMovePath @@ -90,14 +93,18 @@ public static function relocateAfter( * The path to the sibling the item will be moved next to * @param int $offset * How many places the item should be before / after the sibling item. Use - * 0 to place it right after it. + * 1 to place it right after it, -1 to put before it */ private static function relocateWithOffset( &$menu, $itemToMovePath, $targetSiblingPath, - $offset = 0 + $offset ) { + if ($offset === 0) { + throw new \Exception('Offset cannot be zero'); + } + $siblings = &self::getSiblingsReference($menu, $targetSiblingPath); $itemToMove = self::findMenuItemByPath($menu, $itemToMovePath); @@ -114,8 +121,14 @@ private static function relocateWithOffset( throw new \Exception($err); } + // we disallow zero offset insertion to make the function clearer, + // however this means positive offsets are 1 higher than they should be + if ($offset > 0) { + $offset--; + } + // array_splice offset should be 1 greater than the target index +/- the - // offset, i.e. if we want to inset 2 after 1 in [1,3] the + // offset, i.e. if we want to insert 2 after 1 in [1,3] the // target index is 0, offset is 0 (right after) so insertion index is 1 $insertionIndex += ($offset + 1); From 035cbd7e985072d01dd49facca46adbf8565e432 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Wed, 7 Mar 2018 15:30:20 +0000 Subject: [PATCH 019/203] PCHR-3374: Cleanup offset logic, comments --- .../CRM/HRCore/Helper/NavigationMenuHelper.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php index 1387c937bb2..1ee57bdda8d 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php @@ -121,16 +121,14 @@ private static function relocateWithOffset( throw new \Exception($err); } - // we disallow zero offset insertion to make the function clearer, - // however this means positive offsets are 1 higher than they should be - if ($offset > 0) { - $offset--; - } + $insertionIndex += $offset; - // array_splice offset should be 1 greater than the target index +/- the - // offset, i.e. if we want to insert 2 after 1 in [1,3] the - // target index is 0, offset is 0 (right after) so insertion index is 1 - $insertionIndex += ($offset + 1); + // the offset is fine as it is for positive offsets, but we skip 0 when + // changing from 'insert after' (offset 1) to 'insert before' (offset -1) + // so we need to adjust negative offsets + if ($offset < 0) { + $insertionIndex++; + } array_splice($siblings, $insertionIndex, 0, [$itemToMove]); } From 0d147c543eeb089808a1f4c4c869b5090f129e1d Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Wed, 7 Mar 2018 15:38:53 +0000 Subject: [PATCH 020/203] PCHR-3374: Handle negative insertion index --- .../CRM/HRCore/Helper/NavigationMenuHelper.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php index 1ee57bdda8d..508e66e13f5 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php @@ -130,6 +130,9 @@ private static function relocateWithOffset( $insertionIndex++; } + // insertion index cannot be lower than 0 (the first element) + $insertionIndex = max(0, $insertionIndex); + array_splice($siblings, $insertionIndex, 0, [$itemToMove]); } From 0391d23ee7f8b4e02b8536d441e8ae929a87d3a4 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Tue, 6 Mar 2018 16:49:02 +0000 Subject: [PATCH 021/203] PCHR-3375: Replace insertChild with simpler 'insert' function --- .../HRCore/Helper/NavigationMenuHelper.php | 67 +++++++++++++------ .../HRCore/Files/sample_navigation_menu.json | 30 +++++++++ .../Helper/NavigationMenuHelperTest.php | 32 +++++++-- 3 files changed, 104 insertions(+), 25 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php index 508e66e13f5..5298aa3ddd7 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Helper/NavigationMenuHelper.php @@ -21,28 +21,33 @@ public static function findMenuItemByPath($menu, $path) { } /** - * Inserts a navigation menu item as a child of the given parent + * Inserts a navigation menu item * * @param array $menu * menu hierarchy - * @param string $parentPath + * @param string $path * Path to the parent menu item, e.g. "Events/Dashboard" - * @param array $itemAttributes - * Attributes of item to insert, e.g. ['name' => 'New Item'] + * @param array $attributes + * Attributes of item to insert, e.g. ['label' => 'New Item'] */ - public static function insertChild(&$menu, $parentPath, $itemAttributes) { - $parent = &self::findMenuItemReferenceByPath($menu, $parentPath); - - if (!$parent) { - $err = sprintf('Cannot find parent item "%s"', $parentPath); - throw new \Exception($err); - } + public static function insert(&$menu, $path, $attributes = []) { + $name = self::getItemNameFromPath($path); + $defaults = ['name' => $name, 'label' => $name, 'active' => 1]; + $newItem = ['attributes' => array_merge($defaults, $attributes)]; + + if (self::isRootItem($path)) { + $menu[] = $newItem; + } else { + $parentPath = self::getParentPathFromPath($path); + $parent = &self::findMenuItemReferenceByPath($menu, $parentPath); - $label = CRM_Utils_Array::value('name', $itemAttributes); - $defaults = ['label' => $label, 'active' => 1]; - $newItem = ['attributes' => array_merge($defaults, $itemAttributes)]; + if (!$parent) { + $err = sprintf('Cannot find parent item "%s"', $parentPath); + throw new \Exception($err); + } - $parent['child'][] = $newItem; + $parent['child'][] = $newItem; + } } /** @@ -246,10 +251,8 @@ private static function &findMenuItemReferenceByName(&$menu, $name) { * @return array */ private static function &getSiblingsReference(&$menu, $path) { - $finalForwardSlashPos = strrpos($path, '/'); - - if (FALSE !== $finalForwardSlashPos) { - $parentPath = substr($path, 0, $finalForwardSlashPos); + if (!self::isRootItem($path)) { + $parentPath = self::getParentPathFromPath($path); $parent = &self::findMenuItemReferenceByPath($menu, $parentPath); $siblings = &$parent['child']; } @@ -260,6 +263,21 @@ private static function &getSiblingsReference(&$menu, $path) { return $siblings; } + /** + * Gets the parent path from a given path, e.g. "Events" from + * "Events/Dashboard" + * + * @param string $path + * + * @return string + */ + private static function getParentPathFromPath($path) { + $path = explode('/', $path); + array_pop($path); + + return implode('/', $path); + } + /** * Like array_search, but for menu items * @@ -293,4 +311,15 @@ private static function getItemNameFromPath($path) { return end($path); } + /** + * Checks whether the given path is a root menu item, i.e. "Home" + * + * @param string $path + * + * @return bool + */ + private static function isRootItem($path) { + return FALSE === strpos($path, '/'); + } + } diff --git a/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Files/sample_navigation_menu.json b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Files/sample_navigation_menu.json index 70046e26207..fb427b924a7 100644 --- a/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Files/sample_navigation_menu.json +++ b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Files/sample_navigation_menu.json @@ -176,6 +176,36 @@ } } } + }, + "292": { + "attributes": { + "label": "Leave", + "name": "leave_and_absences", + "url": null, + "icon": null, + "permission": "administer leave and absences", + "operator": null, + "separator": null, + "parentID": "110", + "navID": "292", + "active": "1" + }, + "child": { + "293": { + "attributes": { + "label": "Leave/Absence Types", + "name": "leave_and_absence_types", + "url": "civicrm/admin/leaveandabsences/types?action=browse&reset=1", + "icon": null, + "permission": "administer leave and absences", + "operator": null, + "separator": "0", + "parentID": "292", + "navID": "293", + "active": "1" + } + } + } } } } diff --git a/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php index 26683ab9f59..e81f3c01ddc 100644 --- a/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php +++ b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Helper/NavigationMenuHelperTest.php @@ -1,11 +1,12 @@ getSampleMenu(); $childName = 'Test Item'; - $newItem = ['name' => $childName]; + $attributes = ['foo' => 'bar']; $parentName = 'Dropdown Options'; $parentPath = 'Administer/Customize Data and Screens/' . $parentName; $childPath = $parentPath . '/' . $childName; - NavigationMenuHelper::insertChild($menu, $parentPath, $newItem); + NavigationMenuHelper::insert($menu, $childPath, $attributes); $added = NavigationMenuHelper::findMenuItemByPath($menu, $childPath); $this->assertNotNull($added); @@ -51,12 +52,31 @@ public function testInsertionWillAddChildMenuItem() { $this->assertEquals($childName, $matchingItem['attributes']['name']); } + public function testInsertionWillAddRootMenuItem() { + $menu = $this->getSampleMenu(); + $name = 'Foo'; + NavigationMenuHelper::insert($menu, $name); + $newestEntry = array_pop($menu); + + $this->assertEquals($name, $newestEntry['attributes']['name']); + } + + public function testAttributesWillOverrideDefaultsInInsertion() { + $menu = $this->getSampleMenu(); + $name = 'Foo'; + $label = 'Bar'; + NavigationMenuHelper::insert($menu, $name, ['label' => $label]); + $newestEntry = array_pop($menu); + + $this->assertEquals($label, $newestEntry['attributes']['label']); + } + public function testInsertionWillThrowExceptionWithInvalidPath() { - $expectedError = 'Cannot find parent item "Bar"'; + $expectedError = 'Cannot find parent item "Foo"'; $this->setExpectedException(\Exception::class, $expectedError); $menu = []; - $parent = 'Bar'; - NavigationMenuHelper::insertChild($menu, $parent, []); + $path = 'Foo/Bar'; + NavigationMenuHelper::insert($menu, $path, []); } public function testSettingPermissionWillUpdateItInMenu() { From 5b60906c82378c3cdd5e2a10ad4afca24f42cab0 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 12 Mar 2018 09:51:40 +0000 Subject: [PATCH 022/203] PCHR-3375: Add upgrader to add link for editing job contract options --- hrjobcontract/CRM/Hrjobcontract/Upgrader.php | 61 ++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php index 3645ec3a097..97dc95e32f9 100755 --- a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php +++ b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php @@ -512,6 +512,7 @@ public function upgradeBundle() { $this->upgrade_1030(); $this->upgrade_1032(); $this->upgrade_1033(); + $this->upgrade_1036(); } function upgrade_1001() { @@ -1207,6 +1208,66 @@ public function upgrade_1035() { return TRUE; } + /** + * Adds a submenu containing links to edit job contract option groups + * + * @return bool + */ + public function upgrade_1036() { + $params = ['return' => 'id', 'name' => 'Administer']; + $administerId = (int) civicrm_api3('Navigation', 'getvalue', $params); + + $permission = 'Access CiviCRM'; + $parent = $this->createNavItem('Job Contract', $permission, $administerId); + $parentId = $parent['id']; + + // Weight cannot be set when creating for the first time + civicrm_api3('Navigation', 'create', ['id' => $parentId, 'weight' => -100]); + + // If we don't flush it will not recognize newly created parent_id + CRM_Core_PseudoConstant::flush(); + + $optionGroupLinks = [ + 'Contract Types' => 'hrjc_contract_type', + 'Normal Place of Work' => 'hrjc_location', + 'Contract End Reasons' => 'hrjc_contract_end_reason', + 'Standard Full Time Hours' => 'hrjc_hours_type', + 'Pay Scales' => 'hrjc_pay_grade', + 'Benefits' => 'hrjc_benefit_type', + 'Deductions' => 'hrjc_deduction_type', + 'Insurance Plan Types' => 'hrjc_insurance_plantype', + ]; + + foreach ($optionGroupLinks as $itemName => $optionGroup) { + $link = 'civicrm/admin/options/' . $optionGroup . '?reset=1'; + $this->createNavItem($itemName, $permission, $parentId, ['url' => $link]); + } + + return TRUE; + } + + /** + * Creates a navigation menu item using the API + * + * @param string $name + * @param string $permission + * @param int $parentID + * @param array $params + * + * @return array + */ + private function createNavItem($name, $permission, $parentID, $params = []) { + $params = array_merge([ + 'name' => $name, + 'label' => ts($name), + 'permission' => $permission, + 'parent_id' => $parentID, + 'is_active' => 1, + ], $params); + + return civicrm_api3('navigation', 'create', $params); + } + /** * Removes the "Pension Type" item from the * "Administer -> Customize Data and Screens -> Dropdowns" menu From e08d740decca9bf9004c861ae3b9919049fedd0e Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 12 Mar 2018 10:47:16 +0000 Subject: [PATCH 023/203] PCHR-3375: Add upgrader to add link for editing job role options --- .../CRM/Hrjobroles/Upgrader.php | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php b/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php index 372818cfdad..d276ad98db0 100644 --- a/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php +++ b/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php @@ -45,6 +45,63 @@ public function upgrade_1004() { return TRUE; } + /** + * Adds a submenu containing links to edit job role option groups + * + * @return bool + */ + public function upgrade_1005() { + $params = ['return' => 'id', 'name' => 'Administer']; + $administerId = (int) civicrm_api3('Navigation', 'getvalue', $params); + + $permission = 'Access CiviCRM'; + $parent = $this->createNavItem('Job Roles', $permission, $administerId); + $parentId = $parent['id']; + + // Weight cannot be set when creating for the first time + civicrm_api3('Navigation', 'create', ['id' => $parentId, 'weight' => -99]); + + // If we don't flush it will not recognize newly created parent_id + CRM_Core_PseudoConstant::flush(); + + $optionGroupLinks = [ + 'Locations' => 'hrjc_location', + 'Regions' => 'hrjc_region', + 'Departments' => 'hrjc_department', + 'Levels' => 'hrjc_level_type', + 'Cost Centres' => 'cost_centres', + ]; + + foreach ($optionGroupLinks as $itemName => $optionGroup) { + $link = 'civicrm/admin/options/' . $optionGroup . '?reset=1'; + $this->createNavItem($itemName, $permission, $parentId, ['url' => $link]); + } + + return TRUE; + } + + /** + * Creates a navigation menu item using the API + * + * @param string $name + * @param string $permission + * @param int $parentID + * @param array $params + * + * @return array + */ + private function createNavItem($name, $permission, $parentID, $params = []) { + $params = array_merge([ + 'name' => $name, + 'label' => ts($name), + 'permission' => $permission, + 'parent_id' => $parentID, + 'is_active' => 1, + ], $params); + + return civicrm_api3('navigation', 'create', $params); + } + /** * Creates new Option Group for Cost Centres */ From 180583654f15b1acdb92e1b33acf485c681c184d Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 12 Mar 2018 10:48:42 +0000 Subject: [PATCH 024/203] PCHR-3375: Add upgrader to add link for editing staff detail options --- .../CRM/HRCore/Upgrader.php | 1 + .../CRM/HRCore/Upgrader/Steps/1012.php | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php index e15a417dc7b..e194b80139f 100755 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php @@ -19,6 +19,7 @@ class CRM_HRCore_Upgrader extends CRM_HRCore_Upgrader_Base { use CRM_HRCore_Upgrader_Steps_1009; use CRM_HRCore_Upgrader_Steps_1010; use CRM_HRCore_Upgrader_Steps_1011; + use CRM_HRCore_Upgrader_Steps_1012; /** * @var array diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php new file mode 100644 index 00000000000..8e3df627d66 --- /dev/null +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php @@ -0,0 +1,70 @@ + 'id', 'name' => 'Administer']; + $administerId = (int) civicrm_api3('Navigation', 'getvalue', $params); + + $permission = 'Access CiviCRM'; + $parentName = 'Other Staff Details'; + $parent = $this->up1012_createNavItem($parentName, $permission, $administerId); + $parentId = $parent['id']; + + // Weight cannot be set when creating for the first time + civicrm_api3('Navigation', 'create', ['id' => $parentId, 'weight' => -98]); + + // If we don't flush it will not recognize newly created parent_id + CRM_Core_PseudoConstant::flush(); + + $optionGroupLinks = [ + 'Prefixes' => 'individual_prefix', + 'Emergency Contact Relationships' => 'relationship_with_employee_20150304120408', + 'Career History' => 'occupation_type_20130617111138', + 'Disability Types' => 'type_20130502151940', + 'Qualifications – Skill Categories' => 'category_of_skill_20130510015438', + 'Qualifications – Skill Levels' => 'level_of_skill_20130510015934', + ]; + + foreach ($optionGroupLinks as $itemName => $optionGroup) { + $link = 'civicrm/admin/options/' . $optionGroup . '?reset=1'; + $params = ['url' => $link]; + $this->up1012_createNavItem($itemName, $permission, $parentId, $params); + } + + return TRUE; + } + + /** + * Creates a navigation menu item using the API + * + * @param string $name + * @param string $permission + * @param int $parentID + * @param array $params + * + * @return array + */ + private function up1012_createNavItem( + $name, + $permission, + $parentID, + $params = [] + ) { + $params = array_merge([ + 'name' => $name, + 'label' => ts($name), + 'permission' => $permission, + 'parent_id' => $parentID, + 'is_active' => 1, + ], $params); + + return civicrm_api3('navigation', 'create', $params); + } +} From 9f11b365856462926a142f3c21438654bde7b364 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 12 Mar 2018 10:53:28 +0000 Subject: [PATCH 025/203] PCHR-3375: Add upgrader to add link for editing L&A options --- .../CRM/HRLeaveAndAbsences/Upgrader.php | 1 + .../HRLeaveAndAbsences/Upgrader/Step/1020.php | 58 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php index ae3b66d8b47..fd996daf1bf 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php @@ -25,6 +25,7 @@ class CRM_HRLeaveAndAbsences_Upgrader extends CRM_HRLeaveAndAbsences_Upgrader_Ba use CRM_HRLeaveAndAbsences_Upgrader_Step_1017; use CRM_HRLeaveAndAbsences_Upgrader_Step_1018; use CRM_HRLeaveAndAbsences_Upgrader_Step_1019; + use CRM_HRLeaveAndAbsences_Upgrader_Step_1020; /** * A list of directories to be scanned for XML installation files diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php new file mode 100644 index 00000000000..0a999f298f0 --- /dev/null +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php @@ -0,0 +1,58 @@ + 'id', 'name' => 'leave_and_absences']; + $parentId = (int) civicrm_api3('Navigation', 'getvalue', $params); + civicrm_api3('Navigation', 'create', ['id' => $parentId, 'weight' => -96]); + + $optionGroupLinks = [ + 'Sickness Reasons' => 'hrleaveandabsences_sickness_reason', + 'TOIL to be Accrued' => 'hrleaveandabsences_toil_amounts', + 'Work Pattern Change Reasons' => 'hrleaveandabsences_work_pattern_change_reason', + 'Work Pattern Day Equivalents' => 'hrleaveandabsences_leave_days_amounts' + ]; + + foreach ($optionGroupLinks as $itemName => $optionGroup) { + $link = 'civicrm/admin/options/' . $optionGroup . '?reset=1'; + $params = ['url' => $link]; + $this->up1020_createNavItem($itemName, $permission, $parentId, $params); + } + + return TRUE; + } + + /** + * Creates a navigation menu item using the API + * + * @param string $name + * @param string $permission + * @param int $parentID + * @param array $params + * + * @return array + */ + private function up1020_createNavItem( + $name, + $permission, + $parentID, + $params = [] + ) { + $params = array_merge([ + 'name' => $name, + 'label' => ts($name), + 'permission' => $permission, + 'parent_id' => $parentID, + 'is_active' => 1, + ], $params); + + return civicrm_api3('navigation', 'create', $params); + } +} From d9363fdb7b7cef535866b690a40af429035c2159 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 12 Mar 2018 11:32:49 +0000 Subject: [PATCH 026/203] PCHR-3375: (unrelated) Fix error about undefined index --- uk.co.compucorp.civicrm.hrcore/hrcore.civix.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/uk.co.compucorp.civicrm.hrcore/hrcore.civix.php b/uk.co.compucorp.civicrm.hrcore/hrcore.civix.php index 2b5dcccfba6..49a45eef221 100644 --- a/uk.co.compucorp.civicrm.hrcore/hrcore.civix.php +++ b/uk.co.compucorp.civicrm.hrcore/hrcore.civix.php @@ -292,7 +292,9 @@ function _hrcore_civix_insert_navigation_menu(&$menu, $path, $item) { $first = array_shift($path); foreach ($menu as $key => &$entry) { if ($entry['attributes']['name'] == $first) { - if (!$entry['child']) $entry['child'] = array(); + if (!isset($entry['child'])) { + $entry['child'] = array(); + } $found = _hrcore_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item, $key); } } From b58bbf44d8082e7c0e172f8a2d3e31ccba37bfb7 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 12 Mar 2018 11:57:07 +0000 Subject: [PATCH 027/203] PCHR-3375: Update links to match specs --- hrjobcontract/CRM/Hrjobcontract/Upgrader.php | 1 + .../CRM/HRCore/Upgrader/Steps/1012.php | 38 ++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php index 97dc95e32f9..4836997b50d 100755 --- a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php +++ b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php @@ -1231,6 +1231,7 @@ public function upgrade_1036() { 'Contract Types' => 'hrjc_contract_type', 'Normal Place of Work' => 'hrjc_location', 'Contract End Reasons' => 'hrjc_contract_end_reason', + 'Contract Revision Reasons' => 'hrjc_revision_change_reason', 'Standard Full Time Hours' => 'hrjc_hours_type', 'Pay Scales' => 'hrjc_pay_grade', 'Benefits' => 'hrjc_benefit_type', diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php index 8e3df627d66..3d1bdeb073d 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php @@ -23,17 +23,26 @@ public function upgrade_1012() { // If we don't flush it will not recognize newly created parent_id CRM_Core_PseudoConstant::flush(); - $optionGroupLinks = [ - 'Prefixes' => 'individual_prefix', - 'Emergency Contact Relationships' => 'relationship_with_employee_20150304120408', - 'Career History' => 'occupation_type_20130617111138', - 'Disability Types' => 'type_20130502151940', - 'Qualifications – Skill Categories' => 'category_of_skill_20130510015438', - 'Qualifications – Skill Levels' => 'level_of_skill_20130510015934', + $childLinks = [ + 'Prefixes' => + $this->getOptionGroupLink('individual_prefix'), + 'Genders' => + $this->getOptionGroupLink('gender'), + 'Emergency Contact Relationships' => + $this->getOptionGroupLink('relationship_with_employee_20150304120408'), + 'Manager Types' => + 'civicrm/admin/reltype?reset=1', + 'Career History' => + $this->getOptionGroupLink('occupation_type_20130617111138'), + 'Disability Types' => + $this->getOptionGroupLink('type_20130502151940'), + 'Qualifications – Skill Categories' => + $this->getOptionGroupLink('category_of_skill_20130510015438'), + 'Qualifications – Skill Levels' => + $this->getOptionGroupLink('level_of_skill_20130510015934'), ]; - foreach ($optionGroupLinks as $itemName => $optionGroup) { - $link = 'civicrm/admin/options/' . $optionGroup . '?reset=1'; + foreach ($childLinks as $itemName => $link) { $params = ['url' => $link]; $this->up1012_createNavItem($itemName, $permission, $parentId, $params); } @@ -41,6 +50,17 @@ public function upgrade_1012() { return TRUE; } + /** + * Gets the link to edit an option group + * + * @param string $groupName + * + * @return string + */ + private function getOptionGroupLink($groupName) { + return 'civicrm/admin/options/' . $groupName . '?reset=1'; + } + /** * Creates a navigation menu item using the API * From ac584cb24738a654489ef0a468f760991df938d5 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 12 Mar 2018 12:32:34 +0000 Subject: [PATCH 028/203] PCHR-3375: Relabel, reorder and add separators for leave submenu --- .../HRLeaveAndAbsences/Upgrader/Step/1020.php | 80 ++++++++++++++++++- 1 file changed, 76 insertions(+), 4 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php index 0a999f298f0..5cde75d55d7 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php @@ -7,12 +7,26 @@ trait CRM_HRLeaveAndAbsences_Upgrader_Step_1020 { * * @return bool */ - public function upgrade_1020() { - $permission = 'administer leave and absences'; + public function upgrade_1021() { $params = ['return' => 'id', 'name' => 'leave_and_absences']; $parentId = (int) civicrm_api3('Navigation', 'getvalue', $params); civicrm_api3('Navigation', 'create', ['id' => $parentId, 'weight' => -96]); + $this->createNewLinks($parentId); + $this->relabelExistingLinks($parentId); + $this->addSeparators($parentId); + $this->updateWeight($parentId); + + return TRUE; + } + + /** + * Creates new entries in the leave submenu + * + * @param int $parentId + */ + private function createNewLinks($parentId) { + $permission = 'administer leave and absences'; $optionGroupLinks = [ 'Sickness Reasons' => 'hrleaveandabsences_sickness_reason', 'TOIL to be Accrued' => 'hrleaveandabsences_toil_amounts', @@ -25,8 +39,60 @@ public function upgrade_1020() { $params = ['url' => $link]; $this->up1020_createNavItem($itemName, $permission, $parentId, $params); } + } - return TRUE; + /** + * Relabels some of the existing leave items + * + * @param int $parentId + */ + private function relabelExistingLinks($parentId) { + $nameToLabelMapping = [ + 'leave_and_absence_types' => ts('Leave Types'), + 'leave_and_absence_periods' => ts('Leave Periods'), + 'leave_and_absence_manage_work_patterns' => ts('Work Patterns'), + 'leave_and_absence_general_settings' => ts('Leave Settings'), + 'leave_and_absences_import' => ts('Import Leave Requests'), + ]; + + foreach ($nameToLabelMapping as $name => $label) { + $params = ['parent_id' => $parentId, 'name' => $name, 'return' => 'id']; + $id = (int) civicrm_api3('Navigation', 'getvalue', $params); + civicrm_api3('Navigation', 'create', ['id' => $id, 'label' => $label]); + } + } + + /** + * Adds separators after certain items in the leave submenu + * + * @param int $parentId + */ + private function addSeparators($parentId) { + $itemsWithSeparators = [ + 'leave_and_absence_general_settings', + 'Work Pattern Day Equivalents', + ]; + + CRM_Core_PseudoConstant::flush(); + + foreach ($itemsWithSeparators as $name) { + $params = ['parent_id' => $parentId, 'name' => $name, 'return' => 'id']; + $id = (int) civicrm_api3('Navigation', 'getvalue', $params); + civicrm_api3('Navigation', 'create', ['id' => $id, 'has_separator' => 1]); + } + } + + /** + * Sets the weight for the "Import" item so it will appear last + * + * @param int $parentId + */ + private function updateWeight($parentId) { + $name = 'leave_and_absences_import'; + $params = ['parent_id' => $parentId, 'name' => $name, 'return' => 'id']; + $id = (int) civicrm_api3('Navigation', 'getvalue', $params); + $maxWeight = CRM_Core_BAO_Navigation::calculateWeight($parentId); + civicrm_api3('Navigation', 'create', ['id' => $id, 'weight' => $maxWeight]); } /** @@ -53,6 +119,12 @@ private function up1020_createNavItem( 'is_active' => 1, ], $params); - return civicrm_api3('navigation', 'create', $params); + $existing = civicrm_api3('Navigation', 'get', $params); + + if ($existing['count'] > 0) { + return array_shift($existing['values']); + } + + return civicrm_api3('Navigation', 'create', $params); } } From 8503b33148b99456b2cae5878be4bdc475bc8a82 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 12 Mar 2018 12:33:23 +0000 Subject: [PATCH 029/203] PCHR-3375: Don't recreate menu items if upgrader is run twice --- com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php | 8 +++++++- .../CRM/HRCore/Upgrader/Steps/1012.php | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php b/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php index d276ad98db0..70663796e59 100644 --- a/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php +++ b/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php @@ -99,7 +99,13 @@ private function createNavItem($name, $permission, $parentID, $params = []) { 'is_active' => 1, ], $params); - return civicrm_api3('navigation', 'create', $params); + $existing = civicrm_api3('Navigation', 'get', $params); + + if ($existing['count'] > 0) { + return array_shift($existing['values']); + } + + return civicrm_api3('Navigation', 'create', $params); } /** diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php index 3d1bdeb073d..e0ff94b19b9 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php @@ -85,6 +85,12 @@ private function up1012_createNavItem( 'is_active' => 1, ], $params); - return civicrm_api3('navigation', 'create', $params); + $existing = civicrm_api3('Navigation', 'get', $params); + + if ($existing['count'] > 0) { + return array_shift($existing['values']); + } + + return civicrm_api3('Navigation', 'create', $params); } } From db4b089543205da606f6ec8da15fe32faf3452d8 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 12 Mar 2018 12:41:26 +0000 Subject: [PATCH 030/203] PCHR-3375: Rename trait methods to avoid conflicts --- .../CRM/HRCore/Upgrader/Steps/1012.php | 16 ++++++++-------- .../HRLeaveAndAbsences/Upgrader/Step/1020.php | 18 +++++++++--------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php index e0ff94b19b9..b19babc208e 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php @@ -25,21 +25,21 @@ public function upgrade_1012() { $childLinks = [ 'Prefixes' => - $this->getOptionGroupLink('individual_prefix'), + $this->up1020_getOptionGroupLink('individual_prefix'), 'Genders' => - $this->getOptionGroupLink('gender'), + $this->up1020_getOptionGroupLink('gender'), 'Emergency Contact Relationships' => - $this->getOptionGroupLink('relationship_with_employee_20150304120408'), + $this->up1020_getOptionGroupLink('relationship_with_employee_20150304120408'), 'Manager Types' => 'civicrm/admin/reltype?reset=1', 'Career History' => - $this->getOptionGroupLink('occupation_type_20130617111138'), + $this->up1020_getOptionGroupLink('occupation_type_20130617111138'), 'Disability Types' => - $this->getOptionGroupLink('type_20130502151940'), + $this->up1020_getOptionGroupLink('type_20130502151940'), 'Qualifications – Skill Categories' => - $this->getOptionGroupLink('category_of_skill_20130510015438'), + $this->up1020_getOptionGroupLink('category_of_skill_20130510015438'), 'Qualifications – Skill Levels' => - $this->getOptionGroupLink('level_of_skill_20130510015934'), + $this->up1020_getOptionGroupLink('level_of_skill_20130510015934'), ]; foreach ($childLinks as $itemName => $link) { @@ -57,7 +57,7 @@ public function upgrade_1012() { * * @return string */ - private function getOptionGroupLink($groupName) { + private function up1020_getOptionGroupLink($groupName) { return 'civicrm/admin/options/' . $groupName . '?reset=1'; } diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php index 5cde75d55d7..ca90607c164 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php @@ -7,15 +7,15 @@ trait CRM_HRLeaveAndAbsences_Upgrader_Step_1020 { * * @return bool */ - public function upgrade_1021() { + public function upgrade_1020() { $params = ['return' => 'id', 'name' => 'leave_and_absences']; $parentId = (int) civicrm_api3('Navigation', 'getvalue', $params); civicrm_api3('Navigation', 'create', ['id' => $parentId, 'weight' => -96]); - $this->createNewLinks($parentId); - $this->relabelExistingLinks($parentId); - $this->addSeparators($parentId); - $this->updateWeight($parentId); + $this->up1020_createNewLinks($parentId); + $this->up1020_relabelExistingLinks($parentId); + $this->up1020_addSeparators($parentId); + $this->up1020_updateWeight($parentId); return TRUE; } @@ -25,7 +25,7 @@ public function upgrade_1021() { * * @param int $parentId */ - private function createNewLinks($parentId) { + private function up1020_createNewLinks($parentId) { $permission = 'administer leave and absences'; $optionGroupLinks = [ 'Sickness Reasons' => 'hrleaveandabsences_sickness_reason', @@ -46,7 +46,7 @@ private function createNewLinks($parentId) { * * @param int $parentId */ - private function relabelExistingLinks($parentId) { + private function up1020_relabelExistingLinks($parentId) { $nameToLabelMapping = [ 'leave_and_absence_types' => ts('Leave Types'), 'leave_and_absence_periods' => ts('Leave Periods'), @@ -67,7 +67,7 @@ private function relabelExistingLinks($parentId) { * * @param int $parentId */ - private function addSeparators($parentId) { + private function up1020_addSeparators($parentId) { $itemsWithSeparators = [ 'leave_and_absence_general_settings', 'Work Pattern Day Equivalents', @@ -87,7 +87,7 @@ private function addSeparators($parentId) { * * @param int $parentId */ - private function updateWeight($parentId) { + private function up1020_updateWeight($parentId) { $name = 'leave_and_absences_import'; $params = ['parent_id' => $parentId, 'name' => $name, 'return' => 'id']; $id = (int) civicrm_api3('Navigation', 'getvalue', $params); From f34c3e359db171f433fa768cfa1eb7ce464ee7f3 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 12 Mar 2018 12:46:21 +0000 Subject: [PATCH 031/203] PCHR-3375: Don't recreate menu items if they exist --- hrjobcontract/CRM/Hrjobcontract/Upgrader.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php index 4836997b50d..41eda3dafbb 100755 --- a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php +++ b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php @@ -1266,7 +1266,13 @@ private function createNavItem($name, $permission, $parentID, $params = []) { 'is_active' => 1, ], $params); - return civicrm_api3('navigation', 'create', $params); + $existing = civicrm_api3('Navigation', 'get', $params); + + if ($existing['count'] > 0) { + return array_shift($existing['values']); + } + + return civicrm_api3('Navigation', 'create', $params); } /** From f2f3747481f263495f95876b83257129c00610a4 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 12 Mar 2018 12:52:43 +0000 Subject: [PATCH 032/203] PCHR-3375: Move flushing to make it clearer why it's needed --- .../CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php index ca90607c164..c19e6fe1141 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php @@ -13,6 +13,8 @@ public function upgrade_1020() { civicrm_api3('Navigation', 'create', ['id' => $parentId, 'weight' => -96]); $this->up1020_createNewLinks($parentId); + // we need to flush for new items to be recognized + CRM_Core_PseudoConstant::flush(); $this->up1020_relabelExistingLinks($parentId); $this->up1020_addSeparators($parentId); $this->up1020_updateWeight($parentId); @@ -73,8 +75,6 @@ private function up1020_addSeparators($parentId) { 'Work Pattern Day Equivalents', ]; - CRM_Core_PseudoConstant::flush(); - foreach ($itemsWithSeparators as $name) { $params = ['parent_id' => $parentId, 'name' => $name, 'return' => 'id']; $id = (int) civicrm_api3('Navigation', 'getvalue', $params); From 6e5ee8c37d72b126e8873d4019c3e72dfd940ade Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 12 Mar 2018 13:10:17 +0000 Subject: [PATCH 033/203] PCHR-3375: Handle case where multiple domains exist Even if we don't have clients with multiple domains, it does exist in the test database and tests fail if this is not handled. --- com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php | 3 ++- hrjobcontract/CRM/Hrjobcontract/Upgrader.php | 3 ++- .../CRM/HRCore/Upgrader/Steps/1012.php | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php b/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php index 70663796e59..e9cd2b5ae5c 100644 --- a/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php +++ b/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php @@ -51,7 +51,8 @@ public function upgrade_1004() { * @return bool */ public function upgrade_1005() { - $params = ['return' => 'id', 'name' => 'Administer']; + $domain = CRM_Core_Config::domainID(); + $params = ['return' => 'id', 'name' => 'Administer', 'domain_id' => $domain]; $administerId = (int) civicrm_api3('Navigation', 'getvalue', $params); $permission = 'Access CiviCRM'; diff --git a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php index 41eda3dafbb..0c5a8d48c03 100755 --- a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php +++ b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php @@ -1214,7 +1214,8 @@ public function upgrade_1035() { * @return bool */ public function upgrade_1036() { - $params = ['return' => 'id', 'name' => 'Administer']; + $domain = CRM_Core_Config::domainID(); + $params = ['return' => 'id', 'name' => 'Administer', 'domain_id' => $domain]; $administerId = (int) civicrm_api3('Navigation', 'getvalue', $params); $permission = 'Access CiviCRM'; diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php index b19babc208e..b9eb3ea92e4 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php @@ -9,7 +9,8 @@ trait CRM_HRCore_Upgrader_Steps_1012 { * @return bool */ public function upgrade_1012() { - $params = ['return' => 'id', 'name' => 'Administer']; + $domain = CRM_Core_Config::domainID(); + $params = ['return' => 'id', 'name' => 'Administer', 'domain_id' => $domain]; $administerId = (int) civicrm_api3('Navigation', 'getvalue', $params); $permission = 'Access CiviCRM'; From 3537654ad2f3951b79a80a4b6c342e5921ac5701 Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Thu, 8 Mar 2018 10:05:49 +0100 Subject: [PATCH 034/203] PCHR-3420: Hide options on localisation page --- .../Hook/BuildForm/LocalisationPageFilter.php | 81 +++++++++++++++++++ uk.co.compucorp.civicrm.hrcore/hrcore.php | 3 +- 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Hook/BuildForm/LocalisationPageFilter.php diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Hook/BuildForm/LocalisationPageFilter.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Hook/BuildForm/LocalisationPageFilter.php new file mode 100644 index 00000000000..e18673cee0b --- /dev/null +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Hook/BuildForm/LocalisationPageFilter.php @@ -0,0 +1,81 @@ +shouldHandle($formName)) { + return; + } + + $this->filterLocalisationOptions($form); + } + + /** + * Checks if the hook should be handled. + * + * @param string $formName + * + * @return bool + */ + private function shouldHandle($formName) { + if ($formName == CRM_Admin_Form_Setting_Localization::class) { + return TRUE; + } + + return FALSE; + } + + /** + * Hide options on localisation page if user does not have required permission + * + * @param CRM_Core_Form $form + */ + private function filterLocalisationOptions($form) { + $canViewAllFields = CRM_Core_Permission::check('access root menu items and configurations '); + $settings = [ + 'customTranslateFunction', + 'contact_default_language', + 'fieldSeparator', + 'inheritLocale', + 'lcMessages', + 'legacyEncoding', + 'monetaryThousandSeparator', + 'monetaryDecimalPoint', + 'moneyformat', + 'moneyvalueformat' + ]; + + if (! $canViewAllFields) { + $this->hideOptionLabels(); + foreach ($settings as $setting) { + if ($form->elementExists($setting)) { + $form->freeze($setting); + } + } + } + } + + /** + * Hide labels for frozen elements + */ + private function hideOptionLabels() { + CRM_Core_Resources::singleton()->addStyle( + 'tr.crm-localization-form-block-lcMessages, + tr.crm-localization-form-block-inheritLocale, + tr.crm-localization-form-contact_default_language, + tr.crm-localization-form-block-monetaryThousandSeparator, + tr.crm-localization-form-block-monetaryDecimalPoint, + tr.crm-localization-form-block-moneyformat, + tr.crm-localization-form-block-moneyvalueformat, + tr.crm-localization-form-block-customTranslateFunction, + tr.crm-localization-form-block-legacyEncoding, + tr.crm-localization-form-block-fieldSeparator { display: none; }' + ); + } + +} diff --git a/uk.co.compucorp.civicrm.hrcore/hrcore.php b/uk.co.compucorp.civicrm.hrcore/hrcore.php index 3ef44d449fe..45b4136ad54 100644 --- a/uk.co.compucorp.civicrm.hrcore/hrcore.php +++ b/uk.co.compucorp.civicrm.hrcore/hrcore.php @@ -110,12 +110,13 @@ function hrcore_civicrm_container($container) { * Implements hook_civicrm_buildForm * * @param string $formName - * @param object $form + * @param CRM_Core_Form $form */ function hrcore_civicrm_buildForm($formName, &$form) { $listeners = [ new CRM_HRCore_Hook_BuildForm_ActivityFilterSelectFieldsModifier(), new CRM_HRCore_Hook_BuildForm_ActivityLinksFilter(), + new CRM_HRCore_Hook_BuildForm_LocalisationPageFilter(), ]; foreach ($listeners as $currentListener) { From c6ad4c259a00317873e752390014781fd4fa4098 Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Mon, 12 Mar 2018 14:12:10 +0100 Subject: [PATCH 035/203] PCHR-3420: Code refactoring --- .../Hook/BuildForm/LocalisationPageFilter.php | 54 ++++++++----------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Hook/BuildForm/LocalisationPageFilter.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Hook/BuildForm/LocalisationPageFilter.php index e18673cee0b..c14e136b384 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Hook/BuildForm/LocalisationPageFilter.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Hook/BuildForm/LocalisationPageFilter.php @@ -1,6 +1,19 @@ hideOptionLabels(); - foreach ($settings as $setting) { + $hiddenOptionsStyle = "tr.crm-localization-form-contact_default_language"; + + foreach ($this->restrictedSettings as $setting) { if ($form->elementExists($setting)) { + $hiddenOptionsStyle .= ", tr.crm-localization-form-block-$setting"; $form->freeze($setting); } } - } - } - /** - * Hide labels for frozen elements - */ - private function hideOptionLabels() { - CRM_Core_Resources::singleton()->addStyle( - 'tr.crm-localization-form-block-lcMessages, - tr.crm-localization-form-block-inheritLocale, - tr.crm-localization-form-contact_default_language, - tr.crm-localization-form-block-monetaryThousandSeparator, - tr.crm-localization-form-block-monetaryDecimalPoint, - tr.crm-localization-form-block-moneyformat, - tr.crm-localization-form-block-moneyvalueformat, - tr.crm-localization-form-block-customTranslateFunction, - tr.crm-localization-form-block-legacyEncoding, - tr.crm-localization-form-block-fieldSeparator { display: none; }' - ); + $hiddenOptionsStyle .= ' { display: none; }'; + CRM_Core_Resources::singleton()->addStyle($hiddenOptionsStyle); + } } } From d167894ba55ea440e39305ace02490ad8d77a989 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 12 Mar 2018 15:01:54 +0000 Subject: [PATCH 036/203] PCHR-3375: Update method name to match trait --- .../CRM/HRCore/Upgrader/Steps/1012.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php index b9eb3ea92e4..2a5505118cc 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php @@ -26,21 +26,21 @@ public function upgrade_1012() { $childLinks = [ 'Prefixes' => - $this->up1020_getOptionGroupLink('individual_prefix'), + $this->up1012_getOptionGroupLink('individual_prefix'), 'Genders' => - $this->up1020_getOptionGroupLink('gender'), + $this->up1012_getOptionGroupLink('gender'), 'Emergency Contact Relationships' => - $this->up1020_getOptionGroupLink('relationship_with_employee_20150304120408'), + $this->up1012_getOptionGroupLink('relationship_with_employee_20150304120408'), 'Manager Types' => 'civicrm/admin/reltype?reset=1', 'Career History' => - $this->up1020_getOptionGroupLink('occupation_type_20130617111138'), + $this->up1012_getOptionGroupLink('occupation_type_20130617111138'), 'Disability Types' => - $this->up1020_getOptionGroupLink('type_20130502151940'), + $this->up1012_getOptionGroupLink('type_20130502151940'), 'Qualifications – Skill Categories' => - $this->up1020_getOptionGroupLink('category_of_skill_20130510015438'), + $this->up1012_getOptionGroupLink('category_of_skill_20130510015438'), 'Qualifications – Skill Levels' => - $this->up1020_getOptionGroupLink('level_of_skill_20130510015934'), + $this->up1012_getOptionGroupLink('level_of_skill_20130510015934'), ]; foreach ($childLinks as $itemName => $link) { @@ -58,7 +58,7 @@ public function upgrade_1012() { * * @return string */ - private function up1020_getOptionGroupLink($groupName) { + private function up1012_getOptionGroupLink($groupName) { return 'civicrm/admin/options/' . $groupName . '?reset=1'; } From 2471dc153751c65e7e313064b028e07468755135 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 12 Mar 2018 16:51:51 +0000 Subject: [PATCH 037/203] PCHR-3375: Add custom fields shortcut --- .../CRM/HRCore/Upgrader/Steps/1012.php | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php index 2a5505118cc..12732d559dd 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php @@ -13,6 +13,17 @@ public function upgrade_1012() { $params = ['return' => 'id', 'name' => 'Administer', 'domain_id' => $domain]; $administerId = (int) civicrm_api3('Navigation', 'getvalue', $params); + $this->up1012_addOtherStaffDetailsSubmenu($administerId); + $this->up1012_addCustomFieldsShortcut($administerId); + + return TRUE; + } + + /** + * @param $administerId + * @throws CiviCRM_API3_Exception + */ + private function up1012_addOtherStaffDetailsSubmenu($administerId) { $permission = 'Access CiviCRM'; $parentName = 'Other Staff Details'; $parent = $this->up1012_createNavItem($parentName, $permission, $administerId); @@ -47,8 +58,24 @@ public function upgrade_1012() { $params = ['url' => $link]; $this->up1012_createNavItem($itemName, $permission, $parentId, $params); } + } - return TRUE; + /** + * Adds a shortcut to the edit custom groups + fields page + * + * @param int $administerId + */ + private function up1012_addCustomFieldsShortcut($administerId) { + $result = $this->up1012_createNavItem( + 'Custom Fields', + 'administer CiviCRM', + $administerId, + ['url' => 'civicrm/admin/custom/group?reset=1'] + ); + + // weight cannot be set when you're creating first time + $id = $result['id']; + civicrm_api3('Navigation', 'create', ['id' => $id, 'weight' => -95]); } /** @@ -94,4 +121,5 @@ private function up1012_createNavItem( return civicrm_api3('Navigation', 'create', $params); } + } From 9009d609968e3f633538a4c1effd752892d8cac6 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 12 Mar 2018 18:07:54 +0000 Subject: [PATCH 038/203] PCHR-3376: Fix the permission name on existing items Permissions are case sensitive and the permission used to create items in PCHR_3375 uses the wrong case for "Access" --- com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php | 2 +- hrjobcontract/CRM/Hrjobcontract/Upgrader.php | 2 +- .../CRM/HRCore/Upgrader/Steps/1012.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php b/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php index e9cd2b5ae5c..3e58b5465f2 100644 --- a/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php +++ b/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php @@ -55,7 +55,7 @@ public function upgrade_1005() { $params = ['return' => 'id', 'name' => 'Administer', 'domain_id' => $domain]; $administerId = (int) civicrm_api3('Navigation', 'getvalue', $params); - $permission = 'Access CiviCRM'; + $permission = 'access CiviCRM'; $parent = $this->createNavItem('Job Roles', $permission, $administerId); $parentId = $parent['id']; diff --git a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php index 0c5a8d48c03..2ecae3b9fff 100755 --- a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php +++ b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php @@ -1218,7 +1218,7 @@ public function upgrade_1036() { $params = ['return' => 'id', 'name' => 'Administer', 'domain_id' => $domain]; $administerId = (int) civicrm_api3('Navigation', 'getvalue', $params); - $permission = 'Access CiviCRM'; + $permission = 'access CiviCRM'; $parent = $this->createNavItem('Job Contract', $permission, $administerId); $parentId = $parent['id']; diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php index 12732d559dd..6175a9d3a1b 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php @@ -24,7 +24,7 @@ public function upgrade_1012() { * @throws CiviCRM_API3_Exception */ private function up1012_addOtherStaffDetailsSubmenu($administerId) { - $permission = 'Access CiviCRM'; + $permission = 'access CiviCRM'; $parentName = 'Other Staff Details'; $parent = $this->up1012_createNavItem($parentName, $permission, $administerId); $parentId = $parent['id']; From 87201da7ec30e7b77130c2a96d9ea7c6193dab6e Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 12 Mar 2018 18:11:08 +0000 Subject: [PATCH 039/203] PCHR-3376: Update the existing permission on "Administer" child items To limit access to existing items on the "Administer" menu we set change the permission from "administer CiviCRM" to "access root menu items and configurations". --- .../CRM/HRCore/Upgrader.php | 1 + .../CRM/HRCore/Upgrader/Steps/1013.php | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1013.php diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php index e194b80139f..2da53861be1 100755 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php @@ -20,6 +20,7 @@ class CRM_HRCore_Upgrader extends CRM_HRCore_Upgrader_Base { use CRM_HRCore_Upgrader_Steps_1010; use CRM_HRCore_Upgrader_Steps_1011; use CRM_HRCore_Upgrader_Steps_1012; + use CRM_HRCore_Upgrader_Steps_1013; /** * @var array diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1013.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1013.php new file mode 100644 index 00000000000..d203a23245a --- /dev/null +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1013.php @@ -0,0 +1,60 @@ + 'id', 'name' => 'Administer', 'domain_id' => $domain]; + $administerId = (int) civicrm_api3('Navigation', 'getvalue', $params); + + $this->up1013_replaceExistingAdministerItemsPermission($administerId); + + return TRUE; + } + + /** + * @param $administerId + * @throws CiviCRM_API3_Exception + */ + private function up1013_replaceExistingAdministerItemsPermission($administerId) { + $allChildren = []; + $this->up1013_findAllChildElements($administerId, $allChildren); + $replacement = 'access root menu items and configurations'; + $original = 'administer CiviCRM'; + + $exceptions = ['Custom Fields']; + + foreach ($allChildren as $child) { + if (in_array($child['name'], $exceptions)) { + continue; + } + + $permissions = CRM_Utils_Array::value('permission', $child); + $permissions = str_replace($original, $replacement, $permissions); + $params = ['id' => $child['id'], 'permission' => $permissions]; + civicrm_api3('Navigation', 'create', $params); + } + } + + /** + * Recursively search for all children of a given parent ID + * + * @param int $parentId + * @param array $allChildren + */ + private function up1013_findAllChildElements($parentId, &$allChildren) { + $params = ['parent_id' => $parentId]; + $children = civicrm_api3('Navigation', 'get', $params)['values']; + $allChildren = array_merge($allChildren, $children); + + foreach ($children as $child) { + $this->up1013_findAllChildElements($child['id'], $allChildren); + } + } + +} From 5170941a9373512489ba94d40c5c88c5479ba69c Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Tue, 13 Mar 2018 13:29:47 +0000 Subject: [PATCH 040/203] PCHR-3376: Add missing "Localise" link --- .../CRM/HRCore/Upgrader/Steps/1012.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php index 6175a9d3a1b..4313fbaed5d 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php @@ -13,12 +13,31 @@ public function upgrade_1012() { $params = ['return' => 'id', 'name' => 'Administer', 'domain_id' => $domain]; $administerId = (int) civicrm_api3('Navigation', 'getvalue', $params); + $this->up1012_addLocalisationShortcut($administerId); $this->up1012_addOtherStaffDetailsSubmenu($administerId); $this->up1012_addCustomFieldsShortcut($administerId); return TRUE; } + /** + * Adds a shortcut to the localization page + * + * @param int $administerId + */ + private function up1012_addLocalisationShortcut($administerId) { + $result = $this->up1012_createNavItem( + 'Localise CiviCRM', + 'access CiviCRM', + $administerId, + ['url' => 'civicrm/admin/setting/localization?reset=1'] + ); + + // weight cannot be set when you're creating first time + $id = $result['id']; + civicrm_api3('Navigation', 'create', ['id' => $id, 'weight' => -101]); + } + /** * @param $administerId * @throws CiviCRM_API3_Exception From a0dba384e5cf8d57eb26a81b9b81410891ff7c68 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Tue, 13 Mar 2018 14:09:53 +0000 Subject: [PATCH 041/203] PCHR-3376: Fix wrong links --- hrjobcontract/CRM/Hrjobcontract/Upgrader.php | 28 +++++++++++--------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php index 2ecae3b9fff..2e1581736d9 100755 --- a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php +++ b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php @@ -1228,20 +1228,24 @@ public function upgrade_1036() { // If we don't flush it will not recognize newly created parent_id CRM_Core_PseudoConstant::flush(); - $optionGroupLinks = [ - 'Contract Types' => 'hrjc_contract_type', - 'Normal Place of Work' => 'hrjc_location', - 'Contract End Reasons' => 'hrjc_contract_end_reason', - 'Contract Revision Reasons' => 'hrjc_revision_change_reason', - 'Standard Full Time Hours' => 'hrjc_hours_type', - 'Pay Scales' => 'hrjc_pay_grade', - 'Benefits' => 'hrjc_benefit_type', - 'Deductions' => 'hrjc_deduction_type', - 'Insurance Plan Types' => 'hrjc_insurance_plantype', + // returns the link to an option group edit page + $optGroupLinker = function ($groupName) { + return 'civicrm/admin/options/' . $groupName . '?reset=1'; + }; + + $childLinks = [ + 'Contract Types' => $optGroupLinker('hrjc_contract_type'), + 'Normal Place of Work' => $optGroupLinker('hrjc_location'), + 'Contract End Reasons' => $optGroupLinker('hrjc_contract_end_reason'), + 'Contract Revision Reasons' => $optGroupLinker('hrjc_revision_change_reason'), + 'Standard Full Time Hours' => 'civicrm/hours_location', + 'Pay Scales' => 'civicrm/pay_scale', + 'Benefits' => $optGroupLinker('hrjc_benefit_name'), + 'Deductions' => $optGroupLinker('hrjc_deduction_name'), + 'Insurance Plan Types' => $optGroupLinker('hrjc_insurance_plantype'), ]; - foreach ($optionGroupLinks as $itemName => $optionGroup) { - $link = 'civicrm/admin/options/' . $optionGroup . '?reset=1'; + foreach ($childLinks as $itemName => $link) { $this->createNavItem($itemName, $permission, $parentId, ['url' => $link]); } From db727d99efa7f22e14750f01ee58de17c686baf2 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Tue, 13 Mar 2018 14:17:02 +0000 Subject: [PATCH 042/203] PCHR-3376: Update docblock --- .../CRM/HRCore/Upgrader/Steps/1013.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1013.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1013.php index d203a23245a..f0604f9636c 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1013.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1013.php @@ -18,8 +18,10 @@ public function upgrade_1013() { } /** - * @param $administerId - * @throws CiviCRM_API3_Exception + * Replaces all existing 'administer CiviCRM' permissions in the + * 'Administer' submenu with 'access root menu items and configurations' + * + * @param int $administerId */ private function up1013_replaceExistingAdministerItemsPermission($administerId) { $allChildren = []; From d43c3d216e0c2e344b55218792af42d7068ab537 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Tue, 13 Mar 2018 14:50:24 +0000 Subject: [PATCH 043/203] PCHR-3376: Fix error when running tests --- .../CRM/HRCore/Upgrader/Steps/1013.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1013.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1013.php index f0604f9636c..7127dd7c34d 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1013.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1013.php @@ -12,6 +12,9 @@ public function upgrade_1013() { $params = ['return' => 'id', 'name' => 'Administer', 'domain_id' => $domain]; $administerId = (int) civicrm_api3('Navigation', 'getvalue', $params); + // If running two consecutive upgraders, items from first are not found + CRM_Core_PseudoConstant::flush(); + $this->up1013_replaceExistingAdministerItemsPermission($administerId); return TRUE; From e8d2cae487075a6cb8672fbbdec0f57d357b175c Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Tue, 13 Mar 2018 17:42:20 +0000 Subject: [PATCH 044/203] PCHR-3162: Re-add upgrader after merging staging The filename had a conflict so I kept Tunbola's changes. This upgrader was originally added by Samson. --- .../CRM/HRCore/Upgrader.php | 1 + .../CRM/HRCore/Upgrader/Steps/1014.php | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1014.php diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php index 2da53861be1..abfce6b0897 100755 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php @@ -21,6 +21,7 @@ class CRM_HRCore_Upgrader extends CRM_HRCore_Upgrader_Base { use CRM_HRCore_Upgrader_Steps_1011; use CRM_HRCore_Upgrader_Steps_1012; use CRM_HRCore_Upgrader_Steps_1013; + use CRM_HRCore_Upgrader_Steps_1014; /** * @var array diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1014.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1014.php new file mode 100644 index 00000000000..f0f441c3fd6 --- /dev/null +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1014.php @@ -0,0 +1,28 @@ + + ['id'], + 'name' => 'Identify', + ]); + + if ($result['id']) { + civicrm_api3('CustomGroup', 'create', [ + 'id' => $result['id'], + 'is_reserved' => 1, + ]); + } + + return TRUE; + } +} From 1b6f9a88e5afe20002846a633d33538210890540 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Wed, 14 Mar 2018 09:34:01 +0000 Subject: [PATCH 045/203] PCHR-3162: Fix upgrader number After I copied over the upgrader I forgot to update the number in the method, leading to a conflict --- .../CRM/HRCore/Upgrader/Steps/1014.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1014.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1014.php index f0f441c3fd6..3093a8db73a 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1014.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1014.php @@ -10,7 +10,7 @@ trait CRM_HRCore_Upgrader_Steps_1014 { * * @return bool */ - public function upgrade_1011() { + public function upgrade_1014() { $result = civicrm_api3('CustomGroup', 'get', [ 'return' => ['id'], 'name' => 'Identify', From 4eac009dad72706ba3705ad1e3b8725435da9e3f Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Wed, 14 Mar 2018 16:33:57 +0100 Subject: [PATCH 046/203] PCHR-3451: New option group work pattern change --- .../CRM/HRLeaveAndAbsences/Upgrader.php | 1 + .../HRLeaveAndAbsences/Upgrader/Step/1021.php | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php index fd996daf1bf..9b9fd3058a4 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php @@ -26,6 +26,7 @@ class CRM_HRLeaveAndAbsences_Upgrader extends CRM_HRLeaveAndAbsences_Upgrader_Ba use CRM_HRLeaveAndAbsences_Upgrader_Step_1018; use CRM_HRLeaveAndAbsences_Upgrader_Step_1019; use CRM_HRLeaveAndAbsences_Upgrader_Step_1020; + use CRM_HRLeaveAndAbsences_Upgrader_Step_1021; /** * A list of directories to be scanned for XML installation files diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php new file mode 100644 index 00000000000..9211f2fbf59 --- /dev/null +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php @@ -0,0 +1,42 @@ + $groupName + ]); + if ($result['count'] > 0) { + return TRUE; + } + + $groupValues = [ + 'As per contract', + 'Change in contractual hours', + 'Change in contract type' + ]; + $optionParams = [ + 'name' => $groupName, + 'title' => 'Leave and Absence Work Pattern Change Reason', + 'is_active' => 1 + ]; + civicrm_api3('OptionGroup', 'create', $optionParams); + foreach ($groupValues as $value) { + $opValueParams = [ + 'option_group_id' => $groupName, + 'name' => $value, + 'label' => $value, + ]; + civicrm_api3('OptionValue', 'create', $opValueParams); + } + return TRUE; + } +} From c1ea6128721d7f4b375218ef7058e25f0a2101d3 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Thu, 15 Mar 2018 10:31:30 +0000 Subject: [PATCH 047/203] PCHR-3162: Update label --- hrjobcontract/CRM/Hrjobcontract/Upgrader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php index 2e1581736d9..bbf8d939910 100755 --- a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php +++ b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php @@ -1235,7 +1235,7 @@ public function upgrade_1036() { $childLinks = [ 'Contract Types' => $optGroupLinker('hrjc_contract_type'), - 'Normal Place of Work' => $optGroupLinker('hrjc_location'), + 'Normal Places of Work' => $optGroupLinker('hrjc_location'), 'Contract End Reasons' => $optGroupLinker('hrjc_contract_end_reason'), 'Contract Revision Reasons' => $optGroupLinker('hrjc_revision_change_reason'), 'Standard Full Time Hours' => 'civicrm/hours_location', From 9c50684782ece3ee08df557ccb404c3ba7f190e7 Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Fri, 16 Mar 2018 06:05:56 +0100 Subject: [PATCH 048/203] PCHR-3451: Added work pattern change reason XML for setup and updated references --- .../DAO/ContactWorkPattern.php | 6 +-- .../HRLeaveAndAbsences/Upgrader/Step/1021.php | 33 +++--------- ...ces_work_pattern_change_reason_install.xml | 52 +++++++++++++++++++ .../HRLeaveAndAbsences/ContactWorkPattern.xml | 2 +- 4 files changed, 62 insertions(+), 31 deletions(-) create mode 100644 uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/leave_and_absences_work_pattern_change_reason_install.xml diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/ContactWorkPattern.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/ContactWorkPattern.php index fd25c5fe6e2..bbf08516e2b 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/ContactWorkPattern.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/ContactWorkPattern.php @@ -173,7 +173,7 @@ static function &fields() { 'name' => 'change_reason', 'type' => CRM_Utils_Type::T_STRING, 'title' => ts('Change Reason') , - 'description' => 'One of the values of the Job Contract Revision Change Reason option group', + 'description' => 'One of the values of the Work Pattern Change Reasons option group', 'maxlength' => 512, 'size' => CRM_Utils_Type::HUGE, 'table_name' => 'civicrm_hrleaveandabsences_contact_work_pattern', @@ -181,8 +181,8 @@ static function &fields() { 'bao' => 'CRM_HRLeaveAndAbsences_DAO_ContactWorkPattern', 'localizable' => 0, 'pseudoconstant' => array( - 'optionGroupName' => 'hrjc_revision_change_reason', - 'optionEditPath' => 'civicrm/admin/options/hrjc_revision_change_reason', + 'optionGroupName' => 'hrleaveandabsences_work_pattern_change_reason', + 'optionEditPath' => 'civicrm/admin/options/hrleaveandabsences_work_pattern_change_reason', ) ) , ); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php index 9211f2fbf59..49dc2326372 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php @@ -10,33 +10,12 @@ trait CRM_HRLeaveAndAbsences_Upgrader_Step_1021 { * @return bool */ public function upgrade_1021() { - $groupName = 'hrleaveandabsences_work_pattern_change_reason'; - $result = civicrm_api3('OptionGroup', 'get', [ - 'name' => $groupName - ]); - if ($result['count'] > 0) { - return TRUE; - } - - $groupValues = [ - 'As per contract', - 'Change in contractual hours', - 'Change in contract type' - ]; - $optionParams = [ - 'name' => $groupName, - 'title' => 'Leave and Absence Work Pattern Change Reason', - 'is_active' => 1 - ]; - civicrm_api3('OptionGroup', 'create', $optionParams); - foreach ($groupValues as $value) { - $opValueParams = [ - 'option_group_id' => $groupName, - 'name' => $value, - 'label' => $value, - ]; - civicrm_api3('OptionValue', 'create', $opValueParams); - } + require_once 'CRM/Utils/Migrate/Import.php'; + $import = new CRM_Utils_Migrate_Import(); + $extension = 'uk.co.compucorp.civicrm.hrleaveandabsences'; + $file = 'xml/option_groups/leave_and_absences_work_pattern_change_reason_install.xml'; + + $import->run(CRM_Core_Resources::singleton()->getPath($extension, $file)); return TRUE; } } diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/leave_and_absences_work_pattern_change_reason_install.xml b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/leave_and_absences_work_pattern_change_reason_install.xml new file mode 100644 index 00000000000..cca90fa0782 --- /dev/null +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/leave_and_absences_work_pattern_change_reason_install.xml @@ -0,0 +1,52 @@ + + + + + + + hrleaveandabsences_work_pattern_change_reason + Leave and Absence Work Pattern Change Reason + 1 + 1 + + + + + + + 1 + as_per_contract + 1 + 0 + 0 + 1 + 1 + hrleaveandabsences_work_pattern_change_reason + + + + + 2 + change_in_contractual_hours + 0 + 2 + 0 + 1 + 1 + hrleaveandabsences_work_pattern_change_reason + + + + + 3 + change_in_contractual_type + 0 + 3 + 0 + 1 + 1 + hrleaveandabsences_work_pattern_change_reason + + + + diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/ContactWorkPattern.xml b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/ContactWorkPattern.xml index 1e0f18cd1be..cf51391c881 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/ContactWorkPattern.xml +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/ContactWorkPattern.xml @@ -73,7 +73,7 @@ One of the values of the Job Contract Revision Change Reason option group 4.4 - hrjc_revision_change_reason + hrleaveandabsences_work_pattern_change_reason From 50a6b80347493147d9bcacd9dbe09bbe1f7e7163 Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Fri, 16 Mar 2018 12:23:01 +0100 Subject: [PATCH 049/203] PCHR-3451: Code refactoring --- .../CRM/HRLeaveAndAbsences/DAO/ContactWorkPattern.php | 4 ++-- .../CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php | 3 +-- ...son_install.xml => work_pattern_change_reason_install.xml} | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) rename uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/{leave_and_absences_work_pattern_change_reason_install.xml => work_pattern_change_reason_install.xml} (95%) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/ContactWorkPattern.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/ContactWorkPattern.php index bbf08516e2b..54698a2c44a 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/ContactWorkPattern.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/ContactWorkPattern.php @@ -181,8 +181,8 @@ static function &fields() { 'bao' => 'CRM_HRLeaveAndAbsences_DAO_ContactWorkPattern', 'localizable' => 0, 'pseudoconstant' => array( - 'optionGroupName' => 'hrleaveandabsences_work_pattern_change_reason', - 'optionEditPath' => 'civicrm/admin/options/hrleaveandabsences_work_pattern_change_reason', + 'optionGroupName' => 'hrjc_revision_change_reason', + 'optionEditPath' => 'civicrm/admin/options/hrjc_revision_change_reason', ) ) , ); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php index 49dc2326372..ab6deb84992 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php @@ -10,10 +10,9 @@ trait CRM_HRLeaveAndAbsences_Upgrader_Step_1021 { * @return bool */ public function upgrade_1021() { - require_once 'CRM/Utils/Migrate/Import.php'; $import = new CRM_Utils_Migrate_Import(); $extension = 'uk.co.compucorp.civicrm.hrleaveandabsences'; - $file = 'xml/option_groups/leave_and_absences_work_pattern_change_reason_install.xml'; + $file = 'xml/option_groups/work_pattern_change_reason_install.xml'; $import->run(CRM_Core_Resources::singleton()->getPath($extension, $file)); return TRUE; diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/leave_and_absences_work_pattern_change_reason_install.xml b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/work_pattern_change_reason_install.xml similarity index 95% rename from uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/leave_and_absences_work_pattern_change_reason_install.xml rename to uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/work_pattern_change_reason_install.xml index cca90fa0782..74e6d20bd1b 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/leave_and_absences_work_pattern_change_reason_install.xml +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/work_pattern_change_reason_install.xml @@ -5,7 +5,7 @@ hrleaveandabsences_work_pattern_change_reason - Leave and Absence Work Pattern Change Reason + Work Pattern Change Reason 1 1 From 0169930f02d73efd91a3566ddcaddf24926e71dc Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Mon, 19 Mar 2018 18:44:01 +0100 Subject: [PATCH 050/203] PCHR-3451: Frontend update and test integration --- .../DAO/ContactWorkPattern.php | 8 ++-- ...tab-custom-work-pattern-modal.component.js | 10 ++--- ...ustom-work-pattern-modal.component.spec.js | 8 +++- .../test/mocks/data/option-group.data.js | 37 +++++++++++++++++++ .../work_pattern_change_reason_install.xml | 8 ++-- 5 files changed, 56 insertions(+), 15 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/ContactWorkPattern.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/ContactWorkPattern.php index 54698a2c44a..5c0a0e1be47 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/ContactWorkPattern.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/ContactWorkPattern.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/HRLeaveAndAbsences/ContactWorkPattern.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:dd2637660ac3be9bdaeb2955643974ae) + * (GenCodeChecksum:ded89fd6039ec891ba28b56d418a3179) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -173,7 +173,7 @@ static function &fields() { 'name' => 'change_reason', 'type' => CRM_Utils_Type::T_STRING, 'title' => ts('Change Reason') , - 'description' => 'One of the values of the Work Pattern Change Reasons option group', + 'description' => 'One of the values of the Job Contract Revision Change Reason option group', 'maxlength' => 512, 'size' => CRM_Utils_Type::HUGE, 'table_name' => 'civicrm_hrleaveandabsences_contact_work_pattern', @@ -181,8 +181,8 @@ static function &fields() { 'bao' => 'CRM_HRLeaveAndAbsences_DAO_ContactWorkPattern', 'localizable' => 0, 'pseudoconstant' => array( - 'optionGroupName' => 'hrjc_revision_change_reason', - 'optionEditPath' => 'civicrm/admin/options/hrjc_revision_change_reason', + 'optionGroupName' => 'hrleaveandabsences_work_pattern_change_reason', + 'optionEditPath' => 'civicrm/admin/options/hrleaveandabsences_work_pattern_change_reason', ) ) , ); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component.js index bb35ad96785..4a4bde2c0c7 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component.js @@ -46,9 +46,9 @@ define([ loadWorkPatterns(), loadJobContractRevisionChangeReasons() ]) - .finally(function () { - vm.loading.content = false; - }); + .finally(function () { + vm.loading.content = false; + }); })(); /** @@ -107,12 +107,12 @@ define([ } /** - * Loads the Job Contract Revision Change Reasons and indexes by `value` + * Loads the Leave and Absences Work Pattern Change Reason and indexes by `value` * * @return {Promise} */ function loadJobContractRevisionChangeReasons () { - return OptionGroup.valuesOf('hrjc_revision_change_reason') + return OptionGroup.valuesOf('hrleaveandabsences_work_pattern_change_reason') .then(function (reasons) { vm.changeReasons = reasons; }); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/absence-tab/components/absence-tab-custom-work-pattern-modal.component.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/absence-tab/components/absence-tab-custom-work-pattern-modal.component.spec.js index e06748e339d..4a2bad6c9ee 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/absence-tab/components/absence-tab-custom-work-pattern-modal.component.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/absence-tab/components/absence-tab-custom-work-pattern-modal.component.spec.js @@ -34,7 +34,7 @@ spyOn($log, 'debug'); spyOn(WorkPatternAPI, 'get').and.callThrough(); spyOn(OptionGroup, 'valuesOf').and.callFake(function () { - return $q.resolve(optionGroupMock.getCollection('hrjc_revision_change_reason')); + return $q.resolve(optionGroupMock.getCollection('hrleaveandabsences_work_pattern_change_reason')); }); compileComponent(); @@ -49,8 +49,12 @@ }); describe('init()', function () { + it('calls the valueOf with hrleaveandabsences_work_pattern_change_reason', function () { + expect(OptionGroup.valuesOf).toHaveBeenCalledWith('hrleaveandabsences_work_pattern_change_reason'); + }); + it('loads change reasons', function () { - expect(controller.changeReasons).toEqual(optionGroupMock.getCollection('hrjc_revision_change_reason')); + expect(controller.changeReasons).toEqual(optionGroupMock.getCollection('hrleaveandabsences_work_pattern_change_reason')); }); it('loads work patterns', function () { diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/data/option-group.data.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/data/option-group.data.js index fce76f3e0f2..8ffbcb8efb9 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/data/option-group.data.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/data/option-group.data.js @@ -863,6 +863,43 @@ define([ 'is_reserved': '0', 'is_active': '1' }], + hrleaveandabsences_work_pattern_change_reason: [{ + 'id': '1314', + 'option_group_id': '196', + 'label': 'As per contract', + 'value': '1', + 'name': 'as_per_contract', + 'filter': '0', + 'is_default': '1', + 'weight': '1', + 'is_optgroup': '0', + 'is_reserved': '0', + 'is_active': '1' + }, { + 'id': '1315', + 'option_group_id': '196', + 'label': 'Change in contractual hours', + 'value': '2', + 'name': 'change_in_contractual_hours', + 'filter': '0', + 'is_default': '0', + 'weight': '2', + 'is_optgroup': '0', + 'is_reserved': '0', + 'is_active': '1' + }, { + 'id': '1316', + 'option_group_id': '196', + 'label': 'Change in contractual type', + 'value': '3', + 'name': 'change_in_contractual_type', + 'filter': '0', + 'is_default': '0', + 'weight': '3', + 'is_optgroup': '0', + 'is_reserved': '0', + 'is_active': '1' + }], safe_file_extension: [{ 'id': '296', 'option_group_id': '30', diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/work_pattern_change_reason_install.xml b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/work_pattern_change_reason_install.xml index 74e6d20bd1b..e30adffdf3a 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/work_pattern_change_reason_install.xml +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/work_pattern_change_reason_install.xml @@ -17,9 +17,9 @@ 1 as_per_contract 1 - 0 + 1 0 - 1 + 0 1 hrleaveandabsences_work_pattern_change_reason @@ -31,7 +31,7 @@ 0 2 0 - 1 + 0 1 hrleaveandabsences_work_pattern_change_reason @@ -43,7 +43,7 @@ 0 3 0 - 1 + 0 1 hrleaveandabsences_work_pattern_change_reason From 8a7dfe7297d0f0a9995690678ba008fda524d08d Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Tue, 20 Mar 2018 11:29:48 +0000 Subject: [PATCH 051/203] PCHR-3451: Code refactoring --- .../js/angular/dist/absence-tab.min.js | 4 ++-- .../absence-tab-custom-work-pattern-modal.component.js | 4 ++-- .../absence-tab-custom-work-pattern-modal.component.spec.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js index 319ab39ee97..e7dcdbb2cad 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js @@ -1,5 +1,5 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,o){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,r){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),r=e.assign({},r,{absence_type_id:a,date:t(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",r).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,o,s,r){return t.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return s.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,o,s,r){return this.sendPOST("ContactWorkPattern","create",e.assign({},r,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,o,s){return t.debug("WorkPatternAPI.getCalendar",n,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,o){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,o,s,r){function i(t,n){return u().then(function(a){var o=this.days[c(t).valueOf()];return!!o&&e.find(a,function(e){return e.name===n}).value===o.type}.bind(this))}function c(e){return t(e,s.serverDateFormat).clone()}function u(){return l=l||r.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[c(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,o){return t.debug("Calendar"),n.extend({get:function(n,s,r,i){return t.debug("Calendar.get"),a.getCalendar(n,s,r,i).then(function(t){var a=t.values.map(function(e){return o.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function o(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,o,s){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return o.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,o,s,r){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,o,s,"getFull",r)),i.promise},balanceChangeByAbsenceType:function(t,n,o,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var r=a.defer();t&&n||r.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:o?{IN:o}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){r.resolve(e.values)}),r.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?o.reject(t(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,o,s,r,i,c){function u(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),r=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(r.date)]).then(function(t){return s.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,o&&(r.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return r.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(s.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,o,s,r){return n.all(this.processFilters(e),t,o,s,r).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,o){return n.balanceChangeByAbsenceType(e,t,a,o)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/instances/work-pattern.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("WorkPatternInstance",["$log","ModelInstance",function(e,t){return e.debug("WorkPatternInstance"),t.extend({})}])}),define("leave-absences/shared/models/work-pattern.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/work-pattern.instance"],function(e,t){"use strict";t.factory("WorkPattern",["$log","Model","WorkPatternAPI","WorkPatternInstance",function(t,n,a,o){return t.debug("WorkPattern"),n.extend({assignWorkPattern:function(e,t,n,o,s,r){return a.assignWorkPattern(e,t,n,o,s,r)},default:function(){return a.get({is_default:!0}).then(function(t){return o.init(e.first(t),!0)})},unassignWorkPattern:function(e){return a.unassignWorkPattern(e)},workPatternsOf:function(e,t,n){return a.workPatternsOf(e,t,n).then(function(e){return e.map(function(e){return o.init(e,!0)})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,o,s,r,i){function c(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function u(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?c():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return o.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):r.all()}function m(e){return"me"===e?o.leaveManagees(v.contactId):"unassigned"===e?o.leaveManagees(void 0,{unassigned:!0}):o.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

","

People I approve filter displays only staff members who you approve leave for.

","

People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

"].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,u()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:r.contactId}).leaveManagees().then(function(e){r.lookupContacts=e}).then(o)}}}function o(){return t.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:r.filters.userSettings.department?r.filters.userSettings.department.value:null,level_type:r.filters.userSettings.level_type?r.filters.userSettings.level_type.value:null,location:r.filters.userSettings.location?r.filters.userSettings.location.value:null,region:r.filters.userSettings.region?r.filters.userSettings.region.value:null,id:{IN:r.filters.userSettings.contact?[r.filters.userSettings.contact.id]:r.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var r;return{init:function(e){return r=e,r.showContactName=!0,r.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function o(a,o,s,r,i,c,u,l,d,m){function f(){for(var e=[],t=n(O.selectedPeriod.start_date).clone().startOf("month"),a=n(O.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(A(t)),t.add(1,"month");O.months=e}function p(){r.$new().$watch(function(){return O.selectedMonths},function(t,n){null===n||e.equals(t,n)||w()})}function h(e){O.injectMonths=!0,L("injected").then(function(){w(e)}).then(function(){O.loading.calendar=!1})}function v(){S=a("LeaveCalendar"+t.capitalize(M)+"Controller").init(O)}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function g(){return c.all().then(function(e){O.absencePeriods=t.sortBy(e,"start_date"),O.selectedPeriod=t.find(O.absencePeriods,function(e){return!!e.current})}).then(f).then(I)}function _(){return u.all().then(u.loadCalculationUnits)}function y(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return S.loadContacts().then(function(e){O.contacts=e})}function C(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){O.filters.optionValues.regions=e.hrjc_region,O.filters.optionValues.locations=e.hrjc_location,O.filters.optionValues.levelTypes=e.hrjc_level_type,O.filters.optionValues.departments=e.hrjc_department})}function P(){return l.all()}function D(){return o.all([_(),P(),y()]).then(function(e){O.supportData.absenceTypes=e[0],O.supportData.publicHolidays=e[1],O.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,O.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,O.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,O.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function R(){var e=o.resolve();return O.injectMonths&&(e=L("destroyed"),O.injectMonths=!1),e}function A(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function T(e){e=t.includes(["contacts","period"],e)?e:"period",o.resolve().then(function(){O.loading.calendar=!0}).then(R).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function w(e){var n=O.selectedMonths.length?O.months.filter(function(e){return t.includes(O.selectedMonths,e.index)}):O.months;r.$emit("LeaveCalendar::showMonths",n,!!e)}function I(){O.selectedMonths=[n().month()]}function k(){return O.roleOverride?o.resolve().then(function(){M=O.roleOverride}):o.all([m(i.permissions.admin.administer),m(i.permissions.ssp.manage)]).then(function(e){M=e[0]?"admin":e[1]?"manager":"staff"})}function L(e){return o(function(n){var a=0,o=r.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===O.months.length&&(o(),n())})})}s.debug("Component: leave-calendar");var S,M,O=this;O.absencePeriods=[],O.contacts=[],O.contactIdsToReduceTo=null,O.injectMonths=!1,O.months=[],O.selectedMonths=null,O.selectedPeriod=null,O.showContactName=!1,O.showFilters=!1,O.supportData={},O.loading={calendar:!0,page:!0},O.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},O.labelPeriod=b,O.refresh=T,function(){k().then(p).then(v).then(R).then(g).then(function(){return o.all([q(),D()])}).then(function(){return O.showFilters?C():t.noop}).then(function(){h()}).then(function(){O.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",o]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,o){"use strict";function s(){y.calculationUnit=r(y.supportData.calculationUnits,"value",b.calculation_unit)}function r(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(y.contactData.leaveRequest.from_date).isSame(y.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+y.calculationUnit.name+"-on-"+e+"-tooltip"}function c(){b=r(y.supportData.absenceTypes,"id",y.contactData.leaveRequest.type_id),y.contactData.leaveRequest["type_id.title"]=b.title}function u(){"days"===y.calculationUnit.name&&(g=r(y.supportData.dayTypes,"value",y.contactData.leaveRequest.from_date_type),_=r(y.supportData.dayTypes,"value",y.contactData.leaveRequest.to_date_type),y.contactData.leaveRequest["from_date_type.label"]=g.label,y.contactData.leaveRequest["to_date_type.label"]=_.label)}function l(e,t,n,a,s){e.stopPropagation(),o.openModal(t,n,a,s)}function d(){y.dates.from=new Date(y.contactData.leaveRequest.from_date),y.dates.to=new Date(y.contactData.leaveRequest.to_date)}function m(){y.contactData.isAccruedTOIL?y.label="AT":"days"===y.calculationUnit.name?f():p()}function f(){y.label=y.contactData.isAM?"AM":y.contactData.isPM?"PM":""}function p(){var e=t(y.contactData.leaveRequest.from_date).isSame(y.date,"day"),n=t(y.contactData.leaveRequest.to_date).isSame(y.date,"day");y.label=e?t(y.contactData.leaveRequest.from_date).format("HH:mm"):n?t(y.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){y.tooltipTemplate=y.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){y.contactData&&y.contactData.leaveRequest&&(c(),s(),u(),m(),d(),h()) -})}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,r,i,c){function u(e){_([e]),N(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return U[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){S(e),N(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=R(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){F.push(o.$on("LeaveCalendar::showMonths",x)),F.push(i.subscribe("LeaveRequest::new",u)),F.push(i.subscribe("LeaveRequest::edit",B)),F.push(i.subscribe("LeaveRequest::updatedByManager",B)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function P(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function D(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function R(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function A(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function T(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function w(){return[T(c.statusNames.approved),T(c.statusNames.adminApproved),T(c.statusNames.awaitingApproval),T(c.statusNames.moreInformationRequired)]}function I(){return H.month.loading=!0,a.all([L(),k()]).then(b).then($).then(function(){j=!0}).then(function(){H.month.loading=!1})}function k(){return r.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:w()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function L(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function S(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function M(){o.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function O(t,n,o){var s,r;return t.contactsData[n]=t.contactsData[n]||{},r=m(n),s=!0===o?a.resolve():a.all([r.isWeekend(p(t.date)),r.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:P(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?D(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function $(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return O(e,t.id)}))}))}function x(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!j)&&I())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=A(e);t&&(h(t),-1!==w().indexOf(e.status_id)&&u(e))}function N(e){return a.all(R(e).map(function(t){return O(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var j=!1,F=[],U={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=M,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,r,i,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(r.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=P[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(P,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:P[e].label,isDirectAction:P[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,P={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,r,i,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,r.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l,d,m,f){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function h(e){return t(e,c.serverDateFormat).toDate()}function v(e){return t(e).format(c.serverDateFormat)}function b(e){var t;return r.resolve().then(function(){J(e),"from"===e&&Q(),N("hours")&&(y(e),"from"!==e||pe.uiOptions.multipleDays||y("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return P(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return r.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return G()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(N("hours"))return H(e).then(function(){ne(e,!0)})}).then(function(){if(se(),!t)return V();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(I)}function g(){return se(),V()}function _(){return pe.uiOptions.toDate=null,J("to"),r.resolve().then(function(){if(N("hours")&&pe.uiOptions.fromDate)return y("from"),!pe.uiOptions.multipleDays&&y("to"),H("from").then(function(){ne("from",!0)}).then(se)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&V)}function y(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&s&&o&&(s=A(s).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=A(o).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function C(t,n){return t?(t=v(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):D(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):r.reject([])}function P(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function D(e,n){return e=t(e),r.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function R(){return pe.request?pe.request.request_type:pe.leaveType||null}function A(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(K).catch(I)}function w(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function I(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function k(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?V():T()}function L(){var e=pe.request.attributes();return pe.uiOptions.fromDate=h(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=h(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function S(e){s.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){N("days")||+e==+t||(re(),pe.performBalanceChangeCalculation())})}function M(){fe.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){ue()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",V))}function O(){pe.isMode("edit")&&(pe.isLeaveStatus(c.statusNames.approved)||pe.isLeaveStatus(c.statusNames.adminApproved))&&(me={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function $(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(w(a.min,n)<=0||w(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function x(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return r.all(e.map(H)).then(function(){["from","to"].forEach(function(e){$(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(re)}function E(){["from","to"].forEach(function(e){S(e),B(e)})}function B(e){s.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){N("days")||t===n||(se(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function N(e){return pe.selectedAbsenceType.calculation_unit_name===e}function j(e){return pe.request.request_type===e}function F(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return C(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function W(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function H(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(v(t)).then(function(t){he[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return he[e]={},I(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):r.resolve()}function G(){return u.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function Y(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function V(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(K).catch(I).finally(function(){pe.loading.balanceChange=!1})):r.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function X(){return v(pe.request.from_date)===v(pe.request.to_date)}function Q(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,J("to"))}function J(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,se(),re(),ie()}function K(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=h(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=h(pe.period.end_date)}function ee(){return!pe.isMode("create")&&X()||pe.isMode("create")&&(j("sickness")||N("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,r.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,i=he[a].number_of_hours?w(s,r).toString():"0";o.maxAmount=i,t&&(o.amount=o.maxAmount)}function ae(){me&&me.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=me.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function oe(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function se(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?v(e.fromDate):null,pe.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),N("hours")&&!j("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function re(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ce(){e.forEach(fe,function(e){e()})}function ue(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return oe(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),r.resolve().then(e&&ee).then(function(){if(e&&N("hours"))return H("from").then(function(){ne("from",!0)})}).then(e&&se).then(V)}function le(e){return pe.absenceTypes=e,oe(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,J("to")),ae(),V()}function de(e){var t=A(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(A(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(A(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var me=null,fe=[],pe=this,he={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=c.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:Y},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=h,pe.convertDateToServerFormat=v,pe.dateChangeHandler=b,pe.dateTypeChangeHandler=g,pe.daysSelectionModeChangeHandler=_,pe.isLeaveType=j,pe.isNotWorkingDay=F,pe.performBalanceChangeCalculation=V,pe.$onDestroy=ce,function(){n("RequestModalDetails"+e.capitalize(R(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",pe),M(),pe.initChildController().then(function(){return r.all([G(),W()])}).then(!pe.isMode("create")&&L).then(ee).then(function(){if(!pe.isMode("create")&&N("hours"))return x().then(se)}).then(!pe.isMode("create")&&Z).then(O).then(ae).then(k).then(function(){pe.isMode("view")||j("toil")||E()}).catch(I).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l){function d(){return k.fileUploader&&k.fileUploader.queue.length>0}function m(){return k.getFilesAmount()0?T.map(function(e){return e.label}).join(", "):""}function q(){return k.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(T.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){I[e.label]=t})})).catch(function(){I=null})}function P(){return c.valuesOf("safe_file_extension").then(function(e){T=e})}function D(e){return!e.attachment_id||k.canManage}function R(){e.forEach(w,function(e){e()})}function A(e,t){k.fileUploader.queue&&k.fileUploader.queue.length>0?k.fileUploader.uploadAll({entityID:k.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var T=[],w=[],I={},k=Object.create(this);return k.filesLoaded=!1,k.fileUploader=null,k.today=Date.now(),k.userDateFormatWithTime=r.DATE_FORMAT+" HH:mm",k.userDateFormat=r.DATE_FORMAT,k.$onDestroy=R,k.canRemoveAttachment=D,k.canSubmit=d,k.canUploadMore=m,k.formatDateTime=f,k.getAuthorName=p,k.getFilesAmount=h,k.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",k),g(),a.all([P(),q()]).then(_).finally(function(){k.filesLoaded=!0})}(),k}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,o){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"},{type:"toil",icon:"calendar-plus-o",label:"Overtime"}],s.openLeavePopup=a,function(){o=n.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{btnClass:"@",contactId:"<",selectedContactId:"<",isSelfRecord:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,o,s,r,i,c,u,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):W.refresh()}function b(t){t.dataIndex=e.indexBy(t.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return r.all().then(r.loadCalculationUnits).then(function(t){W.absenceTypes=t,W.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return T("approved",{status_id:F(m.statusNames.approved)})}function C(){return n.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function P(){return i.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(t){var n=e.find(W.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function D(){return i.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return O(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function R(){return n.all([i.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),A({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:O(e[0]),expiredTOILS:$(e[1].list)})}).then(function(t){W.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function A(t){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function T(e,t){return A(t).then(function(t){W.sections[e].data=t.list})}function w(){return n.all(Object.values(W.sections).filter(function(e){return e.open}).map(S))}function I(){return T("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function k(){return T("pending",{status_id:{ -in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function L(){return T("holidays",{public_holiday:!0})}function S(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function M(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){W.leaveRequestStatuses=e.indexBy(t,"value")})}function O(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(W.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function $(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function x(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(W.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],B(t,a))})}function B(e,t){var n=W.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function N(){W.loading.content=!0,n.all([P(),C()]).then(function(){W.loading.content=!1}).then(function(){return n.all([w(),h()])})}function j(e){var t=W.sections[e];t.open=!t.open,t.open&&!t.data.length&&S(t)}function F(t){return e.find(W.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:D},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:L},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:k},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:I}},W.labelPeriod=g,W.refresh=N,W.toggleSection=j,function(){n.all([M(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return n.all([P(),C()])}).then(function(){W.loading.content=!1}),x()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["leave-absences/shared/modules/controllers"],function(e){function t(e,t,n,a){function o(){return a.request.calculateBalanceChange(a.selectedAbsenceType.calculation_unit_name)}function s(){var e=a.request,t=!!e.from_date&&!!e.to_date,n=a.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function r(){return a.canCalculateChange()}function i(){return n.resolve()}t.debug("RequestModalDetailsLeaveController"),a.calculateBalanceChange=o,a.canCalculateChange=s,a.canSubmit=r,a.initChildController=i}e.controller("RequestModalDetailsLeaveController",t),t.$inject=["$controller","$log","$q","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function r(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function i(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=r,s.initChildController=i,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s,r){function i(){return r.balance.change.amount=+r.request.toil_to_accrue,n.resolve(r.balance.change)}function c(){return f().catch(function(e){return e.length&&(r.errors=e),n.reject(e)}).then(function(e){return s.calculateToilExpiryDate(r.request.type_id,e)}).then(function(e){return r.request.toil_expiry_date=e,r.uiOptions.expiryDate=new Date(e),e})}function u(){return!!r.request.toil_to_accrue}function l(){var e=r.uiOptions.multipleDays&&!!r.request.to_date,t=!r.uiOptions.multipleDays&&!!r.request.from_date,n=t||e,a=D.from_date!==r.request.from_date||D.to_date!==r.request.to_date;return r.canDisplayToilExpirationField&&n&&R.hasExpirationFromAdminSettings&&a}function d(){return!!(r.request.from_date&&r.request.to_date&&r.request.toil_duration&&r.request.toil_to_accrue)}function m(){r.request.toil_expiry_date=!1,r.uiOptions.expiryDate=null}function f(){var e=r.uiOptions.multipleDays,t=r.request;return p({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function p(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return n.reject([t])}return e.value?n.resolve(e.value):n.reject([])}function h(){var e=r.isMode("create")&&R.hasExpirationFromAdminSettings,t=R.hasPreviousExpirationDate,n=r.isLeaveType("toil"),a=r.canManage;r.canDisplayToilExpirationField=n&&(a||e||t)}function v(){return R.hasPreviousExpirationDate=r.isMode("edit")&&!!r.request.toil_expiry_date,s.canExpire(r.request.type_id).then(function(e){R.hasExpirationFromAdminSettings=e})}function b(){return r.request.to_date_type=r.request.from_date_type="1",v().then(h).then(g).then(y)}function g(){r.canManage&&(r.uiOptions.expiryDate=r.convertDateFormatFromServer(r.request.toil_expiry_date))}function _(){r.isMode("view")||a.$watch(function(){return r.request.toil_to_accrue},function(e,t){+e!=+t&&r.performBalanceChangeCalculation()})}function y(){return o.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){r.toilAmounts=e.indexBy(t,"value")})}function q(){D=angular.copy(r.request.attributes())}function C(){return l()?c().catch(n.resolve):n.resolve()}function P(){r.uiOptions.expiryDate&&(r.request.toil_expiry_date=r.convertDateToServerFormat(r.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var D,R={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};r.canDisplayToilExpirationField=!1,r.calculateBalanceChange=i,r.canCalculateChange=u,r.canSubmit=d,r.clearExpiryDate=m,r.initChildController=b,r.onDateChangeExtended=C,r.setDaysSelectionModeExtended=C,r.updateExpiryDate=P,function(){_(),q()}()}t.controller("RequestModalDetailsToilController",n),n.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),r={date:o};return a.all(r).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={toilDurationHours:"0",toilDurationMinutes:"0",request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},transformAttributes:function(e){var t=Number(e.toil_duration);return t&&(e.toilDurationHours=Math.floor(t/60).toString(),e.toilDurationMinutes=(t%60).toString()),e},updateDuration:function(){this.toil_duration=60*Number(this.toilDurationHours)+Number(this.toilDurationMinutes)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files","toilDurationHours","toilDurationMinutes"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,r,i,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,P){function D(e){"days"===$e.selectedAbsenceType.calculation_unit_name?delete $e.request[e+"_date_amount"]:delete $e.request[e+"_date_type"]}function R(){["from","to"].forEach(D)}function A(){var e=$e.requestStatuses[y.statusNames.awaitingApproval].value;Ie.status_id===e&&e!==$e.request.status_id&&d.publish("ManagerBadge:: Update Count")}function T(){return Oe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return Oe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return!$e.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function k(){var e=T();return $e.isMode("edit")&&(e=e&&(G()||w())),$e.canManage&&$e.requestStatuses&&(e=e&&!!$e.getStatusFromValue($e.newStatusOnSave)),(e=e&&!!$e.period.id)&&!$e.isMode("view")}function L(){$e.isSelfRecord?$e.request.status_id=$e.requestStatuses[y.statusNames.awaitingApproval].value:$e.canManage&&($e.request.status_id=$e.newStatusOnSave||$e.request.status_id)}function S(){if($e.isMode("edit")&&!$e.isRole("staff")&&"toil"!==F())return $e.request.calculateBalanceChange($e.selectedAbsenceType.calculation_unit_name).then(function(e){if(+$e.balance.change.amount!=+e.amount)return P.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function M(){$e.errors=[]}function O(){return $e.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function $(){ee()&&!$e.isRole("staff")&&($e.request.change_balance=!0)}function x(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return $e.request.delete().then(function(){$e.dismissModal(),d.publish("LeaveRequest::delete",$e.request)})}})}function E(){i.dismiss({$value:"cancel"})}function B(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function N(){return j($e.getStatusFromValue($e.request.status_id).name)}function j(e){return n.map(Te[e],function(e){return $e.requestStatuses[e]})}function F(){return $e.request?$e.request.request_type:$e.leaveType||null}function U(){return!$e.request||e.equals({},$e.requestStatuses)?[]:$e.request.status_id?N():j("none")}function W(e){return n.find($e.requestStatuses,function(t){return t.value===e})}function H(e){$e.errors=n.isArray(e)?e:[e],$e.loading.absenceTypes=!1,$e.submitting=!1}function G(){return!e.equals(Ie,$e.request.attributes())||$e.canManage&&$e.newStatusOnSave}function Y(){return $e.postContactSelection=!0,$e.staffMemberSelectionComplete=!1,$e.request.contact_id?o.resolve().then(ie).then(ce).then(he).then(be).then(Z).then(z).then($e.isMode("edit")?ge:n.noop).then(function(){$e.postContactSelection=!1,$e.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Se)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Te.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Te.awaiting_approval=e,Te.more_information_required=e,Te.rejected=e,Te.approved=e,Te.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return $e.canManage?f.find($e.request.contact_id).then(function(e){$e.contactName=e.display_name}):o.resolve()}function X(){ke.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",$e.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){we++})),r.$on("$destroy",Pe),r.$on("LeaveRequestPopup::addTab",function(e,t){Oe.push(t)})}function Q(){var e,t;$e.request=$e.leaveRequest||null,e=F(),t=$e.initRequestAttributes(),"leave"===e?$e.request=_.init(t):"sickness"===e?$e.request=q.init(t):"toil"===e&&($e.request=C.init(t))}function J(){var e={};return $e.request?e=$e.request.attributes():$e.canManage||(e={contact_id:Le}),e}function K(){if(Me="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(Me="admin")}).then(function(){return"staff"===Me&&c(y.permissions.ssp.manage).then(function(e){e&&(Me="manager")})}).finally(function(){$e.canManage=$e.isRole("manager")||$e.isRole("admin")})}function Z(){($e.isRole("admin")||$e.isMode("create")&&$e.isRole("manager"))&&($e.newStatusOnSave=$e.requestStatuses[y.statusNames.approved].value)}function ee(){return!$e.request.status_id||!n.includes(["cancelled","rejected"],W($e.request.status_id).name)}function te(e){var t=$e.getStatusFromValue($e.request.status_id);return!!t&&t.name===e}function ne(e){return $e.request&&$e.request.request_type===e}function ae(e){return $e.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return Me===e}function re(){return h.all().then(function(e){$e.absencePeriods=e})}function ie(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Ae={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return $e.loading.entitlements=!0,b.all({contact_id:$e.request.contact_id,period_id:$e.period.id,type_id:{IN:Ae.ids}},!0).finally(function(){$e.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Le=e.contactId})}function le(){return $e.selectedContactId?f.find($e.selectedContactId).then(function(e){$e.managedContacts=[e]}):$e.isRole("admin")?f.all().then(function(e){$e.managedContacts=n.remove(e.list,function(e){return e.id!==Le})}):f.find(Le).then(function(e){return e.leaveManagees()}).then(function(e){$e.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){$e.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){A(),d.publish(e,$e.request),$e.errors=[],$e.dismissModal()}function pe(){["from","to"].forEach(function(e){$e.request[e+"_date"]=Ie[e+"_date"]})}function he(e){if($e.absenceTypes=me(Ae.types,e),!$e.absenceTypes.length)return o.reject(Se)}function ve(){$e.period=n.find($e.absencePeriods,function(e){return $e.isMode("create")?e.current:oe($e.request,e)})}function be(){$e.isMode("create")?($e.selectedAbsenceType=$e.absenceTypes[0],$e.request.type_id=$e.selectedAbsenceType.id):$e.selectedAbsenceType=n.find($e.absenceTypes,function(e){return e.id===$e.request.type_id})}function ge(){Ie=e.copy($e.request.attributes())}function _e(){var e;$e.request.id?(e=[$e.requestStatuses[y.statusNames.approved].value,$e.requestStatuses[y.statusNames.adminApproved].value,$e.requestStatuses[y.statusNames.rejected].value,$e.requestStatuses[y.statusNames.cancelled].value],$e.mode="edit",$e.isRole("staff")&&e.indexOf($e.request.status_id)>-1&&($e.mode="view")):$e.mode="create"}function ye(){var e=$e.request.status_id;if(!$e.isMode("view")&&!$e.submitting)return $e.submitting=!0,L(),R(),$e.request.isValid().then(ee()&&S).then($).then(!$e.request.change_balance&&pe).then(qe).then(function(){return $e.isMode("edit")?Re():O()}).catch(function(t){$e.request.status_id=e,t&&H(t)}).finally(function(){$e.submitting=!1})}function qe(){return o.all(Oe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===we&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return we>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Pe(){ke.forEach(function(e){e()})}function De(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Re(){return $e.request.update().then(Ce).then(function(){$e.isRole("manager")?fe("LeaveRequest::updatedByManager"):($e.isRole("staff")||$e.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Ae,Te={},we=0,Ie={},ke=[],Le="",Se="No entitlement",Me="",Oe=[],$e=n.assign(this,m);$e.absencePeriods=[],$e.absenceTypes=[],$e.canManage=!1,$e.contactName=null,$e.errors=[],$e.loading={absenceTypes:!0,entitlements:!0},$e.managedContacts=[],$e.mode="",$e.newStatusOnSave=null,$e.period={},$e.postContactSelection=!1,$e.requestStatuses={},$e.selectedAbsenceType={},$e.staffMemberSelectionComplete=!1,$e.submitting=!1,$e.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},$e.canChangeAbsenceType=I,$e.canSubmit=k,$e.closeAlert=M,$e.deleteLeaveRequest=x,$e.dismissModal=E,$e.getStatuses=U,$e.getStatusFromValue=W,$e.initAfterContactSelection=Y,$e.initRequestAttributes=J,$e.isLeaveStatus=te,$e.isLeaveType=ne,$e.isMode=ae,$e.isRole=se,$e.submit=ye,$e.updateAbsenceType=De,function(){$e.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),re(),de()]).then(Q).then(_e).then(ve).then(function(){return $e.canManage&&!$e.isMode("edit")&&le()}).then(function(){if($e.selectedContactId&&($e.request.contact_id=$e.selectedContactId),$e.request.contact_id)return $e.initAfterContactSelection()}).catch(H).finally(function(){$e.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,r,i,c){function u(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,r,i){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:r,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,r){function i(e){l.errorMessage=e}function c(){return r.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrjc_revision_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,r.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(i).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrjc_revision_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(),g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){i.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){r.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,r){function i(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,r){n=o.entitlements.slice(0,r),a=e.entitlements.slice(r+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,r;return s=e.indexBy(n,"entitlement_id.type_id"),r=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:r}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){ +})}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,r,i,c){function u(e){_([e]),N(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return U[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){S(e),N(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=R(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){j.push(o.$on("LeaveCalendar::showMonths",x)),j.push(i.subscribe("LeaveRequest::new",u)),j.push(i.subscribe("LeaveRequest::edit",B)),j.push(i.subscribe("LeaveRequest::updatedByManager",B)),j.push(i.subscribe("LeaveRequest::delete",h)),j.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function P(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function D(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function R(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function A(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function T(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function w(){return[T(c.statusNames.approved),T(c.statusNames.adminApproved),T(c.statusNames.awaitingApproval),T(c.statusNames.moreInformationRequired)]}function I(){return H.month.loading=!0,a.all([L(),k()]).then(b).then($).then(function(){F=!0}).then(function(){H.month.loading=!1})}function k(){return r.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:w()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function L(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function S(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function M(){o.$emit("LeaveCalendar::monthDestroyed"),j.map(function(e){e.remove?e.remove():e()})}function O(t,n,o){var s,r;return t.contactsData[n]=t.contactsData[n]||{},r=m(n),s=!0===o?a.resolve():a.all([r.isWeekend(p(t.date)),r.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:P(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?D(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function $(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return O(e,t.id)}))}))}function x(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!F)&&I())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=A(e);t&&(h(t),-1!==w().indexOf(e.status_id)&&u(e))}function N(e){return a.all(R(e).map(function(t){return O(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var F=!1,j=[],U={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=M,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,r,i,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(r.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=P[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(P,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:P[e].label,isDirectAction:P[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,P={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,r,i,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,r.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l,d,m,f){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function h(e){return t(e,c.serverDateFormat).toDate()}function v(e){return t(e).format(c.serverDateFormat)}function b(e){var t;return r.resolve().then(function(){J(e),"from"===e&&Q(),N("hours")&&(y(e),"from"!==e||pe.uiOptions.multipleDays||y("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return P(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return r.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return G()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(N("hours"))return H(e).then(function(){ne(e,!0)})}).then(function(){if(se(),!t)return V();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(I)}function g(){return se(),V()}function _(){return pe.uiOptions.toDate=null,J("to"),r.resolve().then(function(){if(N("hours")&&pe.uiOptions.fromDate)return y("from"),!pe.uiOptions.multipleDays&&y("to"),H("from").then(function(){ne("from",!0)}).then(se)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&V)}function y(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&s&&o&&(s=A(s).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=A(o).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function C(t,n){return t?(t=v(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):D(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):r.reject([])}function P(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function D(e,n){return e=t(e),r.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function R(){return pe.request?pe.request.request_type:pe.leaveType||null}function A(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(K).catch(I)}function w(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function I(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function k(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?V():T()}function L(){var e=pe.request.attributes();return pe.uiOptions.fromDate=h(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=h(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function S(e){s.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){N("days")||+e==+t||(re(),pe.performBalanceChangeCalculation())})}function M(){fe.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){ue()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",V))}function O(){pe.isMode("edit")&&(pe.isLeaveStatus(c.statusNames.approved)||pe.isLeaveStatus(c.statusNames.adminApproved))&&(me={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function $(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(w(a.min,n)<=0||w(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function x(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return r.all(e.map(H)).then(function(){["from","to"].forEach(function(e){$(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(re)}function E(){["from","to"].forEach(function(e){S(e),B(e)})}function B(e){s.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){N("days")||t===n||(se(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function N(e){return pe.selectedAbsenceType.calculation_unit_name===e}function F(e){return pe.request.request_type===e}function j(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return C(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function W(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function H(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(v(t)).then(function(t){he[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return he[e]={},I(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):r.resolve()}function G(){return u.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function Y(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function V(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(K).catch(I).finally(function(){pe.loading.balanceChange=!1})):r.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function X(){return v(pe.request.from_date)===v(pe.request.to_date)}function Q(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,J("to"))}function J(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,se(),re(),ie()}function K(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=h(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=h(pe.period.end_date)}function ee(){return!pe.isMode("create")&&X()||pe.isMode("create")&&(F("sickness")||N("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,r.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,i=he[a].number_of_hours?w(s,r).toString():"0";o.maxAmount=i,t&&(o.amount=o.maxAmount)}function ae(){me&&me.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=me.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function oe(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function se(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?v(e.fromDate):null,pe.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),N("hours")&&!F("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function re(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ce(){e.forEach(fe,function(e){e()})}function ue(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return oe(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),r.resolve().then(e&&ee).then(function(){if(e&&N("hours"))return H("from").then(function(){ne("from",!0)})}).then(e&&se).then(V)}function le(e){return pe.absenceTypes=e,oe(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,J("to")),ae(),V()}function de(e){var t=A(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(A(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(A(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var me=null,fe=[],pe=this,he={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=c.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:Y},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=h,pe.convertDateToServerFormat=v,pe.dateChangeHandler=b,pe.dateTypeChangeHandler=g,pe.daysSelectionModeChangeHandler=_,pe.isLeaveType=F,pe.isNotWorkingDay=j,pe.performBalanceChangeCalculation=V,pe.$onDestroy=ce,function(){n("RequestModalDetails"+e.capitalize(R(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",pe),M(),pe.initChildController().then(function(){return r.all([G(),W()])}).then(!pe.isMode("create")&&L).then(ee).then(function(){if(!pe.isMode("create")&&N("hours"))return x().then(se)}).then(!pe.isMode("create")&&Z).then(O).then(ae).then(k).then(function(){pe.isMode("view")||F("toil")||E()}).catch(I).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l){function d(){return k.fileUploader&&k.fileUploader.queue.length>0}function m(){return k.getFilesAmount()0?T.map(function(e){return e.label}).join(", "):""}function q(){return k.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(T.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){I[e.label]=t})})).catch(function(){I=null})}function P(){return c.valuesOf("safe_file_extension").then(function(e){T=e})}function D(e){return!e.attachment_id||k.canManage}function R(){e.forEach(w,function(e){e()})}function A(e,t){k.fileUploader.queue&&k.fileUploader.queue.length>0?k.fileUploader.uploadAll({entityID:k.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var T=[],w=[],I={},k=Object.create(this);return k.filesLoaded=!1,k.fileUploader=null,k.today=Date.now(),k.userDateFormatWithTime=r.DATE_FORMAT+" HH:mm",k.userDateFormat=r.DATE_FORMAT,k.$onDestroy=R,k.canRemoveAttachment=D,k.canSubmit=d,k.canUploadMore=m,k.formatDateTime=f,k.getAuthorName=p,k.getFilesAmount=h,k.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",k),g(),a.all([P(),q()]).then(_).finally(function(){k.filesLoaded=!0})}(),k}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,o){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"},{type:"toil",icon:"calendar-plus-o",label:"Overtime"}],s.openLeavePopup=a,function(){o=n.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{btnClass:"@",contactId:"<",selectedContactId:"<",isSelfRecord:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,o,s,r,i,c,u,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):W.refresh()}function b(t){t.dataIndex=e.indexBy(t.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return r.all().then(r.loadCalculationUnits).then(function(t){W.absenceTypes=t,W.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return T("approved",{status_id:j(m.statusNames.approved)})}function C(){return n.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[j(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[j(m.statusNames.awaitingApproval),j(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function P(){return i.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(t){var n=e.find(W.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function D(){return i.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return O(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function R(){return n.all([i.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),A({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:O(e[0]),expiredTOILS:$(e[1].list)})}).then(function(t){W.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function A(t){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function T(e,t){return A(t).then(function(t){W.sections[e].data=t.list})}function w(){return n.all(Object.values(W.sections).filter(function(e){return e.open}).map(S))}function I(){return T("other",{status_id:{in:[j(m.statusNames.rejected),j(m.statusNames.cancelled)]}})}function k(){return T("pending",{status_id:{ +in:[j(m.statusNames.awaitingApproval),j(m.statusNames.moreInformationRequired)]}})}function L(){return T("holidays",{public_holiday:!0})}function S(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function M(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){W.leaveRequestStatuses=e.indexBy(t,"value")})}function O(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(W.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function $(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function x(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(W.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],B(t,a))})}function B(e,t){var n=W.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function N(){W.loading.content=!0,n.all([P(),C()]).then(function(){W.loading.content=!1}).then(function(){return n.all([w(),h()])})}function F(e){var t=W.sections[e];t.open=!t.open,t.open&&!t.data.length&&S(t)}function j(t){return e.find(W.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:D},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:L},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:k},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:I}},W.labelPeriod=g,W.refresh=N,W.toggleSection=F,function(){n.all([M(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return n.all([P(),C()])}).then(function(){W.loading.content=!1}),x()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["leave-absences/shared/modules/controllers"],function(e){function t(e,t,n,a){function o(){return a.request.calculateBalanceChange(a.selectedAbsenceType.calculation_unit_name)}function s(){var e=a.request,t=!!e.from_date&&!!e.to_date,n=a.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function r(){return a.canCalculateChange()}function i(){return n.resolve()}t.debug("RequestModalDetailsLeaveController"),a.calculateBalanceChange=o,a.canCalculateChange=s,a.canSubmit=r,a.initChildController=i}e.controller("RequestModalDetailsLeaveController",t),t.$inject=["$controller","$log","$q","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function r(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function i(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=r,s.initChildController=i,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s,r){function i(){return r.balance.change.amount=+r.request.toil_to_accrue,n.resolve(r.balance.change)}function c(){return f().catch(function(e){return e.length&&(r.errors=e),n.reject(e)}).then(function(e){return s.calculateToilExpiryDate(r.request.type_id,e)}).then(function(e){return r.request.toil_expiry_date=e,r.uiOptions.expiryDate=new Date(e),e})}function u(){return!!r.request.toil_to_accrue}function l(){var e=r.uiOptions.multipleDays&&!!r.request.to_date,t=!r.uiOptions.multipleDays&&!!r.request.from_date,n=t||e,a=D.from_date!==r.request.from_date||D.to_date!==r.request.to_date;return r.canDisplayToilExpirationField&&n&&R.hasExpirationFromAdminSettings&&a}function d(){return!!(r.request.from_date&&r.request.to_date&&r.request.toil_duration&&r.request.toil_to_accrue)}function m(){r.request.toil_expiry_date=!1,r.uiOptions.expiryDate=null}function f(){var e=r.uiOptions.multipleDays,t=r.request;return p({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function p(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return n.reject([t])}return e.value?n.resolve(e.value):n.reject([])}function h(){var e=r.isMode("create")&&R.hasExpirationFromAdminSettings,t=R.hasPreviousExpirationDate,n=r.isLeaveType("toil"),a=r.canManage;r.canDisplayToilExpirationField=n&&(a||e||t)}function v(){return R.hasPreviousExpirationDate=r.isMode("edit")&&!!r.request.toil_expiry_date,s.canExpire(r.request.type_id).then(function(e){R.hasExpirationFromAdminSettings=e})}function b(){return r.request.to_date_type=r.request.from_date_type="1",v().then(h).then(g).then(y)}function g(){r.canManage&&(r.uiOptions.expiryDate=r.convertDateFormatFromServer(r.request.toil_expiry_date))}function _(){r.isMode("view")||a.$watch(function(){return r.request.toil_to_accrue},function(e,t){+e!=+t&&r.performBalanceChangeCalculation()})}function y(){return o.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){r.toilAmounts=e.indexBy(t,"value")})}function q(){D=angular.copy(r.request.attributes())}function C(){return l()?c().catch(n.resolve):n.resolve()}function P(){r.uiOptions.expiryDate&&(r.request.toil_expiry_date=r.convertDateToServerFormat(r.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var D,R={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};r.canDisplayToilExpirationField=!1,r.calculateBalanceChange=i,r.canCalculateChange=u,r.canSubmit=d,r.clearExpiryDate=m,r.initChildController=b,r.onDateChangeExtended=C,r.setDaysSelectionModeExtended=C,r.updateExpiryDate=P,function(){_(),q()}()}t.controller("RequestModalDetailsToilController",n),n.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),r={date:o};return a.all(r).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={toilDurationHours:"0",toilDurationMinutes:"0",request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},transformAttributes:function(e){var t=Number(e.toil_duration);return t&&(e.toilDurationHours=Math.floor(t/60).toString(),e.toilDurationMinutes=(t%60).toString()),e},updateDuration:function(){this.toil_duration=60*Number(this.toilDurationHours)+Number(this.toilDurationMinutes)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files","toilDurationHours","toilDurationMinutes"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,r,i,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,P){function D(e){"days"===$e.selectedAbsenceType.calculation_unit_name?delete $e.request[e+"_date_amount"]:delete $e.request[e+"_date_type"]}function R(){["from","to"].forEach(D)}function A(){var e=$e.requestStatuses[y.statusNames.awaitingApproval].value;Ie.status_id===e&&e!==$e.request.status_id&&d.publish("ManagerBadge:: Update Count")}function T(){return Oe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return Oe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return!$e.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function k(){var e=T();return $e.isMode("edit")&&(e=e&&(G()||w())),$e.canManage&&$e.requestStatuses&&(e=e&&!!$e.getStatusFromValue($e.newStatusOnSave)),(e=e&&!!$e.period.id)&&!$e.isMode("view")}function L(){$e.isSelfRecord?$e.request.status_id=$e.requestStatuses[y.statusNames.awaitingApproval].value:$e.canManage&&($e.request.status_id=$e.newStatusOnSave||$e.request.status_id)}function S(){if($e.isMode("edit")&&!$e.isRole("staff")&&"toil"!==j())return $e.request.calculateBalanceChange($e.selectedAbsenceType.calculation_unit_name).then(function(e){if(+$e.balance.change.amount!=+e.amount)return P.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function M(){$e.errors=[]}function O(){return $e.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function $(){ee()&&!$e.isRole("staff")&&($e.request.change_balance=!0)}function x(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return $e.request.delete().then(function(){$e.dismissModal(),d.publish("LeaveRequest::delete",$e.request)})}})}function E(){i.dismiss({$value:"cancel"})}function B(){var e=j();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function N(){return F($e.getStatusFromValue($e.request.status_id).name)}function F(e){return n.map(Te[e],function(e){return $e.requestStatuses[e]})}function j(){return $e.request?$e.request.request_type:$e.leaveType||null}function U(){return!$e.request||e.equals({},$e.requestStatuses)?[]:$e.request.status_id?N():F("none")}function W(e){return n.find($e.requestStatuses,function(t){return t.value===e})}function H(e){$e.errors=n.isArray(e)?e:[e],$e.loading.absenceTypes=!1,$e.submitting=!1}function G(){return!e.equals(Ie,$e.request.attributes())||$e.canManage&&$e.newStatusOnSave}function Y(){return $e.postContactSelection=!0,$e.staffMemberSelectionComplete=!1,$e.request.contact_id?o.resolve().then(ie).then(ce).then(he).then(be).then(Z).then(z).then($e.isMode("edit")?ge:n.noop).then(function(){$e.postContactSelection=!1,$e.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Se)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Te.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Te.awaiting_approval=e,Te.more_information_required=e,Te.rejected=e,Te.approved=e,Te.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return $e.canManage?f.find($e.request.contact_id).then(function(e){$e.contactName=e.display_name}):o.resolve()}function X(){ke.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",$e.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){we++})),r.$on("$destroy",Pe),r.$on("LeaveRequestPopup::addTab",function(e,t){Oe.push(t)})}function Q(){var e,t;$e.request=$e.leaveRequest||null,e=j(),t=$e.initRequestAttributes(),"leave"===e?$e.request=_.init(t):"sickness"===e?$e.request=q.init(t):"toil"===e&&($e.request=C.init(t))}function J(){var e={};return $e.request?e=$e.request.attributes():$e.canManage||(e={contact_id:Le}),e}function K(){if(Me="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(Me="admin")}).then(function(){return"staff"===Me&&c(y.permissions.ssp.manage).then(function(e){e&&(Me="manager")})}).finally(function(){$e.canManage=$e.isRole("manager")||$e.isRole("admin")})}function Z(){($e.isRole("admin")||$e.isMode("create")&&$e.isRole("manager"))&&($e.newStatusOnSave=$e.requestStatuses[y.statusNames.approved].value)}function ee(){return!$e.request.status_id||!n.includes(["cancelled","rejected"],W($e.request.status_id).name)}function te(e){var t=$e.getStatusFromValue($e.request.status_id);return!!t&&t.name===e}function ne(e){return $e.request&&$e.request.request_type===e}function ae(e){return $e.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return Me===e}function re(){return h.all().then(function(e){$e.absencePeriods=e})}function ie(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Ae={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return $e.loading.entitlements=!0,b.all({contact_id:$e.request.contact_id,period_id:$e.period.id,type_id:{IN:Ae.ids}},!0).finally(function(){$e.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Le=e.contactId})}function le(){return $e.selectedContactId?f.find($e.selectedContactId).then(function(e){$e.managedContacts=[e]}):$e.isRole("admin")?f.all().then(function(e){$e.managedContacts=n.remove(e.list,function(e){return e.id!==Le})}):f.find(Le).then(function(e){return e.leaveManagees()}).then(function(e){$e.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){$e.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){A(),d.publish(e,$e.request),$e.errors=[],$e.dismissModal()}function pe(){["from","to"].forEach(function(e){$e.request[e+"_date"]=Ie[e+"_date"]})}function he(e){if($e.absenceTypes=me(Ae.types,e),!$e.absenceTypes.length)return o.reject(Se)}function ve(){$e.period=n.find($e.absencePeriods,function(e){return $e.isMode("create")?e.current:oe($e.request,e)})}function be(){$e.isMode("create")?($e.selectedAbsenceType=$e.absenceTypes[0],$e.request.type_id=$e.selectedAbsenceType.id):$e.selectedAbsenceType=n.find($e.absenceTypes,function(e){return e.id===$e.request.type_id})}function ge(){Ie=e.copy($e.request.attributes())}function _e(){var e;$e.request.id?(e=[$e.requestStatuses[y.statusNames.approved].value,$e.requestStatuses[y.statusNames.adminApproved].value,$e.requestStatuses[y.statusNames.rejected].value,$e.requestStatuses[y.statusNames.cancelled].value],$e.mode="edit",$e.isRole("staff")&&e.indexOf($e.request.status_id)>-1&&($e.mode="view")):$e.mode="create"}function ye(){var e=$e.request.status_id;if(!$e.isMode("view")&&!$e.submitting)return $e.submitting=!0,L(),R(),$e.request.isValid().then(ee()&&S).then($).then(!$e.request.change_balance&&pe).then(qe).then(function(){return $e.isMode("edit")?Re():O()}).catch(function(t){$e.request.status_id=e,t&&H(t)}).finally(function(){$e.submitting=!1})}function qe(){return o.all(Oe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===we&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return we>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Pe(){ke.forEach(function(e){e()})}function De(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Re(){return $e.request.update().then(Ce).then(function(){$e.isRole("manager")?fe("LeaveRequest::updatedByManager"):($e.isRole("staff")||$e.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Ae,Te={},we=0,Ie={},ke=[],Le="",Se="No entitlement",Me="",Oe=[],$e=n.assign(this,m);$e.absencePeriods=[],$e.absenceTypes=[],$e.canManage=!1,$e.contactName=null,$e.errors=[],$e.loading={absenceTypes:!0,entitlements:!0},$e.managedContacts=[],$e.mode="",$e.newStatusOnSave=null,$e.period={},$e.postContactSelection=!1,$e.requestStatuses={},$e.selectedAbsenceType={},$e.staffMemberSelectionComplete=!1,$e.submitting=!1,$e.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},$e.canChangeAbsenceType=I,$e.canSubmit=k,$e.closeAlert=M,$e.deleteLeaveRequest=x,$e.dismissModal=E,$e.getStatuses=U,$e.getStatusFromValue=W,$e.initAfterContactSelection=Y,$e.initRequestAttributes=J,$e.isLeaveStatus=te,$e.isLeaveType=ne,$e.isMode=ae,$e.isRole=se,$e.submit=ye,$e.updateAbsenceType=De,function(){$e.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),re(),de()]).then(Q).then(_e).then(ve).then(function(){return $e.canManage&&!$e.isMode("edit")&&le()}).then(function(){if($e.selectedContactId&&($e.request.contact_id=$e.selectedContactId),$e.request.contact_id)return $e.initAfterContactSelection()}).catch(H).finally(function(){$e.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,r,i,c){function u(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,r,i){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:r,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,r){function i(e){l.errorMessage=e}function c(){return r.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrleaveandabsences_work_pattern_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,r.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(i).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrjc_revision_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(),g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){i.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){r.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,r){function i(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,r){n=o.entitlements.slice(0,r),a=e.entitlements.slice(r+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,r;return s=e.indexBy(n,"entitlement_id.type_id"),r=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:r}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){ var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t];e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,r){o.comment&&(t=s.concat(o).concat(r),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(i).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,r,i,c,u,l,d){function m(){P.absencePeriods=t.chain(P.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){P.absenceTypes=t.filter(P.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:P.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:P.contactId,returnUrl:n})}function h(){return c.all().then(function(e){P.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:P.contactId}).then(function(e){q=e})}function g(e){r.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=P.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){P.absencePeriods=t.map(P.absencePeriods,function(e){var n=t.map(P.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

Last updated:
By: "+e.author_name+"
Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],P=this;P.absencePeriods=[],P.loading={absencePeriods:!0},P.getEditEntitlementsPageURL=p,P.openAnnualEntitlementChangeLog=g,P.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){P.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,r,i){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return r.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){i.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component.js index 4a4bde2c0c7..a3ca4a9bf35 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component.js @@ -107,9 +107,9 @@ define([ } /** - * Loads the Leave and Absences Work Pattern Change Reason and indexes by `value` + * Loads the Leave and Absences Work Pattern Change Reasons and indexes by `value` * - * @return {Promise} + * @return {Promise} resolves with {Array} */ function loadJobContractRevisionChangeReasons () { return OptionGroup.valuesOf('hrleaveandabsences_work_pattern_change_reason') diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/absence-tab/components/absence-tab-custom-work-pattern-modal.component.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/absence-tab/components/absence-tab-custom-work-pattern-modal.component.spec.js index 4a2bad6c9ee..ab1035522cb 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/absence-tab/components/absence-tab-custom-work-pattern-modal.component.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/absence-tab/components/absence-tab-custom-work-pattern-modal.component.spec.js @@ -49,7 +49,7 @@ }); describe('init()', function () { - it('calls the valueOf with hrleaveandabsences_work_pattern_change_reason', function () { + it('fetches values of the Work Pattern Change Reason option group', function () { expect(OptionGroup.valuesOf).toHaveBeenCalledWith('hrleaveandabsences_work_pattern_change_reason'); }); From 8ff23948eb7ecec56fcd06d8e1bf22db98526623 Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Tue, 20 Mar 2018 16:39:54 +0100 Subject: [PATCH 052/203] PCHR-3451: PR Feedback --- .../js/angular/dist/absence-tab.min.js | 4 +- ...tab-custom-work-pattern-modal.component.js | 2 +- .../absence-tab-work-patterns.component.js | 6 +-- ...bsence-tab-work-patterns.component.spec.js | 8 +++- .../test/mocks/data/option-group.data.js | 37 ------------------- 5 files changed, 12 insertions(+), 45 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js index e7dcdbb2cad..cbdfd8d1e16 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js @@ -1,5 +1,5 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,o){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,r){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),r=e.assign({},r,{absence_type_id:a,date:t(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",r).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,o,s,r){return t.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return s.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,o,s,r){return this.sendPOST("ContactWorkPattern","create",e.assign({},r,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,o,s){return t.debug("WorkPatternAPI.getCalendar",n,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,o){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,o,s,r){function i(t,n){return u().then(function(a){var o=this.days[c(t).valueOf()];return!!o&&e.find(a,function(e){return e.name===n}).value===o.type}.bind(this))}function c(e){return t(e,s.serverDateFormat).clone()}function u(){return l=l||r.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[c(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,o){return t.debug("Calendar"),n.extend({get:function(n,s,r,i){return t.debug("Calendar.get"),a.getCalendar(n,s,r,i).then(function(t){var a=t.values.map(function(e){return o.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function o(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,o,s){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return o.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,o,s,r){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,o,s,"getFull",r)),i.promise},balanceChangeByAbsenceType:function(t,n,o,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var r=a.defer();t&&n||r.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:o?{IN:o}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){r.resolve(e.values)}),r.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?o.reject(t(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,o,s,r,i,c){function u(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),r=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(r.date)]).then(function(t){return s.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,o&&(r.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return r.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(s.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,o,s,r){return n.all(this.processFilters(e),t,o,s,r).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,o){return n.balanceChangeByAbsenceType(e,t,a,o)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/instances/work-pattern.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("WorkPatternInstance",["$log","ModelInstance",function(e,t){return e.debug("WorkPatternInstance"),t.extend({})}])}),define("leave-absences/shared/models/work-pattern.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/work-pattern.instance"],function(e,t){"use strict";t.factory("WorkPattern",["$log","Model","WorkPatternAPI","WorkPatternInstance",function(t,n,a,o){return t.debug("WorkPattern"),n.extend({assignWorkPattern:function(e,t,n,o,s,r){return a.assignWorkPattern(e,t,n,o,s,r)},default:function(){return a.get({is_default:!0}).then(function(t){return o.init(e.first(t),!0)})},unassignWorkPattern:function(e){return a.unassignWorkPattern(e)},workPatternsOf:function(e,t,n){return a.workPatternsOf(e,t,n).then(function(e){return e.map(function(e){return o.init(e,!0)})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,o,s,r,i){function c(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function u(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?c():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return o.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):r.all()}function m(e){return"me"===e?o.leaveManagees(v.contactId):"unassigned"===e?o.leaveManagees(void 0,{unassigned:!0}):o.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

","

People I approve filter displays only staff members who you approve leave for.

","

People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

"].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,u()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:r.contactId}).leaveManagees().then(function(e){r.lookupContacts=e}).then(o)}}}function o(){return t.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:r.filters.userSettings.department?r.filters.userSettings.department.value:null,level_type:r.filters.userSettings.level_type?r.filters.userSettings.level_type.value:null,location:r.filters.userSettings.location?r.filters.userSettings.location.value:null,region:r.filters.userSettings.region?r.filters.userSettings.region.value:null,id:{IN:r.filters.userSettings.contact?[r.filters.userSettings.contact.id]:r.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var r;return{init:function(e){return r=e,r.showContactName=!0,r.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function o(a,o,s,r,i,c,u,l,d,m){function f(){for(var e=[],t=n(O.selectedPeriod.start_date).clone().startOf("month"),a=n(O.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(A(t)),t.add(1,"month");O.months=e}function p(){r.$new().$watch(function(){return O.selectedMonths},function(t,n){null===n||e.equals(t,n)||w()})}function h(e){O.injectMonths=!0,L("injected").then(function(){w(e)}).then(function(){O.loading.calendar=!1})}function v(){S=a("LeaveCalendar"+t.capitalize(M)+"Controller").init(O)}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function g(){return c.all().then(function(e){O.absencePeriods=t.sortBy(e,"start_date"),O.selectedPeriod=t.find(O.absencePeriods,function(e){return!!e.current})}).then(f).then(I)}function _(){return u.all().then(u.loadCalculationUnits)}function y(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return S.loadContacts().then(function(e){O.contacts=e})}function C(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){O.filters.optionValues.regions=e.hrjc_region,O.filters.optionValues.locations=e.hrjc_location,O.filters.optionValues.levelTypes=e.hrjc_level_type,O.filters.optionValues.departments=e.hrjc_department})}function P(){return l.all()}function D(){return o.all([_(),P(),y()]).then(function(e){O.supportData.absenceTypes=e[0],O.supportData.publicHolidays=e[1],O.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,O.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,O.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,O.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function R(){var e=o.resolve();return O.injectMonths&&(e=L("destroyed"),O.injectMonths=!1),e}function A(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function T(e){e=t.includes(["contacts","period"],e)?e:"period",o.resolve().then(function(){O.loading.calendar=!0}).then(R).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function w(e){var n=O.selectedMonths.length?O.months.filter(function(e){return t.includes(O.selectedMonths,e.index)}):O.months;r.$emit("LeaveCalendar::showMonths",n,!!e)}function I(){O.selectedMonths=[n().month()]}function k(){return O.roleOverride?o.resolve().then(function(){M=O.roleOverride}):o.all([m(i.permissions.admin.administer),m(i.permissions.ssp.manage)]).then(function(e){M=e[0]?"admin":e[1]?"manager":"staff"})}function L(e){return o(function(n){var a=0,o=r.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===O.months.length&&(o(),n())})})}s.debug("Component: leave-calendar");var S,M,O=this;O.absencePeriods=[],O.contacts=[],O.contactIdsToReduceTo=null,O.injectMonths=!1,O.months=[],O.selectedMonths=null,O.selectedPeriod=null,O.showContactName=!1,O.showFilters=!1,O.supportData={},O.loading={calendar:!0,page:!0},O.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},O.labelPeriod=b,O.refresh=T,function(){k().then(p).then(v).then(R).then(g).then(function(){return o.all([q(),D()])}).then(function(){return O.showFilters?C():t.noop}).then(function(){h()}).then(function(){O.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",o]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,o){"use strict";function s(){y.calculationUnit=r(y.supportData.calculationUnits,"value",b.calculation_unit)}function r(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(y.contactData.leaveRequest.from_date).isSame(y.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+y.calculationUnit.name+"-on-"+e+"-tooltip"}function c(){b=r(y.supportData.absenceTypes,"id",y.contactData.leaveRequest.type_id),y.contactData.leaveRequest["type_id.title"]=b.title}function u(){"days"===y.calculationUnit.name&&(g=r(y.supportData.dayTypes,"value",y.contactData.leaveRequest.from_date_type),_=r(y.supportData.dayTypes,"value",y.contactData.leaveRequest.to_date_type),y.contactData.leaveRequest["from_date_type.label"]=g.label,y.contactData.leaveRequest["to_date_type.label"]=_.label)}function l(e,t,n,a,s){e.stopPropagation(),o.openModal(t,n,a,s)}function d(){y.dates.from=new Date(y.contactData.leaveRequest.from_date),y.dates.to=new Date(y.contactData.leaveRequest.to_date)}function m(){y.contactData.isAccruedTOIL?y.label="AT":"days"===y.calculationUnit.name?f():p()}function f(){y.label=y.contactData.isAM?"AM":y.contactData.isPM?"PM":""}function p(){var e=t(y.contactData.leaveRequest.from_date).isSame(y.date,"day"),n=t(y.contactData.leaveRequest.to_date).isSame(y.date,"day");y.label=e?t(y.contactData.leaveRequest.from_date).format("HH:mm"):n?t(y.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){y.tooltipTemplate=y.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){y.contactData&&y.contactData.leaveRequest&&(c(),s(),u(),m(),d(),h()) })}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,r,i,c){function u(e){_([e]),N(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return U[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){S(e),N(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=R(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){j.push(o.$on("LeaveCalendar::showMonths",x)),j.push(i.subscribe("LeaveRequest::new",u)),j.push(i.subscribe("LeaveRequest::edit",B)),j.push(i.subscribe("LeaveRequest::updatedByManager",B)),j.push(i.subscribe("LeaveRequest::delete",h)),j.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function P(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function D(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function R(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function A(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function T(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function w(){return[T(c.statusNames.approved),T(c.statusNames.adminApproved),T(c.statusNames.awaitingApproval),T(c.statusNames.moreInformationRequired)]}function I(){return H.month.loading=!0,a.all([L(),k()]).then(b).then($).then(function(){F=!0}).then(function(){H.month.loading=!1})}function k(){return r.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:w()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function L(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function S(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function M(){o.$emit("LeaveCalendar::monthDestroyed"),j.map(function(e){e.remove?e.remove():e()})}function O(t,n,o){var s,r;return t.contactsData[n]=t.contactsData[n]||{},r=m(n),s=!0===o?a.resolve():a.all([r.isWeekend(p(t.date)),r.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:P(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?D(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function $(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return O(e,t.id)}))}))}function x(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!F)&&I())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=A(e);t&&(h(t),-1!==w().indexOf(e.status_id)&&u(e))}function N(e){return a.all(R(e).map(function(t){return O(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var F=!1,j=[],U={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=M,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,r,i,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(r.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=P[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(P,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:P[e].label,isDirectAction:P[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,P={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,r,i,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,r.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l,d,m,f){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function h(e){return t(e,c.serverDateFormat).toDate()}function v(e){return t(e).format(c.serverDateFormat)}function b(e){var t;return r.resolve().then(function(){J(e),"from"===e&&Q(),N("hours")&&(y(e),"from"!==e||pe.uiOptions.multipleDays||y("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return P(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return r.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return G()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(N("hours"))return H(e).then(function(){ne(e,!0)})}).then(function(){if(se(),!t)return V();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(I)}function g(){return se(),V()}function _(){return pe.uiOptions.toDate=null,J("to"),r.resolve().then(function(){if(N("hours")&&pe.uiOptions.fromDate)return y("from"),!pe.uiOptions.multipleDays&&y("to"),H("from").then(function(){ne("from",!0)}).then(se)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&V)}function y(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&s&&o&&(s=A(s).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=A(o).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function C(t,n){return t?(t=v(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):D(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):r.reject([])}function P(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function D(e,n){return e=t(e),r.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function R(){return pe.request?pe.request.request_type:pe.leaveType||null}function A(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(K).catch(I)}function w(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function I(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function k(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?V():T()}function L(){var e=pe.request.attributes();return pe.uiOptions.fromDate=h(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=h(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function S(e){s.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){N("days")||+e==+t||(re(),pe.performBalanceChangeCalculation())})}function M(){fe.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){ue()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",V))}function O(){pe.isMode("edit")&&(pe.isLeaveStatus(c.statusNames.approved)||pe.isLeaveStatus(c.statusNames.adminApproved))&&(me={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function $(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(w(a.min,n)<=0||w(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function x(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return r.all(e.map(H)).then(function(){["from","to"].forEach(function(e){$(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(re)}function E(){["from","to"].forEach(function(e){S(e),B(e)})}function B(e){s.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){N("days")||t===n||(se(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function N(e){return pe.selectedAbsenceType.calculation_unit_name===e}function F(e){return pe.request.request_type===e}function j(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return C(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function W(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function H(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(v(t)).then(function(t){he[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return he[e]={},I(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):r.resolve()}function G(){return u.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function Y(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function V(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(K).catch(I).finally(function(){pe.loading.balanceChange=!1})):r.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function X(){return v(pe.request.from_date)===v(pe.request.to_date)}function Q(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,J("to"))}function J(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,se(),re(),ie()}function K(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=h(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=h(pe.period.end_date)}function ee(){return!pe.isMode("create")&&X()||pe.isMode("create")&&(F("sickness")||N("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,r.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,i=he[a].number_of_hours?w(s,r).toString():"0";o.maxAmount=i,t&&(o.amount=o.maxAmount)}function ae(){me&&me.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=me.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function oe(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function se(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?v(e.fromDate):null,pe.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),N("hours")&&!F("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function re(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ce(){e.forEach(fe,function(e){e()})}function ue(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return oe(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),r.resolve().then(e&&ee).then(function(){if(e&&N("hours"))return H("from").then(function(){ne("from",!0)})}).then(e&&se).then(V)}function le(e){return pe.absenceTypes=e,oe(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,J("to")),ae(),V()}function de(e){var t=A(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(A(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(A(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var me=null,fe=[],pe=this,he={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=c.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:Y},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=h,pe.convertDateToServerFormat=v,pe.dateChangeHandler=b,pe.dateTypeChangeHandler=g,pe.daysSelectionModeChangeHandler=_,pe.isLeaveType=F,pe.isNotWorkingDay=j,pe.performBalanceChangeCalculation=V,pe.$onDestroy=ce,function(){n("RequestModalDetails"+e.capitalize(R(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",pe),M(),pe.initChildController().then(function(){return r.all([G(),W()])}).then(!pe.isMode("create")&&L).then(ee).then(function(){if(!pe.isMode("create")&&N("hours"))return x().then(se)}).then(!pe.isMode("create")&&Z).then(O).then(ae).then(k).then(function(){pe.isMode("view")||F("toil")||E()}).catch(I).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l){function d(){return k.fileUploader&&k.fileUploader.queue.length>0}function m(){return k.getFilesAmount()0?T.map(function(e){return e.label}).join(", "):""}function q(){return k.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(T.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){I[e.label]=t})})).catch(function(){I=null})}function P(){return c.valuesOf("safe_file_extension").then(function(e){T=e})}function D(e){return!e.attachment_id||k.canManage}function R(){e.forEach(w,function(e){e()})}function A(e,t){k.fileUploader.queue&&k.fileUploader.queue.length>0?k.fileUploader.uploadAll({entityID:k.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var T=[],w=[],I={},k=Object.create(this);return k.filesLoaded=!1,k.fileUploader=null,k.today=Date.now(),k.userDateFormatWithTime=r.DATE_FORMAT+" HH:mm",k.userDateFormat=r.DATE_FORMAT,k.$onDestroy=R,k.canRemoveAttachment=D,k.canSubmit=d,k.canUploadMore=m,k.formatDateTime=f,k.getAuthorName=p,k.getFilesAmount=h,k.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",k),g(),a.all([P(),q()]).then(_).finally(function(){k.filesLoaded=!0})}(),k}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,o){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"},{type:"toil",icon:"calendar-plus-o",label:"Overtime"}],s.openLeavePopup=a,function(){o=n.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{btnClass:"@",contactId:"<",selectedContactId:"<",isSelfRecord:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,o,s,r,i,c,u,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):W.refresh()}function b(t){t.dataIndex=e.indexBy(t.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return r.all().then(r.loadCalculationUnits).then(function(t){W.absenceTypes=t,W.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return T("approved",{status_id:j(m.statusNames.approved)})}function C(){return n.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[j(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[j(m.statusNames.awaitingApproval),j(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function P(){return i.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(t){var n=e.find(W.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function D(){return i.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return O(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function R(){return n.all([i.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),A({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:O(e[0]),expiredTOILS:$(e[1].list)})}).then(function(t){W.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function A(t){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function T(e,t){return A(t).then(function(t){W.sections[e].data=t.list})}function w(){return n.all(Object.values(W.sections).filter(function(e){return e.open}).map(S))}function I(){return T("other",{status_id:{in:[j(m.statusNames.rejected),j(m.statusNames.cancelled)]}})}function k(){return T("pending",{status_id:{ -in:[j(m.statusNames.awaitingApproval),j(m.statusNames.moreInformationRequired)]}})}function L(){return T("holidays",{public_holiday:!0})}function S(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function M(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){W.leaveRequestStatuses=e.indexBy(t,"value")})}function O(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(W.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function $(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function x(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(W.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],B(t,a))})}function B(e,t){var n=W.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function N(){W.loading.content=!0,n.all([P(),C()]).then(function(){W.loading.content=!1}).then(function(){return n.all([w(),h()])})}function F(e){var t=W.sections[e];t.open=!t.open,t.open&&!t.data.length&&S(t)}function j(t){return e.find(W.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:D},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:L},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:k},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:I}},W.labelPeriod=g,W.refresh=N,W.toggleSection=F,function(){n.all([M(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return n.all([P(),C()])}).then(function(){W.loading.content=!1}),x()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["leave-absences/shared/modules/controllers"],function(e){function t(e,t,n,a){function o(){return a.request.calculateBalanceChange(a.selectedAbsenceType.calculation_unit_name)}function s(){var e=a.request,t=!!e.from_date&&!!e.to_date,n=a.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function r(){return a.canCalculateChange()}function i(){return n.resolve()}t.debug("RequestModalDetailsLeaveController"),a.calculateBalanceChange=o,a.canCalculateChange=s,a.canSubmit=r,a.initChildController=i}e.controller("RequestModalDetailsLeaveController",t),t.$inject=["$controller","$log","$q","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function r(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function i(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=r,s.initChildController=i,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s,r){function i(){return r.balance.change.amount=+r.request.toil_to_accrue,n.resolve(r.balance.change)}function c(){return f().catch(function(e){return e.length&&(r.errors=e),n.reject(e)}).then(function(e){return s.calculateToilExpiryDate(r.request.type_id,e)}).then(function(e){return r.request.toil_expiry_date=e,r.uiOptions.expiryDate=new Date(e),e})}function u(){return!!r.request.toil_to_accrue}function l(){var e=r.uiOptions.multipleDays&&!!r.request.to_date,t=!r.uiOptions.multipleDays&&!!r.request.from_date,n=t||e,a=D.from_date!==r.request.from_date||D.to_date!==r.request.to_date;return r.canDisplayToilExpirationField&&n&&R.hasExpirationFromAdminSettings&&a}function d(){return!!(r.request.from_date&&r.request.to_date&&r.request.toil_duration&&r.request.toil_to_accrue)}function m(){r.request.toil_expiry_date=!1,r.uiOptions.expiryDate=null}function f(){var e=r.uiOptions.multipleDays,t=r.request;return p({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function p(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return n.reject([t])}return e.value?n.resolve(e.value):n.reject([])}function h(){var e=r.isMode("create")&&R.hasExpirationFromAdminSettings,t=R.hasPreviousExpirationDate,n=r.isLeaveType("toil"),a=r.canManage;r.canDisplayToilExpirationField=n&&(a||e||t)}function v(){return R.hasPreviousExpirationDate=r.isMode("edit")&&!!r.request.toil_expiry_date,s.canExpire(r.request.type_id).then(function(e){R.hasExpirationFromAdminSettings=e})}function b(){return r.request.to_date_type=r.request.from_date_type="1",v().then(h).then(g).then(y)}function g(){r.canManage&&(r.uiOptions.expiryDate=r.convertDateFormatFromServer(r.request.toil_expiry_date))}function _(){r.isMode("view")||a.$watch(function(){return r.request.toil_to_accrue},function(e,t){+e!=+t&&r.performBalanceChangeCalculation()})}function y(){return o.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){r.toilAmounts=e.indexBy(t,"value")})}function q(){D=angular.copy(r.request.attributes())}function C(){return l()?c().catch(n.resolve):n.resolve()}function P(){r.uiOptions.expiryDate&&(r.request.toil_expiry_date=r.convertDateToServerFormat(r.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var D,R={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};r.canDisplayToilExpirationField=!1,r.calculateBalanceChange=i,r.canCalculateChange=u,r.canSubmit=d,r.clearExpiryDate=m,r.initChildController=b,r.onDateChangeExtended=C,r.setDaysSelectionModeExtended=C,r.updateExpiryDate=P,function(){_(),q()}()}t.controller("RequestModalDetailsToilController",n),n.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),r={date:o};return a.all(r).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={toilDurationHours:"0",toilDurationMinutes:"0",request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},transformAttributes:function(e){var t=Number(e.toil_duration);return t&&(e.toilDurationHours=Math.floor(t/60).toString(),e.toilDurationMinutes=(t%60).toString()),e},updateDuration:function(){this.toil_duration=60*Number(this.toilDurationHours)+Number(this.toilDurationMinutes)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files","toilDurationHours","toilDurationMinutes"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,r,i,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,P){function D(e){"days"===$e.selectedAbsenceType.calculation_unit_name?delete $e.request[e+"_date_amount"]:delete $e.request[e+"_date_type"]}function R(){["from","to"].forEach(D)}function A(){var e=$e.requestStatuses[y.statusNames.awaitingApproval].value;Ie.status_id===e&&e!==$e.request.status_id&&d.publish("ManagerBadge:: Update Count")}function T(){return Oe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return Oe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return!$e.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function k(){var e=T();return $e.isMode("edit")&&(e=e&&(G()||w())),$e.canManage&&$e.requestStatuses&&(e=e&&!!$e.getStatusFromValue($e.newStatusOnSave)),(e=e&&!!$e.period.id)&&!$e.isMode("view")}function L(){$e.isSelfRecord?$e.request.status_id=$e.requestStatuses[y.statusNames.awaitingApproval].value:$e.canManage&&($e.request.status_id=$e.newStatusOnSave||$e.request.status_id)}function S(){if($e.isMode("edit")&&!$e.isRole("staff")&&"toil"!==j())return $e.request.calculateBalanceChange($e.selectedAbsenceType.calculation_unit_name).then(function(e){if(+$e.balance.change.amount!=+e.amount)return P.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function M(){$e.errors=[]}function O(){return $e.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function $(){ee()&&!$e.isRole("staff")&&($e.request.change_balance=!0)}function x(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return $e.request.delete().then(function(){$e.dismissModal(),d.publish("LeaveRequest::delete",$e.request)})}})}function E(){i.dismiss({$value:"cancel"})}function B(){var e=j();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function N(){return F($e.getStatusFromValue($e.request.status_id).name)}function F(e){return n.map(Te[e],function(e){return $e.requestStatuses[e]})}function j(){return $e.request?$e.request.request_type:$e.leaveType||null}function U(){return!$e.request||e.equals({},$e.requestStatuses)?[]:$e.request.status_id?N():F("none")}function W(e){return n.find($e.requestStatuses,function(t){return t.value===e})}function H(e){$e.errors=n.isArray(e)?e:[e],$e.loading.absenceTypes=!1,$e.submitting=!1}function G(){return!e.equals(Ie,$e.request.attributes())||$e.canManage&&$e.newStatusOnSave}function Y(){return $e.postContactSelection=!0,$e.staffMemberSelectionComplete=!1,$e.request.contact_id?o.resolve().then(ie).then(ce).then(he).then(be).then(Z).then(z).then($e.isMode("edit")?ge:n.noop).then(function(){$e.postContactSelection=!1,$e.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Se)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Te.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Te.awaiting_approval=e,Te.more_information_required=e,Te.rejected=e,Te.approved=e,Te.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return $e.canManage?f.find($e.request.contact_id).then(function(e){$e.contactName=e.display_name}):o.resolve()}function X(){ke.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",$e.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){we++})),r.$on("$destroy",Pe),r.$on("LeaveRequestPopup::addTab",function(e,t){Oe.push(t)})}function Q(){var e,t;$e.request=$e.leaveRequest||null,e=j(),t=$e.initRequestAttributes(),"leave"===e?$e.request=_.init(t):"sickness"===e?$e.request=q.init(t):"toil"===e&&($e.request=C.init(t))}function J(){var e={};return $e.request?e=$e.request.attributes():$e.canManage||(e={contact_id:Le}),e}function K(){if(Me="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(Me="admin")}).then(function(){return"staff"===Me&&c(y.permissions.ssp.manage).then(function(e){e&&(Me="manager")})}).finally(function(){$e.canManage=$e.isRole("manager")||$e.isRole("admin")})}function Z(){($e.isRole("admin")||$e.isMode("create")&&$e.isRole("manager"))&&($e.newStatusOnSave=$e.requestStatuses[y.statusNames.approved].value)}function ee(){return!$e.request.status_id||!n.includes(["cancelled","rejected"],W($e.request.status_id).name)}function te(e){var t=$e.getStatusFromValue($e.request.status_id);return!!t&&t.name===e}function ne(e){return $e.request&&$e.request.request_type===e}function ae(e){return $e.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return Me===e}function re(){return h.all().then(function(e){$e.absencePeriods=e})}function ie(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Ae={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return $e.loading.entitlements=!0,b.all({contact_id:$e.request.contact_id,period_id:$e.period.id,type_id:{IN:Ae.ids}},!0).finally(function(){$e.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Le=e.contactId})}function le(){return $e.selectedContactId?f.find($e.selectedContactId).then(function(e){$e.managedContacts=[e]}):$e.isRole("admin")?f.all().then(function(e){$e.managedContacts=n.remove(e.list,function(e){return e.id!==Le})}):f.find(Le).then(function(e){return e.leaveManagees()}).then(function(e){$e.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){$e.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){A(),d.publish(e,$e.request),$e.errors=[],$e.dismissModal()}function pe(){["from","to"].forEach(function(e){$e.request[e+"_date"]=Ie[e+"_date"]})}function he(e){if($e.absenceTypes=me(Ae.types,e),!$e.absenceTypes.length)return o.reject(Se)}function ve(){$e.period=n.find($e.absencePeriods,function(e){return $e.isMode("create")?e.current:oe($e.request,e)})}function be(){$e.isMode("create")?($e.selectedAbsenceType=$e.absenceTypes[0],$e.request.type_id=$e.selectedAbsenceType.id):$e.selectedAbsenceType=n.find($e.absenceTypes,function(e){return e.id===$e.request.type_id})}function ge(){Ie=e.copy($e.request.attributes())}function _e(){var e;$e.request.id?(e=[$e.requestStatuses[y.statusNames.approved].value,$e.requestStatuses[y.statusNames.adminApproved].value,$e.requestStatuses[y.statusNames.rejected].value,$e.requestStatuses[y.statusNames.cancelled].value],$e.mode="edit",$e.isRole("staff")&&e.indexOf($e.request.status_id)>-1&&($e.mode="view")):$e.mode="create"}function ye(){var e=$e.request.status_id;if(!$e.isMode("view")&&!$e.submitting)return $e.submitting=!0,L(),R(),$e.request.isValid().then(ee()&&S).then($).then(!$e.request.change_balance&&pe).then(qe).then(function(){return $e.isMode("edit")?Re():O()}).catch(function(t){$e.request.status_id=e,t&&H(t)}).finally(function(){$e.submitting=!1})}function qe(){return o.all(Oe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===we&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return we>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Pe(){ke.forEach(function(e){e()})}function De(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Re(){return $e.request.update().then(Ce).then(function(){$e.isRole("manager")?fe("LeaveRequest::updatedByManager"):($e.isRole("staff")||$e.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Ae,Te={},we=0,Ie={},ke=[],Le="",Se="No entitlement",Me="",Oe=[],$e=n.assign(this,m);$e.absencePeriods=[],$e.absenceTypes=[],$e.canManage=!1,$e.contactName=null,$e.errors=[],$e.loading={absenceTypes:!0,entitlements:!0},$e.managedContacts=[],$e.mode="",$e.newStatusOnSave=null,$e.period={},$e.postContactSelection=!1,$e.requestStatuses={},$e.selectedAbsenceType={},$e.staffMemberSelectionComplete=!1,$e.submitting=!1,$e.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},$e.canChangeAbsenceType=I,$e.canSubmit=k,$e.closeAlert=M,$e.deleteLeaveRequest=x,$e.dismissModal=E,$e.getStatuses=U,$e.getStatusFromValue=W,$e.initAfterContactSelection=Y,$e.initRequestAttributes=J,$e.isLeaveStatus=te,$e.isLeaveType=ne,$e.isMode=ae,$e.isRole=se,$e.submit=ye,$e.updateAbsenceType=De,function(){$e.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),re(),de()]).then(Q).then(_e).then(ve).then(function(){return $e.canManage&&!$e.isMode("edit")&&le()}).then(function(){if($e.selectedContactId&&($e.request.contact_id=$e.selectedContactId),$e.request.contact_id)return $e.initAfterContactSelection()}).catch(H).finally(function(){$e.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,r,i,c){function u(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,r,i){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:r,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,r){function i(e){l.errorMessage=e}function c(){return r.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrleaveandabsences_work_pattern_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,r.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(i).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrjc_revision_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(),g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){i.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){r.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,r){function i(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,r){n=o.entitlements.slice(0,r),a=e.entitlements.slice(r+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,r;return s=e.indexBy(n,"entitlement_id.type_id"),r=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:r}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){ -var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t];e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,r){o.comment&&(t=s.concat(o).concat(r),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(i).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,r,i,c,u,l,d){function m(){P.absencePeriods=t.chain(P.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){P.absenceTypes=t.filter(P.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:P.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:P.contactId,returnUrl:n})}function h(){return c.all().then(function(e){P.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:P.contactId}).then(function(e){q=e})}function g(e){r.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=P.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){P.absencePeriods=t.map(P.absencePeriods,function(e){var n=t.map(P.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

Last updated:
By: "+e.author_name+"
Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],P=this;P.absencePeriods=[],P.loading={absencePeriods:!0},P.getEditEntitlementsPageURL=p,P.openAnnualEntitlementChangeLog=g,P.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){P.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,r,i){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return r.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){i.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); +in:[j(m.statusNames.awaitingApproval),j(m.statusNames.moreInformationRequired)]}})}function L(){return T("holidays",{public_holiday:!0})}function S(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function M(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){W.leaveRequestStatuses=e.indexBy(t,"value")})}function O(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(W.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function $(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function x(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(W.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],B(t,a))})}function B(e,t){var n=W.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function N(){W.loading.content=!0,n.all([P(),C()]).then(function(){W.loading.content=!1}).then(function(){return n.all([w(),h()])})}function F(e){var t=W.sections[e];t.open=!t.open,t.open&&!t.data.length&&S(t)}function j(t){return e.find(W.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:D},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:L},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:k},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:I}},W.labelPeriod=g,W.refresh=N,W.toggleSection=F,function(){n.all([M(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return n.all([P(),C()])}).then(function(){W.loading.content=!1}),x()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["leave-absences/shared/modules/controllers"],function(e){function t(e,t,n,a){function o(){return a.request.calculateBalanceChange(a.selectedAbsenceType.calculation_unit_name)}function s(){var e=a.request,t=!!e.from_date&&!!e.to_date,n=a.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function r(){return a.canCalculateChange()}function i(){return n.resolve()}t.debug("RequestModalDetailsLeaveController"),a.calculateBalanceChange=o,a.canCalculateChange=s,a.canSubmit=r,a.initChildController=i}e.controller("RequestModalDetailsLeaveController",t),t.$inject=["$controller","$log","$q","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function r(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function i(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=r,s.initChildController=i,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s,r){function i(){return r.balance.change.amount=+r.request.toil_to_accrue,n.resolve(r.balance.change)}function c(){return f().catch(function(e){return e.length&&(r.errors=e),n.reject(e)}).then(function(e){return s.calculateToilExpiryDate(r.request.type_id,e)}).then(function(e){return r.request.toil_expiry_date=e,r.uiOptions.expiryDate=new Date(e),e})}function u(){return!!r.request.toil_to_accrue}function l(){var e=r.uiOptions.multipleDays&&!!r.request.to_date,t=!r.uiOptions.multipleDays&&!!r.request.from_date,n=t||e,a=D.from_date!==r.request.from_date||D.to_date!==r.request.to_date;return r.canDisplayToilExpirationField&&n&&R.hasExpirationFromAdminSettings&&a}function d(){return!!(r.request.from_date&&r.request.to_date&&r.request.toil_duration&&r.request.toil_to_accrue)}function m(){r.request.toil_expiry_date=!1,r.uiOptions.expiryDate=null}function f(){var e=r.uiOptions.multipleDays,t=r.request;return p({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function p(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return n.reject([t])}return e.value?n.resolve(e.value):n.reject([])}function h(){var e=r.isMode("create")&&R.hasExpirationFromAdminSettings,t=R.hasPreviousExpirationDate,n=r.isLeaveType("toil"),a=r.canManage;r.canDisplayToilExpirationField=n&&(a||e||t)}function v(){return R.hasPreviousExpirationDate=r.isMode("edit")&&!!r.request.toil_expiry_date,s.canExpire(r.request.type_id).then(function(e){R.hasExpirationFromAdminSettings=e})}function b(){return r.request.to_date_type=r.request.from_date_type="1",v().then(h).then(g).then(y)}function g(){r.canManage&&(r.uiOptions.expiryDate=r.convertDateFormatFromServer(r.request.toil_expiry_date))}function _(){r.isMode("view")||a.$watch(function(){return r.request.toil_to_accrue},function(e,t){+e!=+t&&r.performBalanceChangeCalculation()})}function y(){return o.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){r.toilAmounts=e.indexBy(t,"value")})}function q(){D=angular.copy(r.request.attributes())}function C(){return l()?c().catch(n.resolve):n.resolve()}function P(){r.uiOptions.expiryDate&&(r.request.toil_expiry_date=r.convertDateToServerFormat(r.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var D,R={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};r.canDisplayToilExpirationField=!1,r.calculateBalanceChange=i,r.canCalculateChange=u,r.canSubmit=d,r.clearExpiryDate=m,r.initChildController=b,r.onDateChangeExtended=C,r.setDaysSelectionModeExtended=C,r.updateExpiryDate=P,function(){_(),q()}()}t.controller("RequestModalDetailsToilController",n),n.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),r={date:o};return a.all(r).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={toilDurationHours:"0",toilDurationMinutes:"0",request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},transformAttributes:function(e){var t=Number(e.toil_duration);return t&&(e.toilDurationHours=Math.floor(t/60).toString(),e.toilDurationMinutes=(t%60).toString()),e},updateDuration:function(){this.toil_duration=60*Number(this.toilDurationHours)+Number(this.toilDurationMinutes)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files","toilDurationHours","toilDurationMinutes"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,r,i,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,P){function D(e){"days"===$e.selectedAbsenceType.calculation_unit_name?delete $e.request[e+"_date_amount"]:delete $e.request[e+"_date_type"]}function R(){["from","to"].forEach(D)}function A(){var e=$e.requestStatuses[y.statusNames.awaitingApproval].value;Ie.status_id===e&&e!==$e.request.status_id&&d.publish("ManagerBadge:: Update Count")}function T(){return Oe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return Oe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return!$e.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function k(){var e=T();return $e.isMode("edit")&&(e=e&&(G()||w())),$e.canManage&&$e.requestStatuses&&(e=e&&!!$e.getStatusFromValue($e.newStatusOnSave)),(e=e&&!!$e.period.id)&&!$e.isMode("view")}function L(){$e.isSelfRecord?$e.request.status_id=$e.requestStatuses[y.statusNames.awaitingApproval].value:$e.canManage&&($e.request.status_id=$e.newStatusOnSave||$e.request.status_id)}function S(){if($e.isMode("edit")&&!$e.isRole("staff")&&"toil"!==j())return $e.request.calculateBalanceChange($e.selectedAbsenceType.calculation_unit_name).then(function(e){if(+$e.balance.change.amount!=+e.amount)return P.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function M(){$e.errors=[]}function O(){return $e.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function $(){ee()&&!$e.isRole("staff")&&($e.request.change_balance=!0)}function x(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return $e.request.delete().then(function(){$e.dismissModal(),d.publish("LeaveRequest::delete",$e.request)})}})}function E(){i.dismiss({$value:"cancel"})}function B(){var e=j();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function N(){return F($e.getStatusFromValue($e.request.status_id).name)}function F(e){return n.map(Te[e],function(e){return $e.requestStatuses[e]})}function j(){return $e.request?$e.request.request_type:$e.leaveType||null}function U(){return!$e.request||e.equals({},$e.requestStatuses)?[]:$e.request.status_id?N():F("none")}function W(e){return n.find($e.requestStatuses,function(t){return t.value===e})}function H(e){$e.errors=n.isArray(e)?e:[e],$e.loading.absenceTypes=!1,$e.submitting=!1}function G(){return!e.equals(Ie,$e.request.attributes())||$e.canManage&&$e.newStatusOnSave}function Y(){return $e.postContactSelection=!0,$e.staffMemberSelectionComplete=!1,$e.request.contact_id?o.resolve().then(ie).then(ce).then(he).then(be).then(Z).then(z).then($e.isMode("edit")?ge:n.noop).then(function(){$e.postContactSelection=!1,$e.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Se)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Te.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Te.awaiting_approval=e,Te.more_information_required=e,Te.rejected=e,Te.approved=e,Te.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return $e.canManage?f.find($e.request.contact_id).then(function(e){$e.contactName=e.display_name}):o.resolve()}function X(){ke.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",$e.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){we++})),r.$on("$destroy",Pe),r.$on("LeaveRequestPopup::addTab",function(e,t){Oe.push(t)})}function Q(){var e,t;$e.request=$e.leaveRequest||null,e=j(),t=$e.initRequestAttributes(),"leave"===e?$e.request=_.init(t):"sickness"===e?$e.request=q.init(t):"toil"===e&&($e.request=C.init(t))}function J(){var e={};return $e.request?e=$e.request.attributes():$e.canManage||(e={contact_id:Le}),e}function K(){if(Me="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(Me="admin")}).then(function(){return"staff"===Me&&c(y.permissions.ssp.manage).then(function(e){e&&(Me="manager")})}).finally(function(){$e.canManage=$e.isRole("manager")||$e.isRole("admin")})}function Z(){($e.isRole("admin")||$e.isMode("create")&&$e.isRole("manager"))&&($e.newStatusOnSave=$e.requestStatuses[y.statusNames.approved].value)}function ee(){return!$e.request.status_id||!n.includes(["cancelled","rejected"],W($e.request.status_id).name)}function te(e){var t=$e.getStatusFromValue($e.request.status_id);return!!t&&t.name===e}function ne(e){return $e.request&&$e.request.request_type===e}function ae(e){return $e.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return Me===e}function re(){return h.all().then(function(e){$e.absencePeriods=e})}function ie(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Ae={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return $e.loading.entitlements=!0,b.all({contact_id:$e.request.contact_id,period_id:$e.period.id,type_id:{IN:Ae.ids}},!0).finally(function(){$e.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Le=e.contactId})}function le(){return $e.selectedContactId?f.find($e.selectedContactId).then(function(e){$e.managedContacts=[e]}):$e.isRole("admin")?f.all().then(function(e){$e.managedContacts=n.remove(e.list,function(e){return e.id!==Le})}):f.find(Le).then(function(e){return e.leaveManagees()}).then(function(e){$e.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){$e.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){A(),d.publish(e,$e.request),$e.errors=[],$e.dismissModal()}function pe(){["from","to"].forEach(function(e){$e.request[e+"_date"]=Ie[e+"_date"]})}function he(e){if($e.absenceTypes=me(Ae.types,e),!$e.absenceTypes.length)return o.reject(Se)}function ve(){$e.period=n.find($e.absencePeriods,function(e){return $e.isMode("create")?e.current:oe($e.request,e)})}function be(){$e.isMode("create")?($e.selectedAbsenceType=$e.absenceTypes[0],$e.request.type_id=$e.selectedAbsenceType.id):$e.selectedAbsenceType=n.find($e.absenceTypes,function(e){return e.id===$e.request.type_id})}function ge(){Ie=e.copy($e.request.attributes())}function _e(){var e;$e.request.id?(e=[$e.requestStatuses[y.statusNames.approved].value,$e.requestStatuses[y.statusNames.adminApproved].value,$e.requestStatuses[y.statusNames.rejected].value,$e.requestStatuses[y.statusNames.cancelled].value],$e.mode="edit",$e.isRole("staff")&&e.indexOf($e.request.status_id)>-1&&($e.mode="view")):$e.mode="create"}function ye(){var e=$e.request.status_id;if(!$e.isMode("view")&&!$e.submitting)return $e.submitting=!0,L(),R(),$e.request.isValid().then(ee()&&S).then($).then(!$e.request.change_balance&&pe).then(qe).then(function(){return $e.isMode("edit")?Re():O()}).catch(function(t){$e.request.status_id=e,t&&H(t)}).finally(function(){$e.submitting=!1})}function qe(){return o.all(Oe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===we&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return we>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Pe(){ke.forEach(function(e){e()})}function De(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Re(){return $e.request.update().then(Ce).then(function(){$e.isRole("manager")?fe("LeaveRequest::updatedByManager"):($e.isRole("staff")||$e.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Ae,Te={},we=0,Ie={},ke=[],Le="",Se="No entitlement",Me="",Oe=[],$e=n.assign(this,m);$e.absencePeriods=[],$e.absenceTypes=[],$e.canManage=!1,$e.contactName=null,$e.errors=[],$e.loading={absenceTypes:!0,entitlements:!0},$e.managedContacts=[],$e.mode="",$e.newStatusOnSave=null,$e.period={},$e.postContactSelection=!1,$e.requestStatuses={},$e.selectedAbsenceType={},$e.staffMemberSelectionComplete=!1,$e.submitting=!1,$e.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},$e.canChangeAbsenceType=I,$e.canSubmit=k,$e.closeAlert=M,$e.deleteLeaveRequest=x,$e.dismissModal=E,$e.getStatuses=U,$e.getStatusFromValue=W,$e.initAfterContactSelection=Y,$e.initRequestAttributes=J,$e.isLeaveStatus=te,$e.isLeaveType=ne,$e.isMode=ae,$e.isRole=se,$e.submit=ye,$e.updateAbsenceType=De,function(){$e.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),re(),de()]).then(Q).then(_e).then(ve).then(function(){return $e.canManage&&!$e.isMode("edit")&&le()}).then(function(){if($e.selectedContactId&&($e.request.contact_id=$e.selectedContactId),$e.request.contact_id)return $e.initAfterContactSelection()}).catch(H).finally(function(){$e.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,r,i,c){function u(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,r,i){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:r,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,r){function i(e){l.errorMessage=e}function c(){return r.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrleaveandabsences_work_pattern_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,r.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(i).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrleaveandabsences_work_pattern_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(),g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){i.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){r.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,r){function i(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,r){n=o.entitlements.slice(0,r),a=e.entitlements.slice(r+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,r;return s=e.indexBy(n,"entitlement_id.type_id"),r=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:r}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2, +t=C.changeLogRows.length-1;e>=0;){var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t];e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,r){o.comment&&(t=s.concat(o).concat(r),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(i).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,r,i,c,u,l,d){function m(){P.absencePeriods=t.chain(P.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){P.absenceTypes=t.filter(P.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:P.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:P.contactId,returnUrl:n})}function h(){return c.all().then(function(e){P.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:P.contactId}).then(function(e){q=e})}function g(e){r.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=P.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){P.absencePeriods=t.map(P.absencePeriods,function(e){var n=t.map(P.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

Last updated:
By: "+e.author_name+"
Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],P=this;P.absencePeriods=[],P.loading={absencePeriods:!0},P.getEditEntitlementsPageURL=p,P.openAnnualEntitlementChangeLog=g,P.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){P.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,r,i){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return r.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){i.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component.js index a3ca4a9bf35..d24c0f46db8 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component.js @@ -107,7 +107,7 @@ define([ } /** - * Loads the Leave and Absences Work Pattern Change Reasons and indexes by `value` + * Loads the Leave and Absences Work Pattern Change Reasons * * @return {Promise} resolves with {Array} */ diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-work-patterns.component.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-work-patterns.component.js index dfdb479e816..8d20a053a16 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-work-patterns.component.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-work-patterns.component.js @@ -104,12 +104,12 @@ define([ } /** - * Loads the Job Contract Revision Change Reasons and indexes by `value` + * Loads the Leave and Absences Work Pattern Change Reasons * - * @return {Promise} + * @return {Promise} resolves with {Array} */ function loadJobContractRevisionChangeReasons () { - return OptionGroup.valuesOf('hrjc_revision_change_reason') + return OptionGroup.valuesOf('hrleaveandabsences_work_pattern_change_reason') .then(function (reasons) { changeReasons = _.indexBy(reasons, 'value'); }); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/absence-tab/components/absence-tab-work-patterns.component.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/absence-tab/components/absence-tab-work-patterns.component.spec.js index 4a3c1d3b660..bf1befc94ff 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/absence-tab/components/absence-tab-work-patterns.component.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/absence-tab/components/absence-tab-work-patterns.component.spec.js @@ -34,7 +34,7 @@ WorkPattern = _WorkPattern_; spyOn(OptionGroup, 'valuesOf').and.callFake(function () { - return $q.resolve(optionGroupMock.getCollection('hrjc_revision_change_reason')); + return $q.resolve(optionGroupMock.getCollection('hrleaveandabsences_work_pattern_change_reason')); }); spyOn($log, 'debug'); @@ -47,13 +47,17 @@ describe('init()', function () { describe('when custom Work patterns are present', function () { + it('fetches values of the Work Pattern Change Reason option group', function () { + expect(OptionGroup.valuesOf).toHaveBeenCalledWith('hrleaveandabsences_work_pattern_change_reason'); + }); + it('Loads custom Work patterns', function () { expect(controller.customWorkPatterns.length).toEqual(workPatternData.workPatternsOf.values.length); }); it('Assign correct change reason label', function () { _.each(controller.customWorkPatterns, function (customWorkpattern) { - var changeReasonLabel = optionGroupMock.getCollection('hrjc_revision_change_reason').find(function (reason) { + var changeReasonLabel = optionGroupMock.getCollection('hrleaveandabsences_work_pattern_change_reason').find(function (reason) { return customWorkpattern.change_reason === reason.value; }).label; diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/data/option-group.data.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/data/option-group.data.js index 8ffbcb8efb9..484b091fcb0 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/data/option-group.data.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/data/option-group.data.js @@ -826,43 +826,6 @@ define([ 'is_active': '1' } ], - hrjc_revision_change_reason: [{ - 'id': '938', - 'option_group_id': '110', - 'label': 'Promotion', - 'value': '1', - 'name': 'Promotion', - 'filter': '0', - 'is_default': '0', - 'weight': '1', - 'is_optgroup': '0', - 'is_reserved': '0', - 'is_active': '1' - }, { - 'id': '939', - 'option_group_id': '110', - 'label': 'Increment', - 'value': '2', - 'name': 'Increment', - 'filter': '0', - 'is_default': '0', - 'weight': '2', - 'is_optgroup': '0', - 'is_reserved': '0', - 'is_active': '1' - }, { - 'id': '940', - 'option_group_id': '110', - 'label': 'Disciplinary', - 'value': '3', - 'name': 'Disciplinary', - 'filter': '0', - 'is_default': '0', - 'weight': '3', - 'is_optgroup': '0', - 'is_reserved': '0', - 'is_active': '1' - }], hrleaveandabsences_work_pattern_change_reason: [{ 'id': '1314', 'option_group_id': '196', From 81a0a551a8a20ed43cf00bfc9d14df7037994006 Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Thu, 22 Mar 2018 09:40:03 +0100 Subject: [PATCH 053/203] PCHR-3451: Typo correction --- .../js/angular/test/mocks/data/option-group.data.js | 4 ++-- .../xml/option_groups/work_pattern_change_reason_install.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/data/option-group.data.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/data/option-group.data.js index 484b091fcb0..8f29872897e 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/data/option-group.data.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/data/option-group.data.js @@ -853,9 +853,9 @@ define([ }, { 'id': '1316', 'option_group_id': '196', - 'label': 'Change in contractual type', + 'label': 'Change in contract type', 'value': '3', - 'name': 'change_in_contractual_type', + 'name': 'change_in_contract_type', 'filter': '0', 'is_default': '0', 'weight': '3', diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/work_pattern_change_reason_install.xml b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/work_pattern_change_reason_install.xml index e30adffdf3a..611be1a0d4b 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/work_pattern_change_reason_install.xml +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/work_pattern_change_reason_install.xml @@ -37,9 +37,9 @@ - + 3 - change_in_contractual_type + change_in_contract_type 0 3 0 From 3061414f26be20a62916c5a5cf5e851bbd37388e Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Fri, 23 Mar 2018 10:24:45 +0100 Subject: [PATCH 054/203] PCHR-3460: Add tool icon to edit job role options --- .../views/include/add_new_role.html | 125 +++++++++++------ .../views/include/job_role_panel.html | 128 ++++++++++++------ 2 files changed, 167 insertions(+), 86 deletions(-) diff --git a/com.civicrm.hrjobroles/views/include/add_new_role.html b/com.civicrm.hrjobroles/views/include/add_new_role.html index 049a9cef5f1..411c09dfa6e 100755 --- a/com.civicrm.hrjobroles/views/include/add_new_role.html +++ b/com.civicrm.hrjobroles/views/include/add_new_role.html @@ -85,63 +85,104 @@
- - {{$select.selected.value.title}} - -
-
-
+
+
+ + {{$select.selected.value.title}} + +
+
+
+
+ + + +
- - {{$select.selected.value.title}} - -
-
-
+
+
+ + {{$select.selected.value.title}} + +
+
+
+
+ + + +
+
- - {{$select.selected.value.title}} - -
-
-
+
+
+ + {{$select.selected.value.title}} + +
+
+
+
+ + + +
- - {{$select.selected.value.title}} - -
-
-
+
+
+ + {{$select.selected.value.title}} + +
+
+
+
+ + + +
diff --git a/com.civicrm.hrjobroles/views/include/job_role_panel.html b/com.civicrm.hrjobroles/views/include/job_role_panel.html index 07be3feac3d..f2b61df5eb3 100755 --- a/com.civicrm.hrjobroles/views/include/job_role_panel.html +++ b/com.civicrm.hrjobroles/views/include/job_role_panel.html @@ -158,17 +158,27 @@ {{jobroles.LocationsData[jobroles.editData[job_roles_data.id]['location']]['title'] || '-'}}

- - {{$select.selected.value.title}} - -
-
-
+
+
+ + {{$select.selected.value.title}} + +
+
+
+
+ + + +
@@ -181,17 +191,27 @@ {{jobroles.RegionsData[jobroles.editData[job_roles_data.id]['region']]['title'] || '-'}}

- - {{$select.selected.value.title}} - -
-
-
+
+
+ + {{$select.selected.value.title}} + +
+
+
+
+ + + +
@@ -204,17 +224,27 @@ {{jobroles.DepartmentsData[jobroles.editData[job_roles_data.id]['department']]['title'] || '-'}}

- - {{$select.selected.value.title}} - -
-
-
+
+
+ + {{$select.selected.value.title}} + +
+
+
+
+ + + +
@@ -227,17 +257,27 @@ {{jobroles.LevelsData[jobroles.editData[job_roles_data.id]['level']]['title'] || '-'}}

- - {{$select.selected.value.title}} - -
-
-
+
+
+ + {{$select.selected.value.title}} + +
+
+
+
+ + + +
From 25d1ada0b616b6b1aa9869202c6c3d185793011f Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Mon, 19 Mar 2018 14:39:37 +0000 Subject: [PATCH 055/203] PCHR-3426: Fix partial name --- ...nt-change-log.scss => _annual-entitlement-change-log.scss} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/{annual-entitlement-change-log.scss => _annual-entitlement-change-log.scss} (52%) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/annual-entitlement-change-log.scss b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_annual-entitlement-change-log.scss similarity index 52% rename from uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/annual-entitlement-change-log.scss rename to uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_annual-entitlement-change-log.scss index 45ba34906cc..988e40700a8 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/annual-entitlement-change-log.scss +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_annual-entitlement-change-log.scss @@ -1,9 +1,9 @@ .annual-entitlement-change-log-component { - table thead td { + thead td { min-width: 100px; } - table thead td.annual-entitlement-change-log-component__comments { + thead .annual-entitlement-change-log-component__comments { min-width: 300px; } } From 6780e807428acb942d22fb8b16fd7db920d30194 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Mon, 19 Mar 2018 14:41:40 +0000 Subject: [PATCH 056/203] PCHR-3426: Move buttons above tab selector --- .../components/manager-leave-container.html | 8 ++++---- .../my-leave/components/my-leave-container.html | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/manager-leave/components/manager-leave-container.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/manager-leave/components/manager-leave-container.html index f3cafdd9c82..7ee85885f06 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/manager-leave/components/manager-leave-container.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/manager-leave/components/manager-leave-container.html @@ -1,5 +1,9 @@
+ + - -
From 2830522540ed962978f7d189d8e225e42c0e66fb Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Tue, 20 Mar 2018 11:52:44 +0000 Subject: [PATCH 057/203] PCHR-3426: Remove force exactly one space after column in SASS --- package-lock.json | 6 +++--- package.json | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index ee4ea49d814..d848417e174 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3826,9 +3826,9 @@ } }, "stylelint-scss": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/stylelint-scss/-/stylelint-scss-2.3.0.tgz", - "integrity": "sha512-gYLw1jma/BUZ9eQ3hsrL/7bddQN2BJ13oSp0A0kOqje4hBrSCrUjf7rmpnK8taRWoU3KASwMo4apWg+YopDK5Q==", + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/stylelint-scss/-/stylelint-scss-2.5.0.tgz", + "integrity": "sha512-+joZpza5nQxAyGwzRMancFEl0EH9+1Vy88YzBghRMS0wHulzDPE9fEkBi6ZOlz+I3tYIBI4x9NbqO5/LkbeE3Q==", "dev": true, "requires": { "lodash": "4.17.5", diff --git a/package.json b/package.json index 4cd7dcc87f4..7fccf89e6ee 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,8 @@ "selector-class-pattern": null, "max-nesting-depth": 3, "no-extra-semicolons": true, - "no-duplicate-selectors": true + "no-duplicate-selectors": true, + "scss/dollar-variable-colon-space-after": "at-least-one-space" } }, "devDependencies": { @@ -55,6 +56,6 @@ "stylelint": "^8.4.0", "stylelint-config-sass-guidelines": "^4.1.0", "stylelint-order": "^0.8.0", - "stylelint-scss": "^2.3.0" + "stylelint-scss": "^2.5.0" } } From 720d2cca2605c10c1006f481c827305c071dcc53 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Tue, 20 Mar 2018 16:24:19 +0000 Subject: [PATCH 058/203] PCHR-3426: Fix Backstop tests --- ...sp-leave-absences-manager-leave-requests.js | 11 ++++------- .../ssp-leave-absences-my-leave-report.js | 18 +++++++++--------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/backstop_data/page-objects/ssp-leave-absences-manager-leave-requests.js b/uk.co.compucorp.civicrm.hrcore/backstop_data/page-objects/ssp-leave-absences-manager-leave-requests.js index f8de09a4b15..8d0d4613081 100644 --- a/uk.co.compucorp.civicrm.hrcore/backstop_data/page-objects/ssp-leave-absences-manager-leave-requests.js +++ b/uk.co.compucorp.civicrm.hrcore/backstop_data/page-objects/ssp-leave-absences-manager-leave-requests.js @@ -101,7 +101,8 @@ module.exports = (function () { }, /** * Apply leave on behalf of staff - * @param {String} row number corresponding to leave request in the list like leave, sickness or toil + * + * @param {String} leaveType leave, sickness or toil * @return {Promise} */ applyLeaveForStaff: function (leaveType) { @@ -109,15 +110,11 @@ module.exports = (function () { return new Promise(function (resolve) { casper.then(function () { - var selector = '.button-container leave-request-record-actions .dropdown-toggle'; - - casper.click(selector); + casper.click('leave-request-record-actions .dropdown-toggle'); }); casper.then(function () { - var leaveSerialNo = leaveType === 'leave' ? 1 : leaveType === 'sickness' ? 2 : 3; - - casper.click('.button-container li:nth-child(' + leaveSerialNo + ') a'); + casper.click('.leave-request-record-actions__new-' + leaveType); }); casper.then(function () { diff --git a/uk.co.compucorp.civicrm.hrcore/backstop_data/page-objects/ssp-leave-absences-my-leave-report.js b/uk.co.compucorp.civicrm.hrcore/backstop_data/page-objects/ssp-leave-absences-my-leave-report.js index 3653bab3874..d524e021320 100644 --- a/uk.co.compucorp.civicrm.hrcore/backstop_data/page-objects/ssp-leave-absences-my-leave-report.js +++ b/uk.co.compucorp.civicrm.hrcore/backstop_data/page-objects/ssp-leave-absences-my-leave-report.js @@ -71,17 +71,17 @@ module.exports = (function () { */ newRequest: function (requestType) { var casper = this.casper; - var requestTypes = ['leave', 'sickness', 'toil']; // must be in the same quantity and order as in UI - var requestTypeButtonIndex = requestTypes.indexOf(requestType) + 1; - var actionDropdownSelector = 'leave-request-record-actions'; - var actionButtonSelector = actionDropdownSelector + ' .dropdown-menu a:nth-child(' + requestTypeButtonIndex + ')'; casper.then(function () { - casper.click(actionDropdownSelector + ' [uib-dropdown] > button'); - casper.waitForSelector(actionButtonSelector, function () { - casper.click(actionButtonSelector); - casper.waitUntilVisible('.chr_leave-request-modal__tab .form-group'); - }); + casper.click('leave-request-record-actions .dropdown-toggle'); + }); + + casper.then(function () { + casper.click('.leave-request-record-actions__new-' + requestType); + }); + + casper.then(function () { + casper.waitUntilVisible('.chr_leave-request-modal__tab .form-group'); }); return this; From d63f48ce3f18b10ae9fd5b5dd4f1ac776ccfae95 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Tue, 20 Mar 2018 16:42:51 +0000 Subject: [PATCH 059/203] PCHR-3426: Split request record button into two --- .../css/leaveandabsence.css | 2 +- .../js/angular/dist/absence-tab.min.js | 6 ++-- .../js/angular/dist/admin-dashboard.min.js | 2 +- .../js/angular/dist/manager-leave.min.js | 4 +-- .../js/angular/dist/my-leave.min.js | 2 +- .../leave-request-record-actions.component.js | 4 +-- ...e-request-record-actions.component.spec.js | 2 +- .../_leave-request-record-actions.scss | 34 ++++++++++++++++++ .../scss/components/_leave.scss | 17 +-------- .../scss/pages/_absence-tab-page.scss | 12 +++---- .../scss/pages/_admin-dashboard-page.scss | 25 +++++++------ .../leave-request-record-actions.html | 36 ++++++++++++------- 12 files changed, 85 insertions(+), 61 deletions(-) create mode 100644 uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave-request-record-actions.scss diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/css/leaveandabsence.css b/uk.co.compucorp.civicrm.hrleaveandabsences/css/leaveandabsence.css index 09e1ca024da..3f0b2ede710 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/css/leaveandabsence.css +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/css/leaveandabsence.css @@ -1 +1 @@ -#bootstrap-theme .chr_disabled{opacity:0.5;pointer-events:none}#bootstrap-theme .table-condensed>thead>tr>th{background:#fff !important;padding:8px 5px}#bootstrap-theme .table-condensed-mixed>thead>tr>th,#bootstrap-theme .table-condensed-mixed>thead>tr>td,#bootstrap-theme .table-condensed-mixed>tbody>tr>th,#bootstrap-theme .table-condensed-mixed>tbody>tr>td{padding-left:5px;padding-right:5px}#bootstrap-theme .table-condensed>tbody>tr>td:first-child,#bootstrap-theme .table-condensed>tbody>tr>th:first-child,#bootstrap-theme .table-condensed>thead>tr>td:first-child,#bootstrap-theme .table-condensed>thead>tr>th:first-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>td:first-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>th:first-child,#bootstrap-theme .table-condensed-mixed>thead>tr>td:first-child,#bootstrap-theme .table-condensed-mixed>thead>tr>th:first-child{padding-left:20px}#bootstrap-theme .table-condensed>tbody>tr>td:last-child,#bootstrap-theme .table-condensed>tbody>tr>th:last-child,#bootstrap-theme .table-condensed>thead>tr>td:last-child,#bootstrap-theme .table-condensed>thead>tr>th:last-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>td:last-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>th:last-child,#bootstrap-theme .table-condensed-mixed>thead>tr>td:last-child,#bootstrap-theme .table-condensed-mixed>thead>tr>th:last-child{padding-right:20px}#bootstrap-theme .table-nested{overflow-y:hidden;position:relative}#bootstrap-theme .table-nested:before{box-shadow:inset 0px 6px 9px -6px rgba(0,0,0,0.2);content:'';display:block;height:10px;left:0;position:absolute;top:0;width:100%;z-index:10}#bootstrap-theme .table-nested:after{box-shadow:inset 0px -4px 9px -6px rgba(0,0,0,0.2);content:'';display:block;height:10px;left:0;position:absolute;bottom:0;width:100%;z-index:10}#bootstrap-theme .table-nested>table,#bootstrap-theme .table-nested>.table{background-color:#fff}#bootstrap-theme .table-nested>table>tbody>tr>td:first-child,#bootstrap-theme .table-nested>table>tbody>tr>th:first-child,#bootstrap-theme .table-nested>table>thead>tr>td:first-child,#bootstrap-theme .table-nested>table>thead>tr>th:first-child,#bootstrap-theme .table-nested>.table>tbody>tr>td:first-child,#bootstrap-theme .table-nested>.table>tbody>tr>th:first-child,#bootstrap-theme .table-nested>.table>thead>tr>td:first-child,#bootstrap-theme .table-nested>.table>thead>tr>th:first-child{padding-left:30px;position:relative}#bootstrap-theme .table-nested>table>tbody>tr>td:first-child:before,#bootstrap-theme .table-nested>table>tbody>tr>th:first-child:before,#bootstrap-theme .table-nested>table>thead>tr>td:first-child:before,#bootstrap-theme .table-nested>table>thead>tr>th:first-child:before,#bootstrap-theme .table-nested>.table>tbody>tr>td:first-child:before,#bootstrap-theme .table-nested>.table>tbody>tr>th:first-child:before,#bootstrap-theme .table-nested>.table>thead>tr>td:first-child:before,#bootstrap-theme .table-nested>.table>thead>tr>th:first-child:before{background:#C2CFD8;content:'';display:block;height:110%;left:0;position:absolute;top:0;width:10px;z-index:2}#bootstrap-theme .table-nested>table>tbody>tr>td:last-child,#bootstrap-theme .table-nested>table>tbody>tr>th:last-child,#bootstrap-theme .table-nested>table>thead>tr>td:last-child,#bootstrap-theme .table-nested>table>thead>tr>th:last-child,#bootstrap-theme .table-nested>.table>tbody>tr>td:last-child,#bootstrap-theme .table-nested>.table>tbody>tr>th:last-child,#bootstrap-theme .table-nested>.table>thead>tr>td:last-child,#bootstrap-theme .table-nested>.table>thead>tr>th:last-child{padding-right:30px;position:relative}#bootstrap-theme .table-nested>table>tbody>tr>td:last-child:after,#bootstrap-theme .table-nested>table>tbody>tr>th:last-child:after,#bootstrap-theme .table-nested>table>thead>tr>td:last-child:after,#bootstrap-theme .table-nested>table>thead>tr>th:last-child:after,#bootstrap-theme .table-nested>.table>tbody>tr>td:last-child:after,#bootstrap-theme .table-nested>.table>tbody>tr>th:last-child:after,#bootstrap-theme .table-nested>.table>thead>tr>td:last-child:after,#bootstrap-theme .table-nested>.table>thead>tr>th:last-child:after{background:#C2CFD8;content:'';display:block;height:110%;right:0;position:absolute;top:0;width:10px;z-index:2}@media screen and (max-width: 767px){#bootstrap-theme .table-nested.table-responsive{border:0;margin-bottom:0}}#bootstrap-theme .table-nested-cell{padding:0 !important}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(1){width:40%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(2){width:15%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(3){width:35%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(4){width:10%}#bootstrap-theme .chr_absence-work-pattern__work-pattern-listing{display:inline-block}#bootstrap-theme .chr_absence-work-pattern__alert{margin-bottom:0 !important}#bootstrap-theme .chr_annual-entitlements__period{width:130px}#bootstrap-theme .chr_annual-entitlements__edit-entitlements{width:150px}#bootstrap-theme .chr_contract-entitlements__position{width:140px}@media (max-width: 992px){#bootstrap-theme .chr_leave-balance-tab .chr_leave-balance-tab__filter:not(:last-child){padding-bottom:15px}}#bootstrap-theme .chr_leave-balance-tab__body{padding:0}@media (min-width: 1200px){#bootstrap-theme .chr_leave-calendar__dates-container .chr_leave-calendar{table-layout:fixed}}#bootstrap-theme .chr_leave-calendar__names-container .chr_leave-calendar{table-layout:fixed}#bootstrap-theme .chr_leave-calendar__day{font-size:10px !important;line-height:1.4em !important;padding:10px !important;text-align:center !important}@media (min-width: 1200px){#bootstrap-theme .chr_leave-calendar__day{padding:10px 0 !important}}#bootstrap-theme .chr_leave-calendar__day--disabled{opacity:0.5}#bootstrap-theme .chr_leave-calendar__day--current{color:#0071BD !important}#bootstrap-theme .chr_leave-calendar__item{color:#FFF;display:block;font-size:10px;height:100%;position:relative;text-align:center;text-transform:uppercase;width:100%}#bootstrap-theme .chr_leave-calendar__item>span{bottom:0;left:0;margin:auto;position:absolute;right:0;top:0;height:1.2em}#bootstrap-theme .chr_leave-calendar__item>.chr_leave-calendar__time-unit{font-size:7px;height:1em;margin-left:-1px}#bootstrap-theme .chr_leave-calendar__item>a{cursor:pointer;bottom:0;left:0;margin:auto;position:absolute;right:0;top:0}#bootstrap-theme .chr_leave-calendar__item--disabled{cursor:not-allowed;opacity:0.5}#bootstrap-theme .chr_leave-calendar__item--type--late{background-color:#eca67e;border-color:#eca67e}#bootstrap-theme .chr_leave-calendar__item--type--non-working{background-color:#41afcb !important;border-color:#41afcb}#bootstrap-theme .chr_leave-calendar__item--type--public-holiday{background-color:#8ec68a !important;border-color:#8ec68a}#bootstrap-theme .chr_leave-calendar__item--type--weekend{background-color:#c7cbd0 !important;border-color:#c7cbd0}#bootstrap-theme .chr_leave-calendar__item--alt{background:#FFF !important;border:1px solid transparent;color:#464354}#bootstrap-theme .chr_leave-calendar__item--requested:before{background:#c7cbd0;content:'';display:block;height:.5em;position:absolute;width:100%;top:0}#bootstrap-theme .chr_leave-calendar__item--toil-requested:before{background:red;content:'';display:block;height:.5em;left:-1px;position:absolute;width:calc(100% + 2px);top:-1px}#bootstrap-theme .chr_leave-calendar__items>td{overflow:hidden;height:35px;padding:0 !important}#bootstrap-theme .chr_leave-calendar__items leave-calendar-day{display:block;height:100%}#bootstrap-theme .chr_leave-calendar__legend__title{font-size:12px}#bootstrap-theme .chr_leave-calendar__legend>.row:not(:first-child){margin-top:20px}#bootstrap-theme .chr_leave-calendar__legend .chr_leave-calendar__legend__entry{margin-top:10px}@media (min-width: 768px){#bootstrap-theme .chr_leave-calendar__legend .chr_leave-calendar__legend__entry{margin-top:0}}#bootstrap-theme .chr_leave-calendar__legend__entry{overflow:auto}#bootstrap-theme .chr_leave-calendar__legend__entry+#bootstrap-theme .chr_leave-calendar__legend__entry{margin-top:10px}#bootstrap-theme .chr_leave-calendar__legend__entry>.chr_leave-calendar__item{font-size:8px;height:20px;margin-right:10px;position:absolute;width:20px}#bootstrap-theme .chr_leave-calendar__legend__label{display:inline-block;font-size:12px;margin-left:26px}#bootstrap-theme .chr_leave-calendar__month-header{background:#F3F6F7}#bootstrap-theme .chr_leave-calendar__month-header .panel-title{font-size:16px}#bootstrap-theme td.chr_leave-calendar__name,#bootstrap-theme th.chr_leave-calendar__name{font-size:12px !important;line-height:100%;padding:0 20px !important;text-align:left;text-overflow:ellipsis;width:100%}#bootstrap-theme th.chr_leave-calendar__name,#bootstrap-theme th.chr_leave-calendar__day{height:49px}#bootstrap-theme th.chr_leave-calendar__name{padding-bottom:10px !important}#bootstrap-theme td.chr_leave-calendar__name{vertical-align:middle !important}#bootstrap-theme .chr_leave-calendar__pagination{font-size:10px;text-align:center}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"]{outline:none;padding:0;line-height:1em}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"] .fa{color:#555}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"][disabled] .fa{opacity:0.5}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"]:hover:not([disabled]) .fa{color:#464354}#bootstrap-theme .chr_leave-calendar__pagination-next{border-top:none}#bootstrap-theme .chr_leave-calendar__pagination-next th{height:24px;padding:4px 0 6px !important}#bootstrap-theme .chr_leave-calendar__pagination-next .chr_leave-calendar__pagination{padding-right:3px !important}#bootstrap-theme .chr_leave-calendar__month-container{margin:0}#bootstrap-theme .chr_leave-calendar__month-container>div{padding:0}#bootstrap-theme .chr_leave-calendar__dates-container{overflow-x:auto}#bootstrap-theme .chr_leave-calendar__admin-filters-hint{display:inline-block;font-size:20px;vertical-align:middle}#bootstrap-theme .chr_leave-calendar__admin-filters-select{width:calc(100% - 50px);display:inline-block;margin-right:20px}#bootstrap-theme .chr_leave-report .dropdown-toggle{color:#464354;padding:0 10px}#bootstrap-theme .chr_leave-report .dropdown-toggle:hover{background:#e6e6e6}#bootstrap-theme .chr_leave-report table{table-layout:fixed}#bootstrap-theme .chr_leave-report table thead th,#bootstrap-theme .chr_leave-report table tbody td{padding:8px 5px}#bootstrap-theme .chr_leave-report__label{color:#464354;font-weight:700}#bootstrap-theme .chr_leave-report__label>.fa{margin-right:5px}#bootstrap-theme .chr_leave-report__label--toggle{cursor:pointer;user-select:none}#bootstrap-theme .chr_leave-report__heading{background-color:#F3F6F7;border-bottom:1px solid #dadcde}#bootstrap-theme .chr_leave-report__heading .chr_leave-report__export-button{line-height:2.4}#bootstrap-theme .chr_leave-report__table table,#bootstrap-theme .chr_leave-report__table .table{border-collapse:separate}#bootstrap-theme .chr_leave-report__table table>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>tbody>tr:first-child>td{border-top-width:0}#bootstrap-theme .chr_leave-report__table table>thead+tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>thead+tbody>tr:first-child>td{border-top-width:1px}#bootstrap-theme .chr_leave-report__table table:not(.table-bordered):not(.table-condensed)>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table:not(.table-bordered):not(.table-condensed)>tbody>tr:first-child>td{border-color:#F3F6F7}#bootstrap-theme .chr_leave-report__table table>thead>tr>th,#bootstrap-theme .chr_leave-report__table .table>thead>tr>th{background:#F3F6F7;border-bottom:0;color:#464354;text-transform:capitalize}#bootstrap-theme .chr_leave-report__table table>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>tbody>tr:first-child>td{border-color:#E8EEF0 !important}#bootstrap-theme .chr_leave-report__table table>tfoot>tr,#bootstrap-theme .chr_leave-report__table .table>tfoot>tr{background:#F3F6F7}#bootstrap-theme .chr_leave-report__table>table>thead>tr>th,#bootstrap-theme .chr_leave-report__table>.table>thead>tr>th{padding-bottom:13px;padding-top:13px}#bootstrap-theme .chr_leave-report__table-container{overflow:auto}#bootstrap-theme .chr_leave-report__table-container .panel{display:inline-block;min-width:100%}#bootstrap-theme .chr_leave-report__table__heading--action{width:45px}#bootstrap-theme .chr_leave-report__table__heading--label{width:280px}#bootstrap-theme .chr_leave-report__table__heading--dates{width:170px}#bootstrap-theme .chr_leave-report__table__heading--status{width:180px}#bootstrap-theme .chr_leave-report__table__heading--type{width:65px;word-break:break-word}#bootstrap-theme .chr_leave-request-comment{margin-top:10px}#bootstrap-theme .chr_leave-request-comment__text{border-bottom:1px solid #E8EEF0;color:#C2CFD8;margin-right:10px;padding-bottom:20px}#bootstrap-theme .chr_leave-request-files_list{height:150px;overflow-y:auto;margin-top:20px;margin-bottom:20px}#bootstrap-theme .chr_leave-request-files_meta{margin-bottom:10px}#bootstrap-theme .chr_leave-request-files_upload{border:dashed 1px #464354;padding:20px}#bootstrap-theme .chr_leave-request-files_upload_action{padding:5px}#bootstrap-theme .chr_leave-request-files_file-name{display:inline-block;max-width:240px;overflow:hidden;text-overflow:ellipsis;vertical-align:bottom}#bootstrap-theme .chr_leave-request-files_delete{margin-top:-7px}#bootstrap-theme .chr_leave-request-modal .modal-title{font-size:18px !important}#bootstrap-theme .chr_leave-request-modal .table-responsive{border:0}#bootstrap-theme .chr_leave-request-modal .chr_leave-request-date-picker-container .input-group{width:100%}@media screen and (max-width: 767px){#bootstrap-theme .chr_leave-request-modal .chr_leave-request-date-picker-container{margin-bottom:10px}}#bootstrap-theme .chr_leave-request-modal__chevron{font-size:0.6em;margin-right:5px;vertical-align:middle}#bootstrap-theme .chr_leave-request-modal__comments{height:230px;margin-bottom:20px;overflow:auto}#bootstrap-theme .chr_leave-request-modal__comments_empty{margin-bottom:20px}#bootstrap-theme .chr_leave-request-modal__footer{margin:0}#bootstrap-theme .chr_leave-request-modal__delete{margin-left:15px;margin-top:8px}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container{margin-bottom:20px}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container ul{opacity:1 !important}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container:not(.ui-select-multiple) input{width:100% !important}#bootstrap-theme .chr_leave-request-modal__form-group,#bootstrap-theme .chr_leave-request-modal__required-documents>div{margin-bottom:15px}#bootstrap-theme .chr_leave-request-modal__response{padding:20px 20px 0}#bootstrap-theme .chr_leave-request-modal__response label{font-size:17px;margin-top:-3px}#bootstrap-theme .chr_leave-request-modal__response .chr_wysiwyg{margin-top:15px}#bootstrap-theme .chr_leave-request-modal__required-documents input{margin-right:5px}#bootstrap-theme .chr_leave-request-modal__small_spinner>div.chr_spinner{margin-top:18px;min-height:initial}#bootstrap-theme .chr_leave-request-modal__tab input[uib-datepicker-popup]{font-size:13px}#bootstrap-theme .chr_leave-request-modal__table{border:1px solid #F3F6F7;margin-bottom:15px !important}#bootstrap-theme .chr_leave-request-modal__user-info{font-size:17px;padding:20px}#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(1){color:#464354}#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(2){color:#555}@media screen and (min-width: 480px){#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(2){border-left:1px solid #E8EEF0}}#bootstrap-theme .chr_leave-request-modal__span-expiry{display:inline-block;margin-top:7px}#bootstrap-theme .chr_leave-request-modal__expiry-clear{position:absolute;right:3.5em;top:0.6em;z-index:2}#bootstrap-theme .chr_leave-request-modal__small-text{font-size:80%}#bootstrap-theme .chr_leave-request-modal__custom-deduction-toggling-row{margin-top:-5px}@media screen and (min-width: 768px){#bootstrap-theme .chr_leave-request-modal__custom-deduction-label{text-align:right}}@media screen and (max-width: 767px){#bootstrap-theme .chr_leave-request-modal__custom-deduction-label{margin-bottom:10px}}#bootstrap-theme .chr_leave-request-modal .form-group{overflow:inherit !important}#bootstrap-theme .chr_leave-request-modal .alert{margin-bottom:0 !important}#bootstrap-theme .chr_leave-request-modal input[uib-datepicker-popup]{box-shadow:none !important;background-color:inherit !important;color:inherit !important;cursor:pointer !important;border-right:none}#bootstrap-theme .leave-widget h4{color:#4D4D69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px}#bootstrap-theme .leave-widget__types>table,#bootstrap-theme .leave-widget__sickness>table,#bootstrap-theme .leave-widget__next-leave>table{border:none}#bootstrap-theme .leave-widget__types>table thead tr th,#bootstrap-theme .leave-widget__sickness>table thead tr th,#bootstrap-theme .leave-widget__next-leave>table thead tr th{color:#4D4D69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px;background:none;width:35%}#bootstrap-theme .leave-widget__types>table thead tr th:first-child,#bootstrap-theme .leave-widget__sickness>table thead tr th:first-child,#bootstrap-theme .leave-widget__next-leave>table thead tr th:first-child{width:65%}#bootstrap-theme .leave-widget__types>table tbody tr td,#bootstrap-theme .leave-widget__sickness>table tbody tr td,#bootstrap-theme .leave-widget__next-leave>table tbody tr td{color:#0071BD;font-size:16px;font-weight:600;padding-bottom:9px}#bootstrap-theme .leave-widget__types>table tbody tr td:first-child,#bootstrap-theme .leave-widget__sickness>table tbody tr td:first-child,#bootstrap-theme .leave-widget__next-leave>table tbody tr td:first-child{color:#464354}#bootstrap-theme .leave-widget hr{border-color:#DEE4ED;margin-bottom:25px;margin-top:25px}#bootstrap-theme .leave-widget__sickness h4{margin-top:18px}#bootstrap-theme .leave-widget__next-leave h3{font-size:16px;margin-bottom:16px;margin-top:0}#bootstrap-theme .leave-widget__next-leave__deduction{font-size:16px;font-weight:600;color:#464354}#bootstrap-theme .chr_leave__page-selector-dropdown{margin-right:5px;position:relative;top:1px;width:calc(100% - 80px)}#bootstrap-theme .chr_leave__page-selector-dropdown select{height:40px}#bootstrap-theme .chr_leave__page-selector-dropdown .crm_custom-select__arrow{line-height:40px;width:40px}#bootstrap-theme leave-request-record-actions .dropdown-menu{left:auto;right:0}#bootstrap-theme leave-request-record-actions .dropdown-toggle{height:40px}#bootstrap-theme leave-request-record-actions i.fa{margin-right:8px}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;border-bottom:1px solid #dadcde;margin:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header .panel-title{margin-top:7px;display:inline-block}@media screen and (max-width: 992px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header>div:not(:last-child),#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header .panel-title{padding-bottom:20px}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter{display:inline-block;margin-top:7px;white-space:nowrap}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter .fa{font-size:0.6em;margin-right:5px;margin-top:-2px;vertical-align:middle}@media screen and (max-width: 991px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter{margin-top:15px}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;border-bottom:1px solid #dadcde;margin:0;padding-top:15px}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>*{padding-left:10px !important;padding-right:10px !important}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>div:not(:last-child){padding-bottom:20px}}@media screen and (min-width: 992px) and (max-width: 1199px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>.no_gutter{padding-bottom:0 !important}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body{margin:0;padding:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body [class^="col-"],#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body [class*=" col-"]{padding:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body a{cursor:pointer}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container{padding-left:10px;padding-right:10px;background-color:#f7f7f9}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container>div{padding-left:15px;padding-right:15px}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .form-group{overflow:inherit !important}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .panel{background-image:none !important}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .panel-body,#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .chr_vertical_tabs{background-color:#f7f7f9}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] input[type="search"]{width:100% !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header .checkbox{margin-top:5px}#bootstrap-theme .page-manager-leave .chr_manage_leave_requests .btn-sm{font-size:100% !important}#bootstrap-theme .chr_manager_calendar__header{padding-left:10px;padding-right:10px;padding-top:15px;margin:0;background-color:#f7f7f9;border-bottom:1px solid #dadcde}#bootstrap-theme .chr_manager_calendar__header>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manager_calendar__header .checkbox{margin:0}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manager_calendar__header>div:not(:last-child){padding-bottom:20px}}#bootstrap-theme .chr_manager_calendar__sub-header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;margin:0}#bootstrap-theme .chr_manager_calendar__sub-header>*{padding-left:10px !important;padding-right:10px !important}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manager_calendar__sub-header>div:not(:last-child){padding-bottom:20px}#bootstrap-theme .chr_manager_calendar__sub-header .ui-select-container{height:auto}}#bootstrap-theme .annual-entitlement-change-log-component table thead td{min-width:100px}#bootstrap-theme .annual-entitlement-change-log-component table thead td.annual-entitlement-change-log-component__comments{min-width:300px}#bootstrap-theme .time-amount-picker .crm_custom-select{display:inline-block;margin-right:2px}#bootstrap-theme .time-amount-picker .crm_custom-select:nth-child(2){margin-left:10px}#bootstrap-theme .absence-tab-page .btn-group{margin-bottom:20px}#bootstrap-theme .absence-tab-page .btn-group>.btn{border-color:transparent !important}#bootstrap-theme .absence-tab-page .tab-pane{padding:0 !important}#bootstrap-theme .absence-tab-page .tab-content{background-color:transparent !important}#bootstrap-theme .crm-absence_type-form-block .crm-section .label{width:35%}#bootstrap-theme .crm-absence_type-form-block .crm-section .content{margin-left:40%}#bootstrap-theme .crm-absence_type-form-block .toil-option,#bootstrap-theme .crm-absence_type-form-block .carry-forward-option,#bootstrap-theme .crm-absence_type-form-block .toil-expiration,#bootstrap-theme .crm-absence_type-form-block .carry-forward-expiration-duration,#bootstrap-theme .crm-absence_type-form-block .carry-forward-expiration-date{display:none}#bootstrap-theme .crm-absence_type-form-block .sp-replacer{padding:2px}#bootstrap-theme .crm-absence_type-form-block .sp-preview{height:15px;width:15px}#bootstrap-theme .crm-absence_type-form-block .sp-dd{height:0;line-height:15px;font-size:9px}.page-civicrm-leaveandabsences-dashboard h1.page-title,.page-civicrm-leaveandabsences-dashboard #branding{display:none !important}.page-civicrm-leaveandabsences-dashboard #page{margin:0;padding:0}.admin-dashboard-page{position:relative}.admin-dashboard-page .crm_page__topbar{height:65px}.admin-dashboard-page .crm_page__topbar .dropdown-toggle{margin:15px 30px 0 0 !important}.admin-dashboard-page .crm_page__topbar .dropdown-toggle+ul{margin-right:30px !important}.admin-dashboard-page .chr_admin-dashboard_side-nav{overflow:hidden;width:170px;position:absolute;height:calc(100% - 12px);background-color:#fff}.admin-dashboard-page .chr_admin-dashboard_side-nav li.active{background:#E8EEF0}.admin-dashboard-page .chr_admin-dashboard_content{float:right;width:calc(100% - 170px - 16px * 2);margin:16px;margin-bottom:0}#bootstrap-theme #calculation-details{background:#fff}#bootstrap-theme #calculation-details .base-contractual-entitlement{color:#0071BD}#bootstrap-theme #calculation-details .working-days-to-work{color:#44CB7E}#bootstrap-theme #calculation-details .working-days-in-period{color:#E6AB5E}#bootstrap-theme #calculation-details .contract-1-pro-rata{color:#E6807F}#bootstrap-theme #calculation-details .contract-2-pro-rata{color:#797300}#bootstrap-theme #calculation-details .contract-3-pro-rata{color:#904E1E}#bootstrap-theme #calculation-details .contract-4-pro-rata{color:#0511B1}#bootstrap-theme #calculation-details .contract-5-pro-rata{color:#4B9609}#bootstrap-theme #calculation-details .calculation-pro-rata{color:#95c0ff}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body{padding-top:20px;padding-bottom:20px}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body .row:first-child h3{margin-top:0}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body h3{margin-bottom:20px}#bootstrap-theme .crm-leave-and-absences-form-block .panel-footer .crm-button:last-child{margin-right:0}#bootstrap-theme.crm-leave-and-balance-import .panel{background-color:#fff}#bootstrap-theme.crm-leave-and-balance-import .panel-header{position:relative}#bootstrap-theme.crm-leave-and-balance-import .panel-header h2{padding:10px 20px}#bootstrap-theme.crm-leave-and-balance-import .panel-body .row:not(:last-child){padding-bottom:2em}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats .label{display:none}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats label{font-weight:normal !important}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats td{border:0;padding:0}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block{box-shadow:none;padding:0}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table{margin-bottom:2em;width:100%}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table th{padding:10px 20px;border-right:none}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table th,#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table td{padding:5px}#bootstrap-theme.crm-leave-and-balance-import #preview-counts,#bootstrap-theme.crm-leave-and-balance-import #summary-counts{box-shadow:none;margin-bottom:2em;width:100%}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td{background-color:#f2dede !important;color:#CF3458}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td a,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td a{color:#bd2d4e;font-weight:bold}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td a:hover,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td a:hover{color:#0062a4}#bootstrap-theme.manage-entitlements-form .wider-hr{margin-left:-20px;margin-right:-20px;border-width:2px}#bootstrap-theme.manage-entitlements-form .wider-row{margin-left:-20px;margin-right:-20px}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters{padding:15px 0;text-align:center}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .override-filters label{display:inline-block}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .override-filters label:before{display:none}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .absence-type-filter{margin-right:10px}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .col-sm-4:last-child{text-align:right}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list{margin-bottom:0}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement-header .title{float:left;width:65%}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement-header .actions{float:right}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list tr.hidden{display:none}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .absence-type{color:#fff;display:inline-block;padding:5px}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement .overridden-proposed-entitlement,#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement .calculation-unit{display:none}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .borderless-button{background-color:transparent;border:0;cursor:pointer}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .add-comment{font-size:1.1em}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .comment-text{display:none}#bootstrap-theme.manage-entitlements-form .manage-entitlements-form__filters{padding-bottom:1em}#bootstrap-theme.manage-entitlements-form .table{background:#f9f9f9;border-top:1px solid #E8EEF0;border-bottom:1px solid #E8EEF0;margin-bottom:2em}#bootstrap-theme.manage-entitlements-form .table th{background:#F3F6F7 !important}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header{border-left:1px solid #E8EEF0;border-right:1px solid #E8EEF0;background:#e4ebed !important;min-width:200px}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .row>div{display:table-cell;float:none;vertical-align:bottom}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .fa{color:#4D4D69}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .action-button-container{padding:0}#bootstrap-theme.manage-entitlements-form .table td.proposed-entitlement{border-left:1px solid #E8EEF0;border-right:1px solid #E8EEF0;background:white}#bootstrap-theme.manage-entitlements-form .table span.absence-type{border-radius:3px;padding:0 5px}#bootstrap-theme.manage-entitlements-form .table tbody .fa{color:#0071BD}#bootstrap-theme.manage-entitlements-form .crm-container .CRM_HRLeaveAndAbsences_Form_ManageEntitlements .crm-button-type-next{float:right !important}#bootstrap-theme.manage-entitlements-form .panel-footer{border-top:none}#add-comment-dialog{display:none}#add-comment-dialog .calculation_comment{box-sizing:border-box;padding:10px;width:100%}#bootstrap-theme .crm-work-pattern-form-block .ui-tabs.ui-widget-content{background:none}#bootstrap-theme .work-pattern-calendar .number-of-weeks{padding:15px 0 15px 0}#bootstrap-theme .work-pattern-calendar .work-pattern-week{border-top:1px solid rgba(0,0,0,0.2);padding:15px 0 15px 0;margin-bottom:15px}#bootstrap-theme .work-pattern-calendar .work-pattern-week.hidden-week{display:none}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-number{float:left;font-weight:bold;padding:5px 0 15px 5px}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days{table-layout:fixed}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-hours{float:right;padding:5px 5px 15px 0}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-hours .number-of-hours{font-weight:bold}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days td{padding:5px 10px 5px 10px}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days input{min-width:0;text-align:center}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days select{min-width:0;width:100% !important}#bootstrap-theme .work-pattern-calendar .work-pattern-week .hours-row td{padding-top:15px;padding-bottom:15px;border-top:1px solid rgba(0,0,0,0.2);border-bottom:1px solid rgba(0,0,0,0.2)}.caret{display:inline-block;width:0;height:0;margin-left:2px;vertical-align:middle;border-top:4px dashed;border-top:4px solid \9;border-right:4px solid transparent;border-left:4px solid transparent}.dropup,.dropdown{position:relative}.dropdown-toggle:focus{outline:0}.dropdown-menu{position:absolute;top:100%;left:0;z-index:1000;display:none;float:left;min-width:160px;padding:5px 0;margin:2px 0 0;list-style:none;font-size:13px;text-align:left;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.15);border-radius:2px;-webkit-box-shadow:0 6px 12px rgba(0,0,0,0.175);box-shadow:0 6px 12px rgba(0,0,0,0.175);background-clip:padding-box}.dropdown-menu.pull-right{right:0;left:auto}.dropdown-menu .divider{height:1px;margin:9px 0;overflow:hidden;background-color:#e5e5e5}.dropdown-menu>li>a{display:block;padding:3px 20px;clear:both;font-weight:normal;line-height:1.5384615385;color:#4D4D69;white-space:nowrap}.dropdown-menu>li>a:hover,.dropdown-menu>li>a:focus{text-decoration:none;color:#42425a;background-color:#F3F6F7}.dropdown-menu>.active>a,.dropdown-menu>.active>a:hover,.dropdown-menu>.active>a:focus{color:#fff;text-decoration:none;outline:0;background-color:#0071BD}.dropdown-menu>.disabled>a,.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{color:#E8EEF0}.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{text-decoration:none;background-color:transparent;background-image:none;filter:progid:DXImageTransform.Microsoft.gradient(enabled = false);cursor:not-allowed}.open>.dropdown-menu{display:block}.open>a{outline:0}.dropdown-menu-right{left:auto;right:0}.dropdown-menu-left{left:0;right:auto}.dropdown-header{display:block;padding:3px 20px;font-size:12px;line-height:1.5384615385;color:#464354;white-space:nowrap}.dropdown-backdrop{position:fixed;left:0;right:0;bottom:0;top:0;z-index:990}.pull-right>.dropdown-menu{right:0;left:auto}.dropup .caret,.navbar-fixed-bottom .dropdown .caret{border-top:0;border-bottom:4px dashed;border-bottom:4px solid \9;content:""}.dropup .dropdown-menu,.navbar-fixed-bottom .dropdown .dropdown-menu{top:auto;bottom:100%;margin-bottom:2px}@media (min-width: 768px){.navbar-right .dropdown-menu{right:0;left:auto}.navbar-right .dropdown-menu-left{left:0;right:auto}}.dropdown-header{padding:11px 20px}.dropdown-menu{-webkit-box-shadow:0 3px 18px 0 rgba(48,40,40,0.25);box-shadow:0 3px 18px 0 rgba(48,40,40,0.25);border:0;margin:0;padding:0}.dropdown-menu>li{border:0;margin:0;padding:0}.dropdown-menu>li>a{padding:11px 20px} +#bootstrap-theme .chr_disabled{opacity:0.5;pointer-events:none}#bootstrap-theme .table-condensed>thead>tr>th{background:#fff !important;padding:8px 5px}#bootstrap-theme .table-condensed-mixed>thead>tr>th,#bootstrap-theme .table-condensed-mixed>thead>tr>td,#bootstrap-theme .table-condensed-mixed>tbody>tr>th,#bootstrap-theme .table-condensed-mixed>tbody>tr>td{padding-left:5px;padding-right:5px}#bootstrap-theme .table-condensed>tbody>tr>td:first-child,#bootstrap-theme .table-condensed>tbody>tr>th:first-child,#bootstrap-theme .table-condensed>thead>tr>td:first-child,#bootstrap-theme .table-condensed>thead>tr>th:first-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>td:first-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>th:first-child,#bootstrap-theme .table-condensed-mixed>thead>tr>td:first-child,#bootstrap-theme .table-condensed-mixed>thead>tr>th:first-child{padding-left:20px}#bootstrap-theme .table-condensed>tbody>tr>td:last-child,#bootstrap-theme .table-condensed>tbody>tr>th:last-child,#bootstrap-theme .table-condensed>thead>tr>td:last-child,#bootstrap-theme .table-condensed>thead>tr>th:last-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>td:last-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>th:last-child,#bootstrap-theme .table-condensed-mixed>thead>tr>td:last-child,#bootstrap-theme .table-condensed-mixed>thead>tr>th:last-child{padding-right:20px}#bootstrap-theme .table-nested{overflow-y:hidden;position:relative}#bootstrap-theme .table-nested:before{box-shadow:inset 0px 6px 9px -6px rgba(0,0,0,0.2);content:'';display:block;height:10px;left:0;position:absolute;top:0;width:100%;z-index:10}#bootstrap-theme .table-nested:after{box-shadow:inset 0px -4px 9px -6px rgba(0,0,0,0.2);content:'';display:block;height:10px;left:0;position:absolute;bottom:0;width:100%;z-index:10}#bootstrap-theme .table-nested>table,#bootstrap-theme .table-nested>.table{background-color:#fff}#bootstrap-theme .table-nested>table>tbody>tr>td:first-child,#bootstrap-theme .table-nested>table>tbody>tr>th:first-child,#bootstrap-theme .table-nested>table>thead>tr>td:first-child,#bootstrap-theme .table-nested>table>thead>tr>th:first-child,#bootstrap-theme .table-nested>.table>tbody>tr>td:first-child,#bootstrap-theme .table-nested>.table>tbody>tr>th:first-child,#bootstrap-theme .table-nested>.table>thead>tr>td:first-child,#bootstrap-theme .table-nested>.table>thead>tr>th:first-child{padding-left:30px;position:relative}#bootstrap-theme .table-nested>table>tbody>tr>td:first-child:before,#bootstrap-theme .table-nested>table>tbody>tr>th:first-child:before,#bootstrap-theme .table-nested>table>thead>tr>td:first-child:before,#bootstrap-theme .table-nested>table>thead>tr>th:first-child:before,#bootstrap-theme .table-nested>.table>tbody>tr>td:first-child:before,#bootstrap-theme .table-nested>.table>tbody>tr>th:first-child:before,#bootstrap-theme .table-nested>.table>thead>tr>td:first-child:before,#bootstrap-theme .table-nested>.table>thead>tr>th:first-child:before{background:#c2cfd8;content:'';display:block;height:110%;left:0;position:absolute;top:0;width:10px;z-index:2}#bootstrap-theme .table-nested>table>tbody>tr>td:last-child,#bootstrap-theme .table-nested>table>tbody>tr>th:last-child,#bootstrap-theme .table-nested>table>thead>tr>td:last-child,#bootstrap-theme .table-nested>table>thead>tr>th:last-child,#bootstrap-theme .table-nested>.table>tbody>tr>td:last-child,#bootstrap-theme .table-nested>.table>tbody>tr>th:last-child,#bootstrap-theme .table-nested>.table>thead>tr>td:last-child,#bootstrap-theme .table-nested>.table>thead>tr>th:last-child{padding-right:30px;position:relative}#bootstrap-theme .table-nested>table>tbody>tr>td:last-child:after,#bootstrap-theme .table-nested>table>tbody>tr>th:last-child:after,#bootstrap-theme .table-nested>table>thead>tr>td:last-child:after,#bootstrap-theme .table-nested>table>thead>tr>th:last-child:after,#bootstrap-theme .table-nested>.table>tbody>tr>td:last-child:after,#bootstrap-theme .table-nested>.table>tbody>tr>th:last-child:after,#bootstrap-theme .table-nested>.table>thead>tr>td:last-child:after,#bootstrap-theme .table-nested>.table>thead>tr>th:last-child:after{background:#c2cfd8;content:'';display:block;height:110%;right:0;position:absolute;top:0;width:10px;z-index:2}@media screen and (max-width: 767px){#bootstrap-theme .table-nested.table-responsive{border:0;margin-bottom:0}}#bootstrap-theme .table-nested-cell{padding:0 !important}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(1){width:40%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(2){width:15%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(3){width:35%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(4){width:10%}#bootstrap-theme .chr_absence-work-pattern__work-pattern-listing{display:inline-block}#bootstrap-theme .chr_absence-work-pattern__alert{margin-bottom:0 !important}#bootstrap-theme .annual-entitlement-change-log-component thead td{min-width:100px}#bootstrap-theme .annual-entitlement-change-log-component thead .annual-entitlement-change-log-component__comments{min-width:300px}#bootstrap-theme .chr_annual-entitlements__period{width:130px}#bootstrap-theme .chr_annual-entitlements__edit-entitlements{width:150px}#bootstrap-theme .chr_contract-entitlements__position{width:140px}@media (max-width: 992px){#bootstrap-theme .chr_leave-balance-tab .chr_leave-balance-tab__filter:not(:last-child){padding-bottom:15px}}#bootstrap-theme .chr_leave-balance-tab__body{padding:0}@media (min-width: 1200px){#bootstrap-theme .chr_leave-calendar__dates-container .chr_leave-calendar{table-layout:fixed}}#bootstrap-theme .chr_leave-calendar__names-container .chr_leave-calendar{table-layout:fixed}#bootstrap-theme .chr_leave-calendar__day{font-size:10px !important;line-height:1.4em !important;padding:10px !important;text-align:center !important}@media (min-width: 1200px){#bootstrap-theme .chr_leave-calendar__day{padding:10px 0 !important}}#bootstrap-theme .chr_leave-calendar__day--disabled{opacity:0.5}#bootstrap-theme .chr_leave-calendar__day--current{color:#0071bd !important}#bootstrap-theme .chr_leave-calendar__item{color:#FFF;display:block;font-size:10px;height:100%;position:relative;text-align:center;text-transform:uppercase;width:100%}#bootstrap-theme .chr_leave-calendar__item>span{bottom:0;left:0;margin:auto;position:absolute;right:0;top:0;height:1.2em}#bootstrap-theme .chr_leave-calendar__item>.chr_leave-calendar__time-unit{font-size:7px;height:1em;margin-left:-1px}#bootstrap-theme .chr_leave-calendar__item>a{cursor:pointer;bottom:0;left:0;margin:auto;position:absolute;right:0;top:0}#bootstrap-theme .chr_leave-calendar__item--disabled{cursor:not-allowed;opacity:0.5}#bootstrap-theme .chr_leave-calendar__item--type--late{background-color:#eca67e;border-color:#eca67e}#bootstrap-theme .chr_leave-calendar__item--type--non-working{background-color:#41afcb !important;border-color:#41afcb}#bootstrap-theme .chr_leave-calendar__item--type--public-holiday{background-color:#8ec68a !important;border-color:#8ec68a}#bootstrap-theme .chr_leave-calendar__item--type--weekend{background-color:#c7cbd0 !important;border-color:#c7cbd0}#bootstrap-theme .chr_leave-calendar__item--alt{background:#FFF !important;border:1px solid transparent;color:#464354}#bootstrap-theme .chr_leave-calendar__item--requested:before{background:#c7cbd0;content:'';display:block;height:.5em;position:absolute;width:100%;top:0}#bootstrap-theme .chr_leave-calendar__item--toil-requested:before{background:red;content:'';display:block;height:.5em;left:-1px;position:absolute;width:calc(100% + 2px);top:-1px}#bootstrap-theme .chr_leave-calendar__items>td{overflow:hidden;height:35px;padding:0 !important}#bootstrap-theme .chr_leave-calendar__items leave-calendar-day{display:block;height:100%}#bootstrap-theme .chr_leave-calendar__legend__title{font-size:12px}#bootstrap-theme .chr_leave-calendar__legend>.row:not(:first-child){margin-top:20px}#bootstrap-theme .chr_leave-calendar__legend .chr_leave-calendar__legend__entry{margin-top:10px}@media (min-width: 768px){#bootstrap-theme .chr_leave-calendar__legend .chr_leave-calendar__legend__entry{margin-top:0}}#bootstrap-theme .chr_leave-calendar__legend__entry{overflow:auto}#bootstrap-theme .chr_leave-calendar__legend__entry+#bootstrap-theme .chr_leave-calendar__legend__entry{margin-top:10px}#bootstrap-theme .chr_leave-calendar__legend__entry>.chr_leave-calendar__item{font-size:8px;height:20px;margin-right:10px;position:absolute;width:20px}#bootstrap-theme .chr_leave-calendar__legend__label{display:inline-block;font-size:12px;margin-left:26px}#bootstrap-theme .chr_leave-calendar__month-header{background:#f3f6f7}#bootstrap-theme .chr_leave-calendar__month-header .panel-title{font-size:16px}#bootstrap-theme td.chr_leave-calendar__name,#bootstrap-theme th.chr_leave-calendar__name{font-size:12px !important;line-height:100%;padding:0 20px !important;text-align:left;text-overflow:ellipsis;width:100%}#bootstrap-theme th.chr_leave-calendar__name,#bootstrap-theme th.chr_leave-calendar__day{height:49px}#bootstrap-theme th.chr_leave-calendar__name{padding-bottom:10px !important}#bootstrap-theme td.chr_leave-calendar__name{vertical-align:middle !important}#bootstrap-theme .chr_leave-calendar__pagination{font-size:10px;text-align:center}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"]{outline:none;padding:0;line-height:1em}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"] .fa{color:#555}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"][disabled] .fa{opacity:0.5}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"]:hover:not([disabled]) .fa{color:#464354}#bootstrap-theme .chr_leave-calendar__pagination-next{border-top:none}#bootstrap-theme .chr_leave-calendar__pagination-next th{height:24px;padding:4px 0 6px !important}#bootstrap-theme .chr_leave-calendar__pagination-next .chr_leave-calendar__pagination{padding-right:3px !important}#bootstrap-theme .chr_leave-calendar__month-container{margin:0}#bootstrap-theme .chr_leave-calendar__month-container>div{padding:0}#bootstrap-theme .chr_leave-calendar__dates-container{overflow-x:auto}#bootstrap-theme .chr_leave-calendar__admin-filters-hint{display:inline-block;font-size:20px;vertical-align:middle}#bootstrap-theme .chr_leave-calendar__admin-filters-select{width:calc(100% - 50px);display:inline-block;margin-right:20px}#bootstrap-theme .chr_leave-report .dropdown-toggle{color:#464354;padding:0 10px}#bootstrap-theme .chr_leave-report .dropdown-toggle:hover{background:#e6e6e6}#bootstrap-theme .chr_leave-report table{table-layout:fixed}#bootstrap-theme .chr_leave-report table thead th,#bootstrap-theme .chr_leave-report table tbody td{padding:8px 5px}#bootstrap-theme .chr_leave-report__label{color:#464354;font-weight:700}#bootstrap-theme .chr_leave-report__label>.fa{margin-right:5px}#bootstrap-theme .chr_leave-report__label--toggle{cursor:pointer;user-select:none}#bootstrap-theme .chr_leave-report__heading{background-color:#f3f6f7;border-bottom:1px solid #dadcde}#bootstrap-theme .chr_leave-report__heading .chr_leave-report__export-button{line-height:2.4}#bootstrap-theme .chr_leave-report__table table,#bootstrap-theme .chr_leave-report__table .table{border-collapse:separate}#bootstrap-theme .chr_leave-report__table table>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>tbody>tr:first-child>td{border-top-width:0}#bootstrap-theme .chr_leave-report__table table>thead+tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>thead+tbody>tr:first-child>td{border-top-width:1px}#bootstrap-theme .chr_leave-report__table table:not(.table-bordered):not(.table-condensed)>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table:not(.table-bordered):not(.table-condensed)>tbody>tr:first-child>td{border-color:#f3f6f7}#bootstrap-theme .chr_leave-report__table table>thead>tr>th,#bootstrap-theme .chr_leave-report__table .table>thead>tr>th{background:#f3f6f7;border-bottom:0;color:#464354;text-transform:capitalize}#bootstrap-theme .chr_leave-report__table table>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>tbody>tr:first-child>td{border-color:#e8eef0 !important}#bootstrap-theme .chr_leave-report__table table>tfoot>tr,#bootstrap-theme .chr_leave-report__table .table>tfoot>tr{background:#f3f6f7}#bootstrap-theme .chr_leave-report__table>table>thead>tr>th,#bootstrap-theme .chr_leave-report__table>.table>thead>tr>th{padding-bottom:13px;padding-top:13px}#bootstrap-theme .chr_leave-report__table-container{overflow:auto}#bootstrap-theme .chr_leave-report__table-container .panel{display:inline-block;min-width:100%}#bootstrap-theme .chr_leave-report__table__heading--action{width:45px}#bootstrap-theme .chr_leave-report__table__heading--label{width:280px}#bootstrap-theme .chr_leave-report__table__heading--dates{width:170px}#bootstrap-theme .chr_leave-report__table__heading--status{width:180px}#bootstrap-theme .chr_leave-report__table__heading--type{width:65px;word-break:break-word}#bootstrap-theme .chr_leave-request-comment{margin-top:10px}#bootstrap-theme .chr_leave-request-comment__text{border-bottom:1px solid #e8eef0;color:#c2cfd8;margin-right:10px;padding-bottom:20px}#bootstrap-theme .chr_leave-request-files_list{height:150px;overflow-y:auto;margin-top:20px;margin-bottom:20px}#bootstrap-theme .chr_leave-request-files_meta{margin-bottom:10px}#bootstrap-theme .chr_leave-request-files_upload{border:dashed 1px #464354;padding:20px}#bootstrap-theme .chr_leave-request-files_upload_action{padding:5px}#bootstrap-theme .chr_leave-request-files_file-name{display:inline-block;max-width:240px;overflow:hidden;text-overflow:ellipsis;vertical-align:bottom}#bootstrap-theme .chr_leave-request-files_delete{margin-top:-7px}#bootstrap-theme .chr_leave-request-modal .modal-title{font-size:18px !important}#bootstrap-theme .chr_leave-request-modal .table-responsive{border:0}#bootstrap-theme .chr_leave-request-modal .chr_leave-request-date-picker-container .input-group{width:100%}@media screen and (max-width: 767px){#bootstrap-theme .chr_leave-request-modal .chr_leave-request-date-picker-container{margin-bottom:10px}}#bootstrap-theme .chr_leave-request-modal__chevron{font-size:0.6em;margin-right:5px;vertical-align:middle}#bootstrap-theme .chr_leave-request-modal__comments{height:230px;margin-bottom:20px;overflow:auto}#bootstrap-theme .chr_leave-request-modal__comments_empty{margin-bottom:20px}#bootstrap-theme .chr_leave-request-modal__footer{margin:0}#bootstrap-theme .chr_leave-request-modal__delete{margin-left:15px;margin-top:8px}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container{margin-bottom:20px}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container ul{opacity:1 !important}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container:not(.ui-select-multiple) input{width:100% !important}#bootstrap-theme .chr_leave-request-modal__form-group,#bootstrap-theme .chr_leave-request-modal__required-documents>div{margin-bottom:15px}#bootstrap-theme .chr_leave-request-modal__response{padding:20px 20px 0}#bootstrap-theme .chr_leave-request-modal__response label{font-size:17px;margin-top:-3px}#bootstrap-theme .chr_leave-request-modal__response .chr_wysiwyg{margin-top:15px}#bootstrap-theme .chr_leave-request-modal__required-documents input{margin-right:5px}#bootstrap-theme .chr_leave-request-modal__small_spinner>div.chr_spinner{margin-top:18px;min-height:initial}#bootstrap-theme .chr_leave-request-modal__tab input[uib-datepicker-popup]{font-size:13px}#bootstrap-theme .chr_leave-request-modal__table{border:1px solid #f3f6f7;margin-bottom:15px !important}#bootstrap-theme .chr_leave-request-modal__user-info{font-size:17px;padding:20px}#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(1){color:#464354}#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(2){color:#555}@media screen and (min-width: 480px){#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(2){border-left:1px solid #e8eef0}}#bootstrap-theme .chr_leave-request-modal__span-expiry{display:inline-block;margin-top:7px}#bootstrap-theme .chr_leave-request-modal__expiry-clear{position:absolute;right:3.5em;top:0.6em;z-index:2}#bootstrap-theme .chr_leave-request-modal__small-text{font-size:80%}#bootstrap-theme .chr_leave-request-modal__custom-deduction-toggling-row{margin-top:-5px}@media screen and (min-width: 768px){#bootstrap-theme .chr_leave-request-modal__custom-deduction-label{text-align:right}}@media screen and (max-width: 767px){#bootstrap-theme .chr_leave-request-modal__custom-deduction-label{margin-bottom:10px}}#bootstrap-theme .chr_leave-request-modal .form-group{overflow:inherit !important}#bootstrap-theme .chr_leave-request-modal .alert{margin-bottom:0 !important}#bootstrap-theme .chr_leave-request-modal input[uib-datepicker-popup]{box-shadow:none !important;background-color:inherit !important;color:inherit !important;cursor:pointer !important;border-right:none}#bootstrap-theme leave-request-record-actions{display:block;margin-bottom:20px}#bootstrap-theme leave-request-record-actions .fa,#bootstrap-theme leave-request-record-actions .btn-group{margin-right:8px}#bootstrap-theme leave-request-record-actions .btn-toolbar{margin-left:0;overflow:inherit}#bootstrap-theme leave-request-record-actions .btn-toolbar .btn-group,#bootstrap-theme leave-request-record-actions .btn-toolbar .btn{margin-left:0}@media screen and (max-width: 767px){#bootstrap-theme leave-request-record-actions .btn-group,#bootstrap-theme leave-request-record-actions .btn{display:block;width:100%}#bootstrap-theme leave-request-record-actions .btn-group{margin-bottom:8px;margin-right:0}}#bootstrap-theme .leave-widget h4{color:#4d4d69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px}#bootstrap-theme .leave-widget__types>table,#bootstrap-theme .leave-widget__sickness>table,#bootstrap-theme .leave-widget__next-leave>table{border:none}#bootstrap-theme .leave-widget__types>table thead tr th,#bootstrap-theme .leave-widget__sickness>table thead tr th,#bootstrap-theme .leave-widget__next-leave>table thead tr th{color:#4d4d69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px;background:none;width:35%}#bootstrap-theme .leave-widget__types>table thead tr th:first-child,#bootstrap-theme .leave-widget__sickness>table thead tr th:first-child,#bootstrap-theme .leave-widget__next-leave>table thead tr th:first-child{width:65%}#bootstrap-theme .leave-widget__types>table tbody tr td,#bootstrap-theme .leave-widget__sickness>table tbody tr td,#bootstrap-theme .leave-widget__next-leave>table tbody tr td{color:#0071bd;font-size:16px;font-weight:600;padding-bottom:9px}#bootstrap-theme .leave-widget__types>table tbody tr td:first-child,#bootstrap-theme .leave-widget__sickness>table tbody tr td:first-child,#bootstrap-theme .leave-widget__next-leave>table tbody tr td:first-child{color:#464354}#bootstrap-theme .leave-widget hr{border-color:#DEE4ED;margin-bottom:25px;margin-top:25px}#bootstrap-theme .leave-widget__sickness h4{margin-top:18px}#bootstrap-theme .leave-widget__next-leave h3{font-size:16px;margin-bottom:16px;margin-top:0}#bootstrap-theme .leave-widget__next-leave__deduction{font-size:16px;font-weight:600;color:#464354}#bootstrap-theme .chr_leave__page-selector-dropdown{margin-right:5px;position:relative;top:1px;width:100%}#bootstrap-theme .chr_leave__page-selector-dropdown select{height:40px}#bootstrap-theme .chr_leave__page-selector-dropdown .crm_custom-select__arrow{line-height:40px;width:40px}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;border-bottom:1px solid #dadcde;margin:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header .panel-title{margin-top:7px;display:inline-block}@media screen and (max-width: 992px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header>div:not(:last-child),#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header .panel-title{padding-bottom:20px}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter{display:inline-block;margin-top:7px;white-space:nowrap}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter .fa{font-size:0.6em;margin-right:5px;margin-top:-2px;vertical-align:middle}@media screen and (max-width: 991px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter{margin-top:15px}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;border-bottom:1px solid #dadcde;margin:0;padding-top:15px}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>*{padding-left:10px !important;padding-right:10px !important}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>div:not(:last-child){padding-bottom:20px}}@media screen and (min-width: 992px) and (max-width: 1199px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>.no_gutter{padding-bottom:0 !important}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body{margin:0;padding:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body [class^="col-"],#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body [class*=" col-"]{padding:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body a{cursor:pointer}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container{padding-left:10px;padding-right:10px;background-color:#f7f7f9}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container>div{padding-left:15px;padding-right:15px}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .form-group{overflow:inherit !important}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .panel{background-image:none !important}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .panel-body,#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .chr_vertical_tabs{background-color:#f7f7f9}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] input[type="search"]{width:100% !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header .checkbox{margin-top:5px}#bootstrap-theme .page-manager-leave .chr_manage_leave_requests .btn-sm{font-size:100% !important}#bootstrap-theme .chr_manager_calendar__header{padding-left:10px;padding-right:10px;padding-top:15px;margin:0;background-color:#f7f7f9;border-bottom:1px solid #dadcde}#bootstrap-theme .chr_manager_calendar__header>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manager_calendar__header .checkbox{margin:0}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manager_calendar__header>div:not(:last-child){padding-bottom:20px}}#bootstrap-theme .chr_manager_calendar__sub-header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;margin:0}#bootstrap-theme .chr_manager_calendar__sub-header>*{padding-left:10px !important;padding-right:10px !important}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manager_calendar__sub-header>div:not(:last-child){padding-bottom:20px}#bootstrap-theme .chr_manager_calendar__sub-header .ui-select-container{height:auto}}#bootstrap-theme .time-amount-picker .crm_custom-select{display:inline-block;margin-right:2px}#bootstrap-theme .time-amount-picker .crm_custom-select:nth-child(2){margin-left:10px}#bootstrap-theme .absence-tab-page .tab-pane{padding:0 !important}#bootstrap-theme .absence-tab-page .tab-content{background-color:transparent !important}#bootstrap-theme .absence-tab-page leave-request-record-actions{margin-bottom:20px}#bootstrap-theme .crm-absence_type-form-block .crm-section .label{width:35%}#bootstrap-theme .crm-absence_type-form-block .crm-section .content{margin-left:40%}#bootstrap-theme .crm-absence_type-form-block .toil-option,#bootstrap-theme .crm-absence_type-form-block .carry-forward-option,#bootstrap-theme .crm-absence_type-form-block .toil-expiration,#bootstrap-theme .crm-absence_type-form-block .carry-forward-expiration-duration,#bootstrap-theme .crm-absence_type-form-block .carry-forward-expiration-date{display:none}#bootstrap-theme .crm-absence_type-form-block .sp-replacer{padding:2px}#bootstrap-theme .crm-absence_type-form-block .sp-preview{height:15px;width:15px}#bootstrap-theme .crm-absence_type-form-block .sp-dd{height:0;line-height:15px;font-size:9px}.page-civicrm-leaveandabsences-dashboard .page-title,.page-civicrm-leaveandabsences-dashboard #branding{display:none !important}.page-civicrm-leaveandabsences-dashboard #page{margin:0;padding:0}.admin-dashboard-page{position:relative}.admin-dashboard-page .crm_page__topbar{height:65px}.admin-dashboard-page leave-request-record-actions{margin:12px 30px 0 0}.admin-dashboard-page .chr_admin-dashboard_side-nav{background-color:#fff;height:calc(100% - 12px);overflow:hidden;position:absolute;width:170px}.admin-dashboard-page .chr_admin-dashboard_side-nav .active{background:#e8eef0}.admin-dashboard-page .chr_admin-dashboard_content{float:right;margin:16px;margin-bottom:0;width:calc(100% - 170px - 16px * 2)}#bootstrap-theme #calculation-details{background:#fff}#bootstrap-theme #calculation-details .base-contractual-entitlement{color:#0071bd}#bootstrap-theme #calculation-details .working-days-to-work{color:#44cb7e}#bootstrap-theme #calculation-details .working-days-in-period{color:#e6ab5e}#bootstrap-theme #calculation-details .contract-1-pro-rata{color:#E6807F}#bootstrap-theme #calculation-details .contract-2-pro-rata{color:#797300}#bootstrap-theme #calculation-details .contract-3-pro-rata{color:#904E1E}#bootstrap-theme #calculation-details .contract-4-pro-rata{color:#0511B1}#bootstrap-theme #calculation-details .contract-5-pro-rata{color:#4B9609}#bootstrap-theme #calculation-details .calculation-pro-rata{color:#95c0ff}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body{padding-top:20px;padding-bottom:20px}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body .row:first-child h3{margin-top:0}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body h3{margin-bottom:20px}#bootstrap-theme .crm-leave-and-absences-form-block .panel-footer .crm-button:last-child{margin-right:0}#bootstrap-theme.crm-leave-and-balance-import .panel{background-color:#fff}#bootstrap-theme.crm-leave-and-balance-import .panel-header{position:relative}#bootstrap-theme.crm-leave-and-balance-import .panel-header h2{padding:10px 20px}#bootstrap-theme.crm-leave-and-balance-import .panel-body .row:not(:last-child){padding-bottom:2em}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats .label{display:none}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats label{font-weight:normal !important}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats td{border:0;padding:0}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block{box-shadow:none;padding:0}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table{margin-bottom:2em;width:100%}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table th{padding:10px 20px;border-right:none}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table th,#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table td{padding:5px}#bootstrap-theme.crm-leave-and-balance-import #preview-counts,#bootstrap-theme.crm-leave-and-balance-import #summary-counts{box-shadow:none;margin-bottom:2em;width:100%}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td{background-color:#f2dede !important;color:#cf3458}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td a,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td a{color:#bd2d4e;font-weight:bold}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td a:hover,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td a:hover{color:#0062a4}#bootstrap-theme.manage-entitlements-form .wider-hr{margin-left:-20px;margin-right:-20px;border-width:2px}#bootstrap-theme.manage-entitlements-form .wider-row{margin-left:-20px;margin-right:-20px}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters{padding:15px 0;text-align:center}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .override-filters label{display:inline-block}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .override-filters label:before{display:none}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .absence-type-filter{margin-right:10px}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .col-sm-4:last-child{text-align:right}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list{margin-bottom:0}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement-header .title{float:left;width:65%}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement-header .actions{float:right}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list tr.hidden{display:none}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .absence-type{color:#fff;display:inline-block;padding:5px}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement .overridden-proposed-entitlement,#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement .calculation-unit{display:none}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .borderless-button{background-color:transparent;border:0;cursor:pointer}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .add-comment{font-size:1.1em}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .comment-text{display:none}#bootstrap-theme.manage-entitlements-form .manage-entitlements-form__filters{padding-bottom:1em}#bootstrap-theme.manage-entitlements-form .table{background:#f9f9f9;border-top:1px solid #e8eef0;border-bottom:1px solid #e8eef0;margin-bottom:2em}#bootstrap-theme.manage-entitlements-form .table th{background:#f3f6f7 !important}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header{border-left:1px solid #e8eef0;border-right:1px solid #e8eef0;background:#e4ebed !important;min-width:200px}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .row>div{display:table-cell;float:none;vertical-align:bottom}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .fa{color:#4d4d69}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .action-button-container{padding:0}#bootstrap-theme.manage-entitlements-form .table td.proposed-entitlement{border-left:1px solid #e8eef0;border-right:1px solid #e8eef0;background:white}#bootstrap-theme.manage-entitlements-form .table span.absence-type{border-radius:3px;padding:0 5px}#bootstrap-theme.manage-entitlements-form .table tbody .fa{color:#0071bd}#bootstrap-theme.manage-entitlements-form .crm-container .CRM_HRLeaveAndAbsences_Form_ManageEntitlements .crm-button-type-next{float:right !important}#bootstrap-theme.manage-entitlements-form .panel-footer{border-top:none}#add-comment-dialog{display:none}#add-comment-dialog .calculation_comment{box-sizing:border-box;padding:10px;width:100%}#bootstrap-theme .crm-work-pattern-form-block .ui-tabs.ui-widget-content{background:none}#bootstrap-theme .work-pattern-calendar .number-of-weeks{padding:15px 0 15px 0}#bootstrap-theme .work-pattern-calendar .work-pattern-week{border-top:1px solid rgba(0,0,0,0.2);padding:15px 0 15px 0;margin-bottom:15px}#bootstrap-theme .work-pattern-calendar .work-pattern-week.hidden-week{display:none}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-number{float:left;font-weight:bold;padding:5px 0 15px 5px}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days{table-layout:fixed}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-hours{float:right;padding:5px 5px 15px 0}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-hours .number-of-hours{font-weight:bold}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days td{padding:5px 10px 5px 10px}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days input{min-width:0;text-align:center}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days select{min-width:0;width:100% !important}#bootstrap-theme .work-pattern-calendar .work-pattern-week .hours-row td{padding-top:15px;padding-bottom:15px;border-top:1px solid rgba(0,0,0,0.2);border-bottom:1px solid rgba(0,0,0,0.2)}.caret{display:inline-block;width:0;height:0;margin-left:2px;vertical-align:middle;border-top:4px dashed;border-top:4px solid \9;border-right:4px solid transparent;border-left:4px solid transparent}.dropup,.dropdown{position:relative}.dropdown-toggle:focus{outline:0}.dropdown-menu{position:absolute;top:100%;left:0;z-index:1000;display:none;float:left;min-width:160px;padding:5px 0;margin:2px 0 0;list-style:none;font-size:13px;text-align:left;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.15);border-radius:2px;-webkit-box-shadow:0 6px 12px rgba(0,0,0,0.175);box-shadow:0 6px 12px rgba(0,0,0,0.175);background-clip:padding-box}.dropdown-menu.pull-right{right:0;left:auto}.dropdown-menu .divider{height:1px;margin:9px 0;overflow:hidden;background-color:#e5e5e5}.dropdown-menu>li>a{display:block;padding:3px 20px;clear:both;font-weight:normal;line-height:1.5384615385;color:#4d4d69;white-space:nowrap}.dropdown-menu>li>a:hover,.dropdown-menu>li>a:focus{text-decoration:none;color:#42425a;background-color:#f3f6f7}.dropdown-menu>.active>a,.dropdown-menu>.active>a:hover,.dropdown-menu>.active>a:focus{color:#fff;text-decoration:none;outline:0;background-color:#0071bd}.dropdown-menu>.disabled>a,.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{color:#e8eef0}.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{text-decoration:none;background-color:transparent;background-image:none;filter:progid:DXImageTransform.Microsoft.gradient(enabled = false);cursor:not-allowed}.open>.dropdown-menu{display:block}.open>a{outline:0}.dropdown-menu-right{left:auto;right:0}.dropdown-menu-left{left:0;right:auto}.dropdown-header{display:block;padding:3px 20px;font-size:12px;line-height:1.5384615385;color:#464354;white-space:nowrap}.dropdown-backdrop{position:fixed;left:0;right:0;bottom:0;top:0;z-index:990}.pull-right>.dropdown-menu{right:0;left:auto}.dropup .caret,.navbar-fixed-bottom .dropdown .caret{border-top:0;border-bottom:4px dashed;border-bottom:4px solid \9;content:""}.dropup .dropdown-menu,.navbar-fixed-bottom .dropdown .dropdown-menu{top:auto;bottom:100%;margin-bottom:2px}@media (min-width: 768px){.navbar-right .dropdown-menu{right:0;left:auto}.navbar-right .dropdown-menu-left{left:0;right:auto}}.dropdown-header{padding:11px 20px}.dropdown-menu{-webkit-box-shadow:0 3px 18px 0 rgba(48,40,40,0.25);box-shadow:0 3px 18px 0 rgba(48,40,40,0.25);border:0;margin:0;padding:0}.dropdown-menu>li{border:0;margin:0;padding:0}.dropdown-menu>li>a{padding:11px 20px} diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js index 319ab39ee97..d8af6d230a1 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js @@ -1,5 +1,5 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,o){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,r){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),r=e.assign({},r,{absence_type_id:a,date:t(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",r).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,o,s,r){return t.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return s.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,o,s,r){return this.sendPOST("ContactWorkPattern","create",e.assign({},r,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,o,s){return t.debug("WorkPatternAPI.getCalendar",n,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,o){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,o,s,r){function i(t,n){return u().then(function(a){var o=this.days[c(t).valueOf()];return!!o&&e.find(a,function(e){return e.name===n}).value===o.type}.bind(this))}function c(e){return t(e,s.serverDateFormat).clone()}function u(){return l=l||r.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[c(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,o){return t.debug("Calendar"),n.extend({get:function(n,s,r,i){return t.debug("Calendar.get"),a.getCalendar(n,s,r,i).then(function(t){var a=t.values.map(function(e){return o.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function o(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,o,s){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return o.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,o,s,r){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,o,s,"getFull",r)),i.promise},balanceChangeByAbsenceType:function(t,n,o,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var r=a.defer();t&&n||r.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:o?{IN:o}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){r.resolve(e.values)}),r.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?o.reject(t(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,o,s,r,i,c){function u(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),r=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(r.date)]).then(function(t){return s.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,o&&(r.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return r.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(s.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,o,s,r){return n.all(this.processFilters(e),t,o,s,r).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,o){return n.balanceChangeByAbsenceType(e,t,a,o)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/instances/work-pattern.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("WorkPatternInstance",["$log","ModelInstance",function(e,t){return e.debug("WorkPatternInstance"),t.extend({})}])}),define("leave-absences/shared/models/work-pattern.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/work-pattern.instance"],function(e,t){"use strict";t.factory("WorkPattern",["$log","Model","WorkPatternAPI","WorkPatternInstance",function(t,n,a,o){return t.debug("WorkPattern"),n.extend({assignWorkPattern:function(e,t,n,o,s,r){return a.assignWorkPattern(e,t,n,o,s,r)},default:function(){return a.get({is_default:!0}).then(function(t){return o.init(e.first(t),!0)})},unassignWorkPattern:function(e){return a.unassignWorkPattern(e)},workPatternsOf:function(e,t,n){return a.workPatternsOf(e,t,n).then(function(e){return e.map(function(e){return o.init(e,!0)})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,o,s,r,i){function c(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function u(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?c():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return o.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):r.all()}function m(e){return"me"===e?o.leaveManagees(v.contactId):"unassigned"===e?o.leaveManagees(void 0,{unassigned:!0}):o.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

","

People I approve filter displays only staff members who you approve leave for.

","

People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

"].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,u()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:r.contactId}).leaveManagees().then(function(e){r.lookupContacts=e}).then(o)}}}function o(){return t.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:r.filters.userSettings.department?r.filters.userSettings.department.value:null,level_type:r.filters.userSettings.level_type?r.filters.userSettings.level_type.value:null,location:r.filters.userSettings.location?r.filters.userSettings.location.value:null,region:r.filters.userSettings.region?r.filters.userSettings.region.value:null,id:{IN:r.filters.userSettings.contact?[r.filters.userSettings.contact.id]:r.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var r;return{init:function(e){return r=e,r.showContactName=!0,r.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function o(a,o,s,r,i,c,u,l,d,m){function f(){for(var e=[],t=n(O.selectedPeriod.start_date).clone().startOf("month"),a=n(O.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(A(t)),t.add(1,"month");O.months=e}function p(){r.$new().$watch(function(){return O.selectedMonths},function(t,n){null===n||e.equals(t,n)||w()})}function h(e){O.injectMonths=!0,L("injected").then(function(){w(e)}).then(function(){O.loading.calendar=!1})}function v(){S=a("LeaveCalendar"+t.capitalize(M)+"Controller").init(O)}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function g(){return c.all().then(function(e){O.absencePeriods=t.sortBy(e,"start_date"),O.selectedPeriod=t.find(O.absencePeriods,function(e){return!!e.current})}).then(f).then(I)}function _(){return u.all().then(u.loadCalculationUnits)}function y(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return S.loadContacts().then(function(e){O.contacts=e})}function C(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){O.filters.optionValues.regions=e.hrjc_region,O.filters.optionValues.locations=e.hrjc_location,O.filters.optionValues.levelTypes=e.hrjc_level_type,O.filters.optionValues.departments=e.hrjc_department})}function P(){return l.all()}function D(){return o.all([_(),P(),y()]).then(function(e){O.supportData.absenceTypes=e[0],O.supportData.publicHolidays=e[1],O.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,O.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,O.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,O.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function R(){var e=o.resolve();return O.injectMonths&&(e=L("destroyed"),O.injectMonths=!1),e}function A(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function T(e){e=t.includes(["contacts","period"],e)?e:"period",o.resolve().then(function(){O.loading.calendar=!0}).then(R).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function w(e){var n=O.selectedMonths.length?O.months.filter(function(e){return t.includes(O.selectedMonths,e.index)}):O.months;r.$emit("LeaveCalendar::showMonths",n,!!e)}function I(){O.selectedMonths=[n().month()]}function k(){return O.roleOverride?o.resolve().then(function(){M=O.roleOverride}):o.all([m(i.permissions.admin.administer),m(i.permissions.ssp.manage)]).then(function(e){M=e[0]?"admin":e[1]?"manager":"staff"})}function L(e){return o(function(n){var a=0,o=r.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===O.months.length&&(o(),n())})})}s.debug("Component: leave-calendar");var S,M,O=this;O.absencePeriods=[],O.contacts=[],O.contactIdsToReduceTo=null,O.injectMonths=!1,O.months=[],O.selectedMonths=null,O.selectedPeriod=null,O.showContactName=!1,O.showFilters=!1,O.supportData={},O.loading={calendar:!0,page:!0},O.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},O.labelPeriod=b,O.refresh=T,function(){k().then(p).then(v).then(R).then(g).then(function(){return o.all([q(),D()])}).then(function(){return O.showFilters?C():t.noop}).then(function(){h()}).then(function(){O.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",o]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,o){"use strict";function s(){y.calculationUnit=r(y.supportData.calculationUnits,"value",b.calculation_unit)}function r(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(y.contactData.leaveRequest.from_date).isSame(y.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+y.calculationUnit.name+"-on-"+e+"-tooltip"}function c(){b=r(y.supportData.absenceTypes,"id",y.contactData.leaveRequest.type_id),y.contactData.leaveRequest["type_id.title"]=b.title}function u(){"days"===y.calculationUnit.name&&(g=r(y.supportData.dayTypes,"value",y.contactData.leaveRequest.from_date_type),_=r(y.supportData.dayTypes,"value",y.contactData.leaveRequest.to_date_type),y.contactData.leaveRequest["from_date_type.label"]=g.label,y.contactData.leaveRequest["to_date_type.label"]=_.label)}function l(e,t,n,a,s){e.stopPropagation(),o.openModal(t,n,a,s)}function d(){y.dates.from=new Date(y.contactData.leaveRequest.from_date),y.dates.to=new Date(y.contactData.leaveRequest.to_date)}function m(){y.contactData.isAccruedTOIL?y.label="AT":"days"===y.calculationUnit.name?f():p()}function f(){y.label=y.contactData.isAM?"AM":y.contactData.isPM?"PM":""}function p(){var e=t(y.contactData.leaveRequest.from_date).isSame(y.date,"day"),n=t(y.contactData.leaveRequest.to_date).isSame(y.date,"day");y.label=e?t(y.contactData.leaveRequest.from_date).format("HH:mm"):n?t(y.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){y.tooltipTemplate=y.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){y.contactData&&y.contactData.leaveRequest&&(c(),s(),u(),m(),d(),h()) -})}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,r,i,c){function u(e){_([e]),N(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return U[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){S(e),N(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=R(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){F.push(o.$on("LeaveCalendar::showMonths",x)),F.push(i.subscribe("LeaveRequest::new",u)),F.push(i.subscribe("LeaveRequest::edit",B)),F.push(i.subscribe("LeaveRequest::updatedByManager",B)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function P(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function D(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function R(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function A(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function T(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function w(){return[T(c.statusNames.approved),T(c.statusNames.adminApproved),T(c.statusNames.awaitingApproval),T(c.statusNames.moreInformationRequired)]}function I(){return H.month.loading=!0,a.all([L(),k()]).then(b).then($).then(function(){j=!0}).then(function(){H.month.loading=!1})}function k(){return r.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:w()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function L(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function S(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function M(){o.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function O(t,n,o){var s,r;return t.contactsData[n]=t.contactsData[n]||{},r=m(n),s=!0===o?a.resolve():a.all([r.isWeekend(p(t.date)),r.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:P(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?D(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function $(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return O(e,t.id)}))}))}function x(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!j)&&I())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=A(e);t&&(h(t),-1!==w().indexOf(e.status_id)&&u(e))}function N(e){return a.all(R(e).map(function(t){return O(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var j=!1,F=[],U={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=M,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,r,i,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(r.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=P[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(P,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:P[e].label,isDirectAction:P[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,P={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,r,i,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,r.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l,d,m,f){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function h(e){return t(e,c.serverDateFormat).toDate()}function v(e){return t(e).format(c.serverDateFormat)}function b(e){var t;return r.resolve().then(function(){J(e),"from"===e&&Q(),N("hours")&&(y(e),"from"!==e||pe.uiOptions.multipleDays||y("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return P(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return r.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return G()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(N("hours"))return H(e).then(function(){ne(e,!0)})}).then(function(){if(se(),!t)return V();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(I)}function g(){return se(),V()}function _(){return pe.uiOptions.toDate=null,J("to"),r.resolve().then(function(){if(N("hours")&&pe.uiOptions.fromDate)return y("from"),!pe.uiOptions.multipleDays&&y("to"),H("from").then(function(){ne("from",!0)}).then(se)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&V)}function y(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&s&&o&&(s=A(s).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=A(o).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function C(t,n){return t?(t=v(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):D(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):r.reject([])}function P(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function D(e,n){return e=t(e),r.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function R(){return pe.request?pe.request.request_type:pe.leaveType||null}function A(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(K).catch(I)}function w(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function I(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function k(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?V():T()}function L(){var e=pe.request.attributes();return pe.uiOptions.fromDate=h(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=h(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function S(e){s.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){N("days")||+e==+t||(re(),pe.performBalanceChangeCalculation())})}function M(){fe.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){ue()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",V))}function O(){pe.isMode("edit")&&(pe.isLeaveStatus(c.statusNames.approved)||pe.isLeaveStatus(c.statusNames.adminApproved))&&(me={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function $(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(w(a.min,n)<=0||w(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function x(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return r.all(e.map(H)).then(function(){["from","to"].forEach(function(e){$(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(re)}function E(){["from","to"].forEach(function(e){S(e),B(e)})}function B(e){s.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){N("days")||t===n||(se(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function N(e){return pe.selectedAbsenceType.calculation_unit_name===e}function j(e){return pe.request.request_type===e}function F(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return C(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function W(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function H(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(v(t)).then(function(t){he[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return he[e]={},I(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):r.resolve()}function G(){return u.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function Y(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function V(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(K).catch(I).finally(function(){pe.loading.balanceChange=!1})):r.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function X(){return v(pe.request.from_date)===v(pe.request.to_date)}function Q(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,J("to"))}function J(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,se(),re(),ie()}function K(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=h(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=h(pe.period.end_date)}function ee(){return!pe.isMode("create")&&X()||pe.isMode("create")&&(j("sickness")||N("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,r.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,i=he[a].number_of_hours?w(s,r).toString():"0";o.maxAmount=i,t&&(o.amount=o.maxAmount)}function ae(){me&&me.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=me.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function oe(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function se(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?v(e.fromDate):null,pe.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),N("hours")&&!j("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function re(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ce(){e.forEach(fe,function(e){e()})}function ue(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return oe(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),r.resolve().then(e&&ee).then(function(){if(e&&N("hours"))return H("from").then(function(){ne("from",!0)})}).then(e&&se).then(V)}function le(e){return pe.absenceTypes=e,oe(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,J("to")),ae(),V()}function de(e){var t=A(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(A(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(A(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var me=null,fe=[],pe=this,he={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=c.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:Y},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=h,pe.convertDateToServerFormat=v,pe.dateChangeHandler=b,pe.dateTypeChangeHandler=g,pe.daysSelectionModeChangeHandler=_,pe.isLeaveType=j,pe.isNotWorkingDay=F,pe.performBalanceChangeCalculation=V,pe.$onDestroy=ce,function(){n("RequestModalDetails"+e.capitalize(R(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",pe),M(),pe.initChildController().then(function(){return r.all([G(),W()])}).then(!pe.isMode("create")&&L).then(ee).then(function(){if(!pe.isMode("create")&&N("hours"))return x().then(se)}).then(!pe.isMode("create")&&Z).then(O).then(ae).then(k).then(function(){pe.isMode("view")||j("toil")||E()}).catch(I).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l){function d(){return k.fileUploader&&k.fileUploader.queue.length>0}function m(){return k.getFilesAmount()0?T.map(function(e){return e.label}).join(", "):""}function q(){return k.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(T.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){I[e.label]=t})})).catch(function(){I=null})}function P(){return c.valuesOf("safe_file_extension").then(function(e){T=e})}function D(e){return!e.attachment_id||k.canManage}function R(){e.forEach(w,function(e){e()})}function A(e,t){k.fileUploader.queue&&k.fileUploader.queue.length>0?k.fileUploader.uploadAll({entityID:k.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var T=[],w=[],I={},k=Object.create(this);return k.filesLoaded=!1,k.fileUploader=null,k.today=Date.now(),k.userDateFormatWithTime=r.DATE_FORMAT+" HH:mm",k.userDateFormat=r.DATE_FORMAT,k.$onDestroy=R,k.canRemoveAttachment=D,k.canSubmit=d,k.canUploadMore=m,k.formatDateTime=f,k.getAuthorName=p,k.getFilesAmount=h,k.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",k),g(),a.all([P(),q()]).then(_).finally(function(){k.filesLoaded=!0})}(),k}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,o){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"},{type:"toil",icon:"calendar-plus-o",label:"Overtime"}],s.openLeavePopup=a,function(){o=n.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{btnClass:"@",contactId:"<",selectedContactId:"<",isSelfRecord:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,o,s,r,i,c,u,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):W.refresh()}function b(t){t.dataIndex=e.indexBy(t.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return r.all().then(r.loadCalculationUnits).then(function(t){W.absenceTypes=t,W.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return T("approved",{status_id:F(m.statusNames.approved)})}function C(){return n.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function P(){return i.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(t){var n=e.find(W.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function D(){return i.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return O(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function R(){return n.all([i.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),A({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:O(e[0]),expiredTOILS:$(e[1].list)})}).then(function(t){W.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function A(t){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function T(e,t){return A(t).then(function(t){W.sections[e].data=t.list})}function w(){return n.all(Object.values(W.sections).filter(function(e){return e.open}).map(S))}function I(){return T("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function k(){return T("pending",{status_id:{ -in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function L(){return T("holidays",{public_holiday:!0})}function S(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function M(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){W.leaveRequestStatuses=e.indexBy(t,"value")})}function O(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(W.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function $(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function x(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(W.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],B(t,a))})}function B(e,t){var n=W.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function N(){W.loading.content=!0,n.all([P(),C()]).then(function(){W.loading.content=!1}).then(function(){return n.all([w(),h()])})}function j(e){var t=W.sections[e];t.open=!t.open,t.open&&!t.data.length&&S(t)}function F(t){return e.find(W.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:D},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:L},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:k},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:I}},W.labelPeriod=g,W.refresh=N,W.toggleSection=j,function(){n.all([M(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return n.all([P(),C()])}).then(function(){W.loading.content=!1}),x()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["leave-absences/shared/modules/controllers"],function(e){function t(e,t,n,a){function o(){return a.request.calculateBalanceChange(a.selectedAbsenceType.calculation_unit_name)}function s(){var e=a.request,t=!!e.from_date&&!!e.to_date,n=a.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function r(){return a.canCalculateChange()}function i(){return n.resolve()}t.debug("RequestModalDetailsLeaveController"),a.calculateBalanceChange=o,a.canCalculateChange=s,a.canSubmit=r,a.initChildController=i}e.controller("RequestModalDetailsLeaveController",t),t.$inject=["$controller","$log","$q","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function r(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function i(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=r,s.initChildController=i,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s,r){function i(){return r.balance.change.amount=+r.request.toil_to_accrue,n.resolve(r.balance.change)}function c(){return f().catch(function(e){return e.length&&(r.errors=e),n.reject(e)}).then(function(e){return s.calculateToilExpiryDate(r.request.type_id,e)}).then(function(e){return r.request.toil_expiry_date=e,r.uiOptions.expiryDate=new Date(e),e})}function u(){return!!r.request.toil_to_accrue}function l(){var e=r.uiOptions.multipleDays&&!!r.request.to_date,t=!r.uiOptions.multipleDays&&!!r.request.from_date,n=t||e,a=D.from_date!==r.request.from_date||D.to_date!==r.request.to_date;return r.canDisplayToilExpirationField&&n&&R.hasExpirationFromAdminSettings&&a}function d(){return!!(r.request.from_date&&r.request.to_date&&r.request.toil_duration&&r.request.toil_to_accrue)}function m(){r.request.toil_expiry_date=!1,r.uiOptions.expiryDate=null}function f(){var e=r.uiOptions.multipleDays,t=r.request;return p({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function p(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return n.reject([t])}return e.value?n.resolve(e.value):n.reject([])}function h(){var e=r.isMode("create")&&R.hasExpirationFromAdminSettings,t=R.hasPreviousExpirationDate,n=r.isLeaveType("toil"),a=r.canManage;r.canDisplayToilExpirationField=n&&(a||e||t)}function v(){return R.hasPreviousExpirationDate=r.isMode("edit")&&!!r.request.toil_expiry_date,s.canExpire(r.request.type_id).then(function(e){R.hasExpirationFromAdminSettings=e})}function b(){return r.request.to_date_type=r.request.from_date_type="1",v().then(h).then(g).then(y)}function g(){r.canManage&&(r.uiOptions.expiryDate=r.convertDateFormatFromServer(r.request.toil_expiry_date))}function _(){r.isMode("view")||a.$watch(function(){return r.request.toil_to_accrue},function(e,t){+e!=+t&&r.performBalanceChangeCalculation()})}function y(){return o.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){r.toilAmounts=e.indexBy(t,"value")})}function q(){D=angular.copy(r.request.attributes())}function C(){return l()?c().catch(n.resolve):n.resolve()}function P(){r.uiOptions.expiryDate&&(r.request.toil_expiry_date=r.convertDateToServerFormat(r.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var D,R={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};r.canDisplayToilExpirationField=!1,r.calculateBalanceChange=i,r.canCalculateChange=u,r.canSubmit=d,r.clearExpiryDate=m,r.initChildController=b,r.onDateChangeExtended=C,r.setDaysSelectionModeExtended=C,r.updateExpiryDate=P,function(){_(),q()}()}t.controller("RequestModalDetailsToilController",n),n.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),r={date:o};return a.all(r).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={toilDurationHours:"0",toilDurationMinutes:"0",request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},transformAttributes:function(e){var t=Number(e.toil_duration);return t&&(e.toilDurationHours=Math.floor(t/60).toString(),e.toilDurationMinutes=(t%60).toString()),e},updateDuration:function(){this.toil_duration=60*Number(this.toilDurationHours)+Number(this.toilDurationMinutes)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files","toilDurationHours","toilDurationMinutes"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,r,i,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,P){function D(e){"days"===$e.selectedAbsenceType.calculation_unit_name?delete $e.request[e+"_date_amount"]:delete $e.request[e+"_date_type"]}function R(){["from","to"].forEach(D)}function A(){var e=$e.requestStatuses[y.statusNames.awaitingApproval].value;Ie.status_id===e&&e!==$e.request.status_id&&d.publish("ManagerBadge:: Update Count")}function T(){return Oe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return Oe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return!$e.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function k(){var e=T();return $e.isMode("edit")&&(e=e&&(G()||w())),$e.canManage&&$e.requestStatuses&&(e=e&&!!$e.getStatusFromValue($e.newStatusOnSave)),(e=e&&!!$e.period.id)&&!$e.isMode("view")}function L(){$e.isSelfRecord?$e.request.status_id=$e.requestStatuses[y.statusNames.awaitingApproval].value:$e.canManage&&($e.request.status_id=$e.newStatusOnSave||$e.request.status_id)}function S(){if($e.isMode("edit")&&!$e.isRole("staff")&&"toil"!==F())return $e.request.calculateBalanceChange($e.selectedAbsenceType.calculation_unit_name).then(function(e){if(+$e.balance.change.amount!=+e.amount)return P.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function M(){$e.errors=[]}function O(){return $e.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function $(){ee()&&!$e.isRole("staff")&&($e.request.change_balance=!0)}function x(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return $e.request.delete().then(function(){$e.dismissModal(),d.publish("LeaveRequest::delete",$e.request)})}})}function E(){i.dismiss({$value:"cancel"})}function B(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function N(){return j($e.getStatusFromValue($e.request.status_id).name)}function j(e){return n.map(Te[e],function(e){return $e.requestStatuses[e]})}function F(){return $e.request?$e.request.request_type:$e.leaveType||null}function U(){return!$e.request||e.equals({},$e.requestStatuses)?[]:$e.request.status_id?N():j("none")}function W(e){return n.find($e.requestStatuses,function(t){return t.value===e})}function H(e){$e.errors=n.isArray(e)?e:[e],$e.loading.absenceTypes=!1,$e.submitting=!1}function G(){return!e.equals(Ie,$e.request.attributes())||$e.canManage&&$e.newStatusOnSave}function Y(){return $e.postContactSelection=!0,$e.staffMemberSelectionComplete=!1,$e.request.contact_id?o.resolve().then(ie).then(ce).then(he).then(be).then(Z).then(z).then($e.isMode("edit")?ge:n.noop).then(function(){$e.postContactSelection=!1,$e.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Se)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Te.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Te.awaiting_approval=e,Te.more_information_required=e,Te.rejected=e,Te.approved=e,Te.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return $e.canManage?f.find($e.request.contact_id).then(function(e){$e.contactName=e.display_name}):o.resolve()}function X(){ke.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",$e.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){we++})),r.$on("$destroy",Pe),r.$on("LeaveRequestPopup::addTab",function(e,t){Oe.push(t)})}function Q(){var e,t;$e.request=$e.leaveRequest||null,e=F(),t=$e.initRequestAttributes(),"leave"===e?$e.request=_.init(t):"sickness"===e?$e.request=q.init(t):"toil"===e&&($e.request=C.init(t))}function J(){var e={};return $e.request?e=$e.request.attributes():$e.canManage||(e={contact_id:Le}),e}function K(){if(Me="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(Me="admin")}).then(function(){return"staff"===Me&&c(y.permissions.ssp.manage).then(function(e){e&&(Me="manager")})}).finally(function(){$e.canManage=$e.isRole("manager")||$e.isRole("admin")})}function Z(){($e.isRole("admin")||$e.isMode("create")&&$e.isRole("manager"))&&($e.newStatusOnSave=$e.requestStatuses[y.statusNames.approved].value)}function ee(){return!$e.request.status_id||!n.includes(["cancelled","rejected"],W($e.request.status_id).name)}function te(e){var t=$e.getStatusFromValue($e.request.status_id);return!!t&&t.name===e}function ne(e){return $e.request&&$e.request.request_type===e}function ae(e){return $e.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return Me===e}function re(){return h.all().then(function(e){$e.absencePeriods=e})}function ie(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Ae={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return $e.loading.entitlements=!0,b.all({contact_id:$e.request.contact_id,period_id:$e.period.id,type_id:{IN:Ae.ids}},!0).finally(function(){$e.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Le=e.contactId})}function le(){return $e.selectedContactId?f.find($e.selectedContactId).then(function(e){$e.managedContacts=[e]}):$e.isRole("admin")?f.all().then(function(e){$e.managedContacts=n.remove(e.list,function(e){return e.id!==Le})}):f.find(Le).then(function(e){return e.leaveManagees()}).then(function(e){$e.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){$e.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){A(),d.publish(e,$e.request),$e.errors=[],$e.dismissModal()}function pe(){["from","to"].forEach(function(e){$e.request[e+"_date"]=Ie[e+"_date"]})}function he(e){if($e.absenceTypes=me(Ae.types,e),!$e.absenceTypes.length)return o.reject(Se)}function ve(){$e.period=n.find($e.absencePeriods,function(e){return $e.isMode("create")?e.current:oe($e.request,e)})}function be(){$e.isMode("create")?($e.selectedAbsenceType=$e.absenceTypes[0],$e.request.type_id=$e.selectedAbsenceType.id):$e.selectedAbsenceType=n.find($e.absenceTypes,function(e){return e.id===$e.request.type_id})}function ge(){Ie=e.copy($e.request.attributes())}function _e(){var e;$e.request.id?(e=[$e.requestStatuses[y.statusNames.approved].value,$e.requestStatuses[y.statusNames.adminApproved].value,$e.requestStatuses[y.statusNames.rejected].value,$e.requestStatuses[y.statusNames.cancelled].value],$e.mode="edit",$e.isRole("staff")&&e.indexOf($e.request.status_id)>-1&&($e.mode="view")):$e.mode="create"}function ye(){var e=$e.request.status_id;if(!$e.isMode("view")&&!$e.submitting)return $e.submitting=!0,L(),R(),$e.request.isValid().then(ee()&&S).then($).then(!$e.request.change_balance&&pe).then(qe).then(function(){return $e.isMode("edit")?Re():O()}).catch(function(t){$e.request.status_id=e,t&&H(t)}).finally(function(){$e.submitting=!1})}function qe(){return o.all(Oe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===we&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return we>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Pe(){ke.forEach(function(e){e()})}function De(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Re(){return $e.request.update().then(Ce).then(function(){$e.isRole("manager")?fe("LeaveRequest::updatedByManager"):($e.isRole("staff")||$e.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Ae,Te={},we=0,Ie={},ke=[],Le="",Se="No entitlement",Me="",Oe=[],$e=n.assign(this,m);$e.absencePeriods=[],$e.absenceTypes=[],$e.canManage=!1,$e.contactName=null,$e.errors=[],$e.loading={absenceTypes:!0,entitlements:!0},$e.managedContacts=[],$e.mode="",$e.newStatusOnSave=null,$e.period={},$e.postContactSelection=!1,$e.requestStatuses={},$e.selectedAbsenceType={},$e.staffMemberSelectionComplete=!1,$e.submitting=!1,$e.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},$e.canChangeAbsenceType=I,$e.canSubmit=k,$e.closeAlert=M,$e.deleteLeaveRequest=x,$e.dismissModal=E,$e.getStatuses=U,$e.getStatusFromValue=W,$e.initAfterContactSelection=Y,$e.initRequestAttributes=J,$e.isLeaveStatus=te,$e.isLeaveType=ne,$e.isMode=ae,$e.isRole=se,$e.submit=ye,$e.updateAbsenceType=De,function(){$e.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),re(),de()]).then(Q).then(_e).then(ve).then(function(){return $e.canManage&&!$e.isMode("edit")&&le()}).then(function(){if($e.selectedContactId&&($e.request.contact_id=$e.selectedContactId),$e.request.contact_id)return $e.initAfterContactSelection()}).catch(H).finally(function(){$e.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,r,i,c){function u(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,r,i){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:r,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,r){function i(e){l.errorMessage=e}function c(){return r.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrjc_revision_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,r.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(i).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrjc_revision_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(),g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){i.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){r.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,r){function i(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,r){n=o.entitlements.slice(0,r),a=e.entitlements.slice(r+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,r;return s=e.indexBy(n,"entitlement_id.type_id"),r=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:r}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){ -var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t];e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,r){o.comment&&(t=s.concat(o).concat(r),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(i).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,r,i,c,u,l,d){function m(){P.absencePeriods=t.chain(P.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){P.absenceTypes=t.filter(P.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:P.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:P.contactId,returnUrl:n})}function h(){return c.all().then(function(e){P.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:P.contactId}).then(function(e){q=e})}function g(e){r.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=P.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){P.absencePeriods=t.map(P.absencePeriods,function(e){var n=t.map(P.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

Last updated:
By: "+e.author_name+"
Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],P=this;P.absencePeriods=[],P.loading={absencePeriods:!0},P.getEditEntitlementsPageURL=p,P.openAnnualEntitlementChangeLog=g,P.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){P.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,r,i){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return r.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){i.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); +})}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,r,i,c){function u(e){_([e]),N(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return U[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){S(e),N(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=R(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){F.push(o.$on("LeaveCalendar::showMonths",x)),F.push(i.subscribe("LeaveRequest::new",u)),F.push(i.subscribe("LeaveRequest::edit",B)),F.push(i.subscribe("LeaveRequest::updatedByManager",B)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function P(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function D(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function R(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function A(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function T(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function w(){return[T(c.statusNames.approved),T(c.statusNames.adminApproved),T(c.statusNames.awaitingApproval),T(c.statusNames.moreInformationRequired)]}function I(){return H.month.loading=!0,a.all([L(),k()]).then(b).then($).then(function(){j=!0}).then(function(){H.month.loading=!1})}function k(){return r.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:w()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function L(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function S(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function M(){o.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function O(t,n,o){var s,r;return t.contactsData[n]=t.contactsData[n]||{},r=m(n),s=!0===o?a.resolve():a.all([r.isWeekend(p(t.date)),r.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:P(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?D(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function $(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return O(e,t.id)}))}))}function x(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!j)&&I())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=A(e);t&&(h(t),-1!==w().indexOf(e.status_id)&&u(e))}function N(e){return a.all(R(e).map(function(t){return O(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var j=!1,F=[],U={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=M,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,r,i,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(r.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=P[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(P,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:P[e].label,isDirectAction:P[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,P={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,r,i,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,r.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l,d,m,f){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function h(e){return t(e,c.serverDateFormat).toDate()}function v(e){return t(e).format(c.serverDateFormat)}function b(e){var t;return r.resolve().then(function(){J(e),"from"===e&&Q(),N("hours")&&(y(e),"from"!==e||pe.uiOptions.multipleDays||y("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return P(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return r.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return G()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(N("hours"))return H(e).then(function(){ne(e,!0)})}).then(function(){if(se(),!t)return V();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(I)}function g(){return se(),V()}function _(){return pe.uiOptions.toDate=null,J("to"),r.resolve().then(function(){if(N("hours")&&pe.uiOptions.fromDate)return y("from"),!pe.uiOptions.multipleDays&&y("to"),H("from").then(function(){ne("from",!0)}).then(se)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&V)}function y(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&s&&o&&(s=A(s).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=A(o).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function C(t,n){return t?(t=v(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):D(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):r.reject([])}function P(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function D(e,n){return e=t(e),r.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function R(){return pe.request?pe.request.request_type:pe.leaveType||null}function A(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(K).catch(I)}function w(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function I(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function k(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?V():T()}function L(){var e=pe.request.attributes();return pe.uiOptions.fromDate=h(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=h(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function S(e){s.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){N("days")||+e==+t||(re(),pe.performBalanceChangeCalculation())})}function M(){fe.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){ue()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",V))}function O(){pe.isMode("edit")&&(pe.isLeaveStatus(c.statusNames.approved)||pe.isLeaveStatus(c.statusNames.adminApproved))&&(me={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function $(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(w(a.min,n)<=0||w(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function x(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return r.all(e.map(H)).then(function(){["from","to"].forEach(function(e){$(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(re)}function E(){["from","to"].forEach(function(e){S(e),B(e)})}function B(e){s.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){N("days")||t===n||(se(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function N(e){return pe.selectedAbsenceType.calculation_unit_name===e}function j(e){return pe.request.request_type===e}function F(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return C(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function W(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function H(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(v(t)).then(function(t){he[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return he[e]={},I(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):r.resolve()}function G(){return u.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function Y(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function V(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(K).catch(I).finally(function(){pe.loading.balanceChange=!1})):r.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function X(){return v(pe.request.from_date)===v(pe.request.to_date)}function Q(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,J("to"))}function J(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,se(),re(),ie()}function K(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=h(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=h(pe.period.end_date)}function ee(){return!pe.isMode("create")&&X()||pe.isMode("create")&&(j("sickness")||N("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,r.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,i=he[a].number_of_hours?w(s,r).toString():"0";o.maxAmount=i,t&&(o.amount=o.maxAmount)}function ae(){me&&me.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=me.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function oe(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function se(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?v(e.fromDate):null,pe.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),N("hours")&&!j("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function re(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ce(){e.forEach(fe,function(e){e()})}function ue(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return oe(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),r.resolve().then(e&&ee).then(function(){if(e&&N("hours"))return H("from").then(function(){ne("from",!0)})}).then(e&&se).then(V)}function le(e){return pe.absenceTypes=e,oe(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,J("to")),ae(),V()}function de(e){var t=A(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(A(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(A(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var me=null,fe=[],pe=this,he={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=c.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:Y},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=h,pe.convertDateToServerFormat=v,pe.dateChangeHandler=b,pe.dateTypeChangeHandler=g,pe.daysSelectionModeChangeHandler=_,pe.isLeaveType=j,pe.isNotWorkingDay=F,pe.performBalanceChangeCalculation=V,pe.$onDestroy=ce,function(){n("RequestModalDetails"+e.capitalize(R(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",pe),M(),pe.initChildController().then(function(){return r.all([G(),W()])}).then(!pe.isMode("create")&&L).then(ee).then(function(){if(!pe.isMode("create")&&N("hours"))return x().then(se)}).then(!pe.isMode("create")&&Z).then(O).then(ae).then(k).then(function(){pe.isMode("view")||j("toil")||E()}).catch(I).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l){function d(){return k.fileUploader&&k.fileUploader.queue.length>0}function m(){return k.getFilesAmount()0?T.map(function(e){return e.label}).join(", "):""}function q(){return k.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(T.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){I[e.label]=t})})).catch(function(){I=null})}function P(){return c.valuesOf("safe_file_extension").then(function(e){T=e})}function D(e){return!e.attachment_id||k.canManage}function R(){e.forEach(w,function(e){e()})}function A(e,t){k.fileUploader.queue&&k.fileUploader.queue.length>0?k.fileUploader.uploadAll({entityID:k.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var T=[],w=[],I={},k=Object.create(this);return k.filesLoaded=!1,k.fileUploader=null,k.today=Date.now(),k.userDateFormatWithTime=r.DATE_FORMAT+" HH:mm",k.userDateFormat=r.DATE_FORMAT,k.$onDestroy=R,k.canRemoveAttachment=D,k.canSubmit=d,k.canUploadMore=m,k.formatDateTime=f,k.getAuthorName=p,k.getFilesAmount=h,k.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",k),g(),a.all([P(),q()]).then(_).finally(function(){k.filesLoaded=!0})}(),k}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,o){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],s.openLeavePopup=a,function(){o=n.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",selectedContactId:"<",isSelfRecord:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,o,s,r,i,c,u,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):W.refresh()}function b(t){t.dataIndex=e.indexBy(t.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return r.all().then(r.loadCalculationUnits).then(function(t){W.absenceTypes=t,W.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return T("approved",{status_id:F(m.statusNames.approved)})}function C(){return n.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function P(){return i.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(t){var n=e.find(W.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function D(){return i.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return O(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function R(){return n.all([i.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),A({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:O(e[0]),expiredTOILS:$(e[1].list)})}).then(function(t){W.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function A(t){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function T(e,t){return A(t).then(function(t){W.sections[e].data=t.list})}function w(){return n.all(Object.values(W.sections).filter(function(e){return e.open}).map(S))}function I(){return T("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function k(){return T("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function L(){ +return T("holidays",{public_holiday:!0})}function S(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function M(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){W.leaveRequestStatuses=e.indexBy(t,"value")})}function O(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(W.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function $(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function x(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(W.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],B(t,a))})}function B(e,t){var n=W.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function N(){W.loading.content=!0,n.all([P(),C()]).then(function(){W.loading.content=!1}).then(function(){return n.all([w(),h()])})}function j(e){var t=W.sections[e];t.open=!t.open,t.open&&!t.data.length&&S(t)}function F(t){return e.find(W.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:D},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:L},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:k},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:I}},W.labelPeriod=g,W.refresh=N,W.toggleSection=j,function(){n.all([M(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return n.all([P(),C()])}).then(function(){W.loading.content=!1}),x()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["leave-absences/shared/modules/controllers"],function(e){function t(e,t,n,a){function o(){return a.request.calculateBalanceChange(a.selectedAbsenceType.calculation_unit_name)}function s(){var e=a.request,t=!!e.from_date&&!!e.to_date,n=a.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function r(){return a.canCalculateChange()}function i(){return n.resolve()}t.debug("RequestModalDetailsLeaveController"),a.calculateBalanceChange=o,a.canCalculateChange=s,a.canSubmit=r,a.initChildController=i}e.controller("RequestModalDetailsLeaveController",t),t.$inject=["$controller","$log","$q","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function r(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function i(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=r,s.initChildController=i,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s,r){function i(){return r.balance.change.amount=+r.request.toil_to_accrue,n.resolve(r.balance.change)}function c(){return f().catch(function(e){return e.length&&(r.errors=e),n.reject(e)}).then(function(e){return s.calculateToilExpiryDate(r.request.type_id,e)}).then(function(e){return r.request.toil_expiry_date=e,r.uiOptions.expiryDate=new Date(e),e})}function u(){return!!r.request.toil_to_accrue}function l(){var e=r.uiOptions.multipleDays&&!!r.request.to_date,t=!r.uiOptions.multipleDays&&!!r.request.from_date,n=t||e,a=D.from_date!==r.request.from_date||D.to_date!==r.request.to_date;return r.canDisplayToilExpirationField&&n&&R.hasExpirationFromAdminSettings&&a}function d(){return!!(r.request.from_date&&r.request.to_date&&r.request.toil_duration&&r.request.toil_to_accrue)}function m(){r.request.toil_expiry_date=!1,r.uiOptions.expiryDate=null}function f(){var e=r.uiOptions.multipleDays,t=r.request;return p({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function p(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return n.reject([t])}return e.value?n.resolve(e.value):n.reject([])}function h(){var e=r.isMode("create")&&R.hasExpirationFromAdminSettings,t=R.hasPreviousExpirationDate,n=r.isLeaveType("toil"),a=r.canManage;r.canDisplayToilExpirationField=n&&(a||e||t)}function v(){return R.hasPreviousExpirationDate=r.isMode("edit")&&!!r.request.toil_expiry_date,s.canExpire(r.request.type_id).then(function(e){R.hasExpirationFromAdminSettings=e})}function b(){return r.request.to_date_type=r.request.from_date_type="1",v().then(h).then(g).then(y)}function g(){r.canManage&&(r.uiOptions.expiryDate=r.convertDateFormatFromServer(r.request.toil_expiry_date))}function _(){r.isMode("view")||a.$watch(function(){return r.request.toil_to_accrue},function(e,t){+e!=+t&&r.performBalanceChangeCalculation()})}function y(){return o.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){r.toilAmounts=e.indexBy(t,"value")})}function q(){D=angular.copy(r.request.attributes())}function C(){return l()?c().catch(n.resolve):n.resolve()}function P(){r.uiOptions.expiryDate&&(r.request.toil_expiry_date=r.convertDateToServerFormat(r.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var D,R={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};r.canDisplayToilExpirationField=!1,r.calculateBalanceChange=i,r.canCalculateChange=u,r.canSubmit=d,r.clearExpiryDate=m,r.initChildController=b,r.onDateChangeExtended=C,r.setDaysSelectionModeExtended=C,r.updateExpiryDate=P,function(){_(),q()}()}t.controller("RequestModalDetailsToilController",n),n.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),r={date:o};return a.all(r).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={toilDurationHours:"0",toilDurationMinutes:"0",request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},transformAttributes:function(e){var t=Number(e.toil_duration);return t&&(e.toilDurationHours=Math.floor(t/60).toString(),e.toilDurationMinutes=(t%60).toString()),e},updateDuration:function(){this.toil_duration=60*Number(this.toilDurationHours)+Number(this.toilDurationMinutes)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files","toilDurationHours","toilDurationMinutes"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,r,i,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,P){function D(e){"days"===$e.selectedAbsenceType.calculation_unit_name?delete $e.request[e+"_date_amount"]:delete $e.request[e+"_date_type"]}function R(){["from","to"].forEach(D)}function A(){var e=$e.requestStatuses[y.statusNames.awaitingApproval].value;Ie.status_id===e&&e!==$e.request.status_id&&d.publish("ManagerBadge:: Update Count")}function T(){return Oe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return Oe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return!$e.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function k(){var e=T();return $e.isMode("edit")&&(e=e&&(G()||w())),$e.canManage&&$e.requestStatuses&&(e=e&&!!$e.getStatusFromValue($e.newStatusOnSave)),(e=e&&!!$e.period.id)&&!$e.isMode("view")}function L(){$e.isSelfRecord?$e.request.status_id=$e.requestStatuses[y.statusNames.awaitingApproval].value:$e.canManage&&($e.request.status_id=$e.newStatusOnSave||$e.request.status_id)}function S(){if($e.isMode("edit")&&!$e.isRole("staff")&&"toil"!==F())return $e.request.calculateBalanceChange($e.selectedAbsenceType.calculation_unit_name).then(function(e){if(+$e.balance.change.amount!=+e.amount)return P.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function M(){$e.errors=[]}function O(){return $e.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function $(){ee()&&!$e.isRole("staff")&&($e.request.change_balance=!0)}function x(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return $e.request.delete().then(function(){$e.dismissModal(),d.publish("LeaveRequest::delete",$e.request)})}})}function E(){i.dismiss({$value:"cancel"})}function B(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function N(){return j($e.getStatusFromValue($e.request.status_id).name)}function j(e){return n.map(Te[e],function(e){return $e.requestStatuses[e]})}function F(){return $e.request?$e.request.request_type:$e.leaveType||null}function U(){return!$e.request||e.equals({},$e.requestStatuses)?[]:$e.request.status_id?N():j("none")}function W(e){return n.find($e.requestStatuses,function(t){return t.value===e})}function H(e){$e.errors=n.isArray(e)?e:[e],$e.loading.absenceTypes=!1,$e.submitting=!1}function G(){return!e.equals(Ie,$e.request.attributes())||$e.canManage&&$e.newStatusOnSave}function Y(){return $e.postContactSelection=!0,$e.staffMemberSelectionComplete=!1,$e.request.contact_id?o.resolve().then(ie).then(ce).then(he).then(be).then(Z).then(z).then($e.isMode("edit")?ge:n.noop).then(function(){$e.postContactSelection=!1,$e.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Se)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Te.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Te.awaiting_approval=e,Te.more_information_required=e,Te.rejected=e,Te.approved=e,Te.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return $e.canManage?f.find($e.request.contact_id).then(function(e){$e.contactName=e.display_name}):o.resolve()}function X(){ke.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",$e.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){we++})),r.$on("$destroy",Pe),r.$on("LeaveRequestPopup::addTab",function(e,t){Oe.push(t)})}function Q(){var e,t;$e.request=$e.leaveRequest||null,e=F(),t=$e.initRequestAttributes(),"leave"===e?$e.request=_.init(t):"sickness"===e?$e.request=q.init(t):"toil"===e&&($e.request=C.init(t))}function J(){var e={};return $e.request?e=$e.request.attributes():$e.canManage||(e={contact_id:Le}),e}function K(){if(Me="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(Me="admin")}).then(function(){return"staff"===Me&&c(y.permissions.ssp.manage).then(function(e){e&&(Me="manager")})}).finally(function(){$e.canManage=$e.isRole("manager")||$e.isRole("admin")})}function Z(){($e.isRole("admin")||$e.isMode("create")&&$e.isRole("manager"))&&($e.newStatusOnSave=$e.requestStatuses[y.statusNames.approved].value)}function ee(){return!$e.request.status_id||!n.includes(["cancelled","rejected"],W($e.request.status_id).name)}function te(e){var t=$e.getStatusFromValue($e.request.status_id);return!!t&&t.name===e}function ne(e){return $e.request&&$e.request.request_type===e}function ae(e){return $e.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return Me===e}function re(){return h.all().then(function(e){$e.absencePeriods=e})}function ie(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Ae={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return $e.loading.entitlements=!0,b.all({contact_id:$e.request.contact_id,period_id:$e.period.id,type_id:{IN:Ae.ids}},!0).finally(function(){$e.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Le=e.contactId})}function le(){return $e.selectedContactId?f.find($e.selectedContactId).then(function(e){$e.managedContacts=[e]}):$e.isRole("admin")?f.all().then(function(e){$e.managedContacts=n.remove(e.list,function(e){return e.id!==Le})}):f.find(Le).then(function(e){return e.leaveManagees()}).then(function(e){$e.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){$e.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){A(),d.publish(e,$e.request),$e.errors=[],$e.dismissModal()}function pe(){["from","to"].forEach(function(e){$e.request[e+"_date"]=Ie[e+"_date"]})}function he(e){if($e.absenceTypes=me(Ae.types,e),!$e.absenceTypes.length)return o.reject(Se)}function ve(){$e.period=n.find($e.absencePeriods,function(e){return $e.isMode("create")?e.current:oe($e.request,e)})}function be(){$e.isMode("create")?($e.selectedAbsenceType=$e.absenceTypes[0],$e.request.type_id=$e.selectedAbsenceType.id):$e.selectedAbsenceType=n.find($e.absenceTypes,function(e){return e.id===$e.request.type_id})}function ge(){Ie=e.copy($e.request.attributes())}function _e(){var e;$e.request.id?(e=[$e.requestStatuses[y.statusNames.approved].value,$e.requestStatuses[y.statusNames.adminApproved].value,$e.requestStatuses[y.statusNames.rejected].value,$e.requestStatuses[y.statusNames.cancelled].value],$e.mode="edit",$e.isRole("staff")&&e.indexOf($e.request.status_id)>-1&&($e.mode="view")):$e.mode="create"}function ye(){var e=$e.request.status_id;if(!$e.isMode("view")&&!$e.submitting)return $e.submitting=!0,L(),R(),$e.request.isValid().then(ee()&&S).then($).then(!$e.request.change_balance&&pe).then(qe).then(function(){return $e.isMode("edit")?Re():O()}).catch(function(t){$e.request.status_id=e,t&&H(t)}).finally(function(){$e.submitting=!1})}function qe(){return o.all(Oe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===we&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return we>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Pe(){ke.forEach(function(e){e()})}function De(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Re(){return $e.request.update().then(Ce).then(function(){$e.isRole("manager")?fe("LeaveRequest::updatedByManager"):($e.isRole("staff")||$e.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Ae,Te={},we=0,Ie={},ke=[],Le="",Se="No entitlement",Me="",Oe=[],$e=n.assign(this,m);$e.absencePeriods=[],$e.absenceTypes=[],$e.canManage=!1,$e.contactName=null,$e.errors=[],$e.loading={absenceTypes:!0,entitlements:!0},$e.managedContacts=[],$e.mode="",$e.newStatusOnSave=null,$e.period={},$e.postContactSelection=!1,$e.requestStatuses={},$e.selectedAbsenceType={},$e.staffMemberSelectionComplete=!1,$e.submitting=!1,$e.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},$e.canChangeAbsenceType=I,$e.canSubmit=k,$e.closeAlert=M,$e.deleteLeaveRequest=x,$e.dismissModal=E,$e.getStatuses=U,$e.getStatusFromValue=W,$e.initAfterContactSelection=Y,$e.initRequestAttributes=J,$e.isLeaveStatus=te,$e.isLeaveType=ne,$e.isMode=ae,$e.isRole=se,$e.submit=ye,$e.updateAbsenceType=De,function(){$e.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),re(),de()]).then(Q).then(_e).then(ve).then(function(){return $e.canManage&&!$e.isMode("edit")&&le()}).then(function(){if($e.selectedContactId&&($e.request.contact_id=$e.selectedContactId),$e.request.contact_id)return $e.initAfterContactSelection()}).catch(H).finally(function(){$e.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,r,i,c){function u(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,r,i){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:r,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,r){function i(e){l.errorMessage=e}function c(){return r.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrjc_revision_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,r.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(i).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrjc_revision_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(),g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){i.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){r.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,r){function i(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,r){n=o.entitlements.slice(0,r),a=e.entitlements.slice(r+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,r;return s=e.indexBy(n,"entitlement_id.type_id"),r=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:r}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t] +;e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,r){o.comment&&(t=s.concat(o).concat(r),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(i).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,r,i,c,u,l,d){function m(){P.absencePeriods=t.chain(P.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){P.absenceTypes=t.filter(P.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:P.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:P.contactId,returnUrl:n})}function h(){return c.all().then(function(e){P.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:P.contactId}).then(function(e){q=e})}function g(e){r.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=P.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){P.absencePeriods=t.map(P.absencePeriods,function(e){var n=t.map(P.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

Last updated:
By: "+e.author_name+"
Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],P=this;P.absencePeriods=[],P.loading={absencePeriods:!0},P.getEditEntitlementsPageURL=p,P.openAnnualEntitlementChangeLog=g,P.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){P.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,r,i){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return r.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){i.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js index 819333dc536..a8a385f1b4e 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js @@ -8,7 +8,7 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){A.$current.navigable==t&&c(e,n)||A.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=A.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=M[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(A.$current=t,A.current=t.self,A.params=n,V(A.params,m),A.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),A.current)}).then(null,function(a){return a===D?S:A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(A.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},A.is=function(e,t,a){a=W({relative:A.$current},a||{});var r=f(e,a.relative);return j(r)?A.$current===r&&(!t||c(r.params.$$values(t),m)):n},A.includes=function(e,t,a){if(a=W({relative:A.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=A.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(A.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function I(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function O(e,t){return{relative:S(e)||t.$current,inherit:!0}}function L(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=W(O(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=I(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function M(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=I(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function k(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function x(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function E(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;aWhen All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

","

People I approve filter displays only staff members who you approve leave for.

","

People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

"].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(M.selectedPeriod.start_date).clone().startOf("month"),a=n(M.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");M.months=e}function p(){s.$new().$watch(function(){return M.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){M.injectMonths=!0,I("injected").then(function(){R(e)}).then(function(){M.loading.calendar=!1})}function v(){O=a("LeaveCalendar"+t.capitalize(L)+"Controller").init(M)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){M.absencePeriods=t.sortBy(e,"start_date"),M.selectedPeriod=t.find(M.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return O.loadContacts().then(function(e){M.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){M.filters.optionValues.regions=e.hrjc_region,M.filters.optionValues.locations=e.hrjc_location,M.filters.optionValues.levelTypes=e.hrjc_level_type,M.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function w(){return r.all([y(),C(),_()]).then(function(e){M.supportData.absenceTypes=e[0],M.supportData.publicHolidays=e[1],M.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,M.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,M.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,M.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return M.injectMonths&&(e=I("destroyed"),M.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){M.loading.calendar=!0}).then(A).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=M.selectedMonths.length?M.months.filter(function(e){return t.includes(M.selectedMonths,e.index)}):M.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){M.selectedMonths=[n().month()]}function T(){return M.roleOverride?r.resolve().then(function(){L=M.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){L=e[0]?"admin":e[1]?"manager":"staff"})}function I(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===M.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var O,L,M=this;M.absencePeriods=[],M.contacts=[],M.contactIdsToReduceTo=null,M.injectMonths=!1,M.months=[],M.selectedMonths=null,M.selectedPeriod=null,M.showContactName=!1,M.showFilters=!1,M.supportData={},M.loading={calendar:!0,page:!0},M.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},M.labelPeriod=g,M.refresh=D,function(){T().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),w()])}).then(function(){return M.showFilters?$():t.noop}).then(function(){h()}).then(function(){M.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){O(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",x)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function w(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([I(),T()]).then(g).then(k).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function I(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function O(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function L(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function M(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?w(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function k(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return M(e,t.id)}))}))}function x(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function E(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(A(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=L,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}), -define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f,m){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function h(e){return t(e,u.serverDateFormat).toDate()}function v(e){return t(e).format(u.serverDateFormat)}function g(e){var t;return s.resolve().then(function(){X(e),"from"===e&&K(),B("hours")&&(_(e),"from"!==e||pe.uiOptions.multipleDays||_("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return C(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return s.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return V()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(B("hours"))return W(e).then(function(){ne(e,!0)})}).then(function(){if(oe(),!t)return Y();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(S)}function b(){return oe(),Y()}function y(){return pe.uiOptions.toDate=null,X("to"),s.resolve().then(function(){if(B("hours")&&pe.uiOptions.fromDate)return _("from"),!pe.uiOptions.multipleDays&&_("to"),W("from").then(function(){ne("from",!0)}).then(oe)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&Y)}function _(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&o&&r&&(o=P(o).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=P(r).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function $(t,n){return t?(t=v(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):w(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):s.reject([])}function C(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function w(e,n){return e=t(e),s.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function A(){return pe.request?pe.request.request_type:pe.leaveType||null}function P(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(Q).catch(S)}function R(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function S(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function T(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?Y():D()}function I(){var e=pe.request.attributes();return pe.uiOptions.fromDate=h(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=h(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function O(e){o.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){B("days")||+e==+t||(se(),pe.performBalanceChangeCalculation())})}function L(){me.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){ce()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",Y))}function M(){pe.isMode("edit")&&(pe.isLeaveStatus(u.statusNames.approved)||pe.isLeaveStatus(u.statusNames.adminApproved))&&(fe={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function k(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(R(a.min,n)<=0||R(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function x(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return s.all(e.map(W)).then(function(){["from","to"].forEach(function(e){k(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(se)}function E(){["from","to"].forEach(function(e){O(e),j(e)})}function j(e){o.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){B("days")||t===n||(oe(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function B(e){return pe.selectedAbsenceType.calculation_unit_name===e}function N(e){return pe.request.request_type===e}function F(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return $(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function H(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function W(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(v(t)).then(function(t){he[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return he[e]={},S(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):s.resolve()}function V(){return c.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function G(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function Y(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(Q).catch(S).finally(function(){pe.loading.balanceChange=!1})):s.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function J(){return v(pe.request.from_date)===v(pe.request.to_date)}function K(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,X("to"))}function X(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,oe(),se(),ie()}function Q(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=h(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=h(pe.period.end_date)}function ee(){return!pe.isMode("create")&&J()||pe.isMode("create")&&(N("sickness")||B("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,s.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,s=n.multipleDays&&"from"===a?r.max:n.times.to.time,i=he[a].number_of_hours?R(o,s).toString():"0";r.maxAmount=i,t&&(r.amount=r.maxAmount)}function ae(){fe&&fe.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=fe.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function re(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function oe(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?v(e.fromDate):null,pe.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),B("hours")&&!N("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function se(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ue(){e.forEach(me,function(e){e()})}function ce(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return re(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),s.resolve().then(e&&ee).then(function(){if(e&&B("hours"))return W("from").then(function(){ne("from",!0)})}).then(e&&oe).then(Y)}function le(e){return pe.absenceTypes=e,re(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,X("to")),ae(),Y()}function de(e){var t=P(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(P(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(P(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var fe=null,me=[],pe=this,he={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=u.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:G},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=h,pe.convertDateToServerFormat=v,pe.dateChangeHandler=g,pe.dateTypeChangeHandler=b,pe.daysSelectionModeChangeHandler=y,pe.isLeaveType=N,pe.isNotWorkingDay=F,pe.performBalanceChangeCalculation=Y,pe.$onDestroy=ue,function(){n("RequestModalDetails"+e.capitalize(A(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",pe),L(),pe.initChildController().then(function(){return s.all([V(),H()])}).then(!pe.isMode("create")&&I).then(ee).then(function(){if(!pe.isMode("create")&&B("hours"))return x().then(oe)}).then(!pe.isMode("create")&&Z).then(M).then(ae).then(T).then(function(){pe.isMode("view")||N("toil")||E()}).catch(S).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function w(e){return!e.attachment_id||T.canManage}function A(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=A,T.canRemoveAttachment=w,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=h,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"},{type:"toil",icon:"calendar-plus-o",label:"Overtime"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{btnClass:"@",contactId:"<",selectedContactId:"<",isSelfRecord:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function w(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function A(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:M(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:x(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function I(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function O(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function L(e,t,n,a){d.openModal.apply(d,arguments)}function M(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function k(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function x(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=k(n)),n.length)return{IN:n}}function E(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,A(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=h,U.getAbsenceTypeByID=v,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=L,U.refresh=E,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),w(),I(),P(),S(),R(),O()]).then(function(){U.loading.page=!1,A()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["leave-absences/shared/modules/controllers"],function(e){function t(e,t,n,a){function r(){return a.request.calculateBalanceChange(a.selectedAbsenceType.calculation_unit_name)}function o(){var e=a.request,t=!!e.from_date&&!!e.to_date,n=a.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function s(){return a.canCalculateChange()}function i(){return n.resolve()}t.debug("RequestModalDetailsLeaveController"),a.calculateBalanceChange=r,a.canCalculateChange=o,a.canSubmit=s,a.initChildController=i}e.controller("RequestModalDetailsLeaveController",t),t.$inject=["$controller","$log","$q","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s){function i(){return s.balance.change.amount=+s.request.toil_to_accrue,n.resolve(s.balance.change)}function u(){return m().catch(function(e){return e.length&&(s.errors=e),n.reject(e)}).then(function(e){return o.calculateToilExpiryDate(s.request.type_id,e)}).then(function(e){return s.request.toil_expiry_date=e,s.uiOptions.expiryDate=new Date(e),e})}function c(){return!!s.request.toil_to_accrue}function l(){var e=s.uiOptions.multipleDays&&!!s.request.to_date,t=!s.uiOptions.multipleDays&&!!s.request.from_date,n=t||e,a=w.from_date!==s.request.from_date||w.to_date!==s.request.to_date;return s.canDisplayToilExpirationField&&n&&A.hasExpirationFromAdminSettings&&a}function d(){return!!(s.request.from_date&&s.request.to_date&&s.request.toil_duration&&s.request.toil_to_accrue)}function f(){s.request.toil_expiry_date=!1,s.uiOptions.expiryDate=null}function m(){var e=s.uiOptions.multipleDays,t=s.request;return p({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function p(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return n.reject([t])}return e.value?n.resolve(e.value):n.reject([])}function h(){var e=s.isMode("create")&&A.hasExpirationFromAdminSettings,t=A.hasPreviousExpirationDate,n=s.isLeaveType("toil"),a=s.canManage;s.canDisplayToilExpirationField=n&&(a||e||t)}function v(){return A.hasPreviousExpirationDate=s.isMode("edit")&&!!s.request.toil_expiry_date,o.canExpire(s.request.type_id).then(function(e){A.hasExpirationFromAdminSettings=e})}function g(){return s.request.to_date_type=s.request.from_date_type="1",v().then(h).then(b).then(_)}function b(){s.canManage&&(s.uiOptions.expiryDate=s.convertDateFormatFromServer(s.request.toil_expiry_date))}function y(){s.isMode("view")||a.$watch(function(){return s.request.toil_to_accrue},function(e,t){+e!=+t&&s.performBalanceChangeCalculation()})}function _(){return r.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){s.toilAmounts=e.indexBy(t,"value")})}function q(){w=angular.copy(s.request.attributes())}function $(){return l()?u().catch(n.resolve):n.resolve()}function C(){s.uiOptions.expiryDate&&(s.request.toil_expiry_date=s.convertDateToServerFormat(s.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var w,A={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};s.canDisplayToilExpirationField=!1,s.calculateBalanceChange=i,s.canCalculateChange=c,s.canSubmit=d,s.clearExpiryDate=f,s.initChildController=g,s.onDateChangeExtended=$,s.setDaysSelectionModeExtended=$,s.updateExpiryDate=C,function(){y(),q()}()}t.controller("RequestModalDetailsToilController",n),n.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}), +define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f,m){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function h(e){return t(e,u.serverDateFormat).toDate()}function v(e){return t(e).format(u.serverDateFormat)}function g(e){var t;return s.resolve().then(function(){X(e),"from"===e&&K(),B("hours")&&(_(e),"from"!==e||pe.uiOptions.multipleDays||_("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return C(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return s.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return V()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(B("hours"))return W(e).then(function(){ne(e,!0)})}).then(function(){if(oe(),!t)return Y();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(S)}function b(){return oe(),Y()}function y(){return pe.uiOptions.toDate=null,X("to"),s.resolve().then(function(){if(B("hours")&&pe.uiOptions.fromDate)return _("from"),!pe.uiOptions.multipleDays&&_("to"),W("from").then(function(){ne("from",!0)}).then(oe)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&Y)}function _(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&o&&r&&(o=P(o).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=P(r).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function $(t,n){return t?(t=v(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):w(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):s.reject([])}function C(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function w(e,n){return e=t(e),s.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function A(){return pe.request?pe.request.request_type:pe.leaveType||null}function P(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(Q).catch(S)}function R(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function S(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function T(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?Y():D()}function I(){var e=pe.request.attributes();return pe.uiOptions.fromDate=h(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=h(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function O(e){o.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){B("days")||+e==+t||(se(),pe.performBalanceChangeCalculation())})}function L(){me.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){ce()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",Y))}function M(){pe.isMode("edit")&&(pe.isLeaveStatus(u.statusNames.approved)||pe.isLeaveStatus(u.statusNames.adminApproved))&&(fe={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function k(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(R(a.min,n)<=0||R(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function x(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return s.all(e.map(W)).then(function(){["from","to"].forEach(function(e){k(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(se)}function E(){["from","to"].forEach(function(e){O(e),j(e)})}function j(e){o.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){B("days")||t===n||(oe(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function B(e){return pe.selectedAbsenceType.calculation_unit_name===e}function N(e){return pe.request.request_type===e}function F(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return $(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function H(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function W(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(v(t)).then(function(t){he[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return he[e]={},S(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):s.resolve()}function V(){return c.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function G(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function Y(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(Q).catch(S).finally(function(){pe.loading.balanceChange=!1})):s.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function J(){return v(pe.request.from_date)===v(pe.request.to_date)}function K(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,X("to"))}function X(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,oe(),se(),ie()}function Q(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=h(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=h(pe.period.end_date)}function ee(){return!pe.isMode("create")&&J()||pe.isMode("create")&&(N("sickness")||B("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,s.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,s=n.multipleDays&&"from"===a?r.max:n.times.to.time,i=he[a].number_of_hours?R(o,s).toString():"0";r.maxAmount=i,t&&(r.amount=r.maxAmount)}function ae(){fe&&fe.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=fe.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function re(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function oe(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?v(e.fromDate):null,pe.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),B("hours")&&!N("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function se(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ue(){e.forEach(me,function(e){e()})}function ce(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return re(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),s.resolve().then(e&&ee).then(function(){if(e&&B("hours"))return W("from").then(function(){ne("from",!0)})}).then(e&&oe).then(Y)}function le(e){return pe.absenceTypes=e,re(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,X("to")),ae(),Y()}function de(e){var t=P(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(P(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(P(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var fe=null,me=[],pe=this,he={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=u.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:G},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=h,pe.convertDateToServerFormat=v,pe.dateChangeHandler=g,pe.dateTypeChangeHandler=b,pe.daysSelectionModeChangeHandler=y,pe.isLeaveType=N,pe.isNotWorkingDay=F,pe.performBalanceChangeCalculation=Y,pe.$onDestroy=ue,function(){n("RequestModalDetails"+e.capitalize(A(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",pe),L(),pe.initChildController().then(function(){return s.all([V(),H()])}).then(!pe.isMode("create")&&I).then(ee).then(function(){if(!pe.isMode("create")&&B("hours"))return x().then(oe)}).then(!pe.isMode("create")&&Z).then(M).then(ae).then(T).then(function(){pe.isMode("view")||N("toil")||E()}).catch(S).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function w(e){return!e.attachment_id||T.canManage}function A(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=A,T.canRemoveAttachment=w,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=h,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",selectedContactId:"<",isSelfRecord:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function w(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function A(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:M(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:x(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function I(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function O(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function L(e,t,n,a){d.openModal.apply(d,arguments)}function M(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function k(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function x(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=k(n)),n.length)return{IN:n}}function E(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,A(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=h,U.getAbsenceTypeByID=v,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=L,U.refresh=E,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),w(),I(),P(),S(),R(),O()]).then(function(){U.loading.page=!1,A()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["leave-absences/shared/modules/controllers"],function(e){function t(e,t,n,a){function r(){return a.request.calculateBalanceChange(a.selectedAbsenceType.calculation_unit_name)}function o(){var e=a.request,t=!!e.from_date&&!!e.to_date,n=a.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function s(){return a.canCalculateChange()}function i(){return n.resolve()}t.debug("RequestModalDetailsLeaveController"),a.calculateBalanceChange=r,a.canCalculateChange=o,a.canSubmit=s,a.initChildController=i}e.controller("RequestModalDetailsLeaveController",t),t.$inject=["$controller","$log","$q","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s){function i(){return s.balance.change.amount=+s.request.toil_to_accrue,n.resolve(s.balance.change)}function u(){return m().catch(function(e){return e.length&&(s.errors=e),n.reject(e)}).then(function(e){return o.calculateToilExpiryDate(s.request.type_id,e)}).then(function(e){return s.request.toil_expiry_date=e,s.uiOptions.expiryDate=new Date(e),e})}function c(){return!!s.request.toil_to_accrue}function l(){var e=s.uiOptions.multipleDays&&!!s.request.to_date,t=!s.uiOptions.multipleDays&&!!s.request.from_date,n=t||e,a=w.from_date!==s.request.from_date||w.to_date!==s.request.to_date;return s.canDisplayToilExpirationField&&n&&A.hasExpirationFromAdminSettings&&a}function d(){return!!(s.request.from_date&&s.request.to_date&&s.request.toil_duration&&s.request.toil_to_accrue)}function f(){s.request.toil_expiry_date=!1,s.uiOptions.expiryDate=null}function m(){var e=s.uiOptions.multipleDays,t=s.request;return p({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function p(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return n.reject([t])}return e.value?n.resolve(e.value):n.reject([])}function h(){var e=s.isMode("create")&&A.hasExpirationFromAdminSettings,t=A.hasPreviousExpirationDate,n=s.isLeaveType("toil"),a=s.canManage;s.canDisplayToilExpirationField=n&&(a||e||t)}function v(){return A.hasPreviousExpirationDate=s.isMode("edit")&&!!s.request.toil_expiry_date,o.canExpire(s.request.type_id).then(function(e){A.hasExpirationFromAdminSettings=e})}function g(){return s.request.to_date_type=s.request.from_date_type="1",v().then(h).then(b).then(_)}function b(){s.canManage&&(s.uiOptions.expiryDate=s.convertDateFormatFromServer(s.request.toil_expiry_date))}function y(){s.isMode("view")||a.$watch(function(){return s.request.toil_to_accrue},function(e,t){+e!=+t&&s.performBalanceChangeCalculation()})}function _(){return r.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){s.toilAmounts=e.indexBy(t,"value")})}function q(){w=angular.copy(s.request.attributes())}function $(){return l()?u().catch(n.resolve):n.resolve()}function C(){s.uiOptions.expiryDate&&(s.request.toil_expiry_date=s.convertDateToServerFormat(s.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var w,A={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};s.canDisplayToilExpirationField=!1,s.calculateBalanceChange=i,s.canCalculateChange=c,s.canSubmit=d,s.clearExpiryDate=f,s.initChildController=g,s.onDateChangeExtended=$,s.setDaysSelectionModeExtended=$,s.updateExpiryDate=C,function(){y(),q()}()}t.controller("RequestModalDetailsToilController",n),n.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}), define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,r,o){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(o.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={toilDurationHours:"0",toilDurationMinutes:"0",request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},transformAttributes:function(e){var t=Number(e.toil_duration);return t&&(e.toilDurationHours=Math.floor(t/60).toString(),e.toilDurationMinutes=(t%60).toString()),e},updateDuration:function(){this.toil_duration=60*Number(this.toilDurationHours)+Number(this.toilDurationMinutes)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files","toilDurationHours","toilDurationMinutes"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function w(e){"days"===ke.selectedAbsenceType.calculation_unit_name?delete ke.request[e+"_date_amount"]:delete ke.request[e+"_date_type"]}function A(){["from","to"].forEach(w)}function P(){var e=ke.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==ke.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!ke.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return ke.isMode("edit")&&(e=e&&(V()||R())),ke.canManage&&ke.requestStatuses&&(e=e&&!!ke.getStatusFromValue(ke.newStatusOnSave)),(e=e&&!!ke.period.id)&&!ke.isMode("view")}function I(){ke.isSelfRecord?ke.request.status_id=ke.requestStatuses[_.statusNames.awaitingApproval].value:ke.canManage&&(ke.request.status_id=ke.newStatusOnSave||ke.request.status_id)}function O(){if(ke.isMode("edit")&&!ke.isRole("staff")&&"toil"!==F())return ke.request.calculateBalanceChange(ke.selectedAbsenceType.calculation_unit_name).then(function(e){if(+ke.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function L(){ke.errors=[]}function M(){return ke.request.create().then($e).then(function(){me("LeaveRequest::new")})}function k(){ee()&&!ke.isRole("staff")&&(ke.request.change_balance=!0)}function x(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return ke.request.delete().then(function(){ke.dismissModal(),d.publish("LeaveRequest::delete",ke.request)})}})}function E(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(ke.getStatusFromValue(ke.request.status_id).name)}function N(e){return n.map(De[e],function(e){return ke.requestStatuses[e]})}function F(){return ke.request?ke.request.request_type:ke.leaveType||null}function U(){return!ke.request||e.equals({},ke.requestStatuses)?[]:ke.request.status_id?B():N("none")}function H(e){return n.find(ke.requestStatuses,function(t){return t.value===e})}function W(e){ke.errors=n.isArray(e)?e:[e],ke.loading.absenceTypes=!1,ke.submitting=!1}function V(){return!e.equals(Se,ke.request.attributes())||ke.canManage&&ke.newStatusOnSave}function G(){return ke.postContactSelection=!0,ke.staffMemberSelectionComplete=!1,ke.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(ke.isMode("edit")?be:n.noop).then(function(){ke.postContactSelection=!1,ke.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Oe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return ke.canManage?m.find(ke.request.contact_id).then(function(e){ke.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",ke.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function K(){var e,t;ke.request=ke.leaveRequest||null,e=F(),t=ke.initRequestAttributes(),"leave"===e?ke.request=y.init(t):"sickness"===e?ke.request=q.init(t):"toil"===e&&(ke.request=$.init(t))}function X(){var e={};return ke.request?e=ke.request.attributes():ke.canManage||(e={contact_id:Ie}),e}function Q(){if(Le="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Le="admin")}).then(function(){return"staff"===Le&&u(_.permissions.ssp.manage).then(function(e){e&&(Le="manager")})}).finally(function(){ke.canManage=ke.isRole("manager")||ke.isRole("admin")})}function Z(){(ke.isRole("admin")||ke.isMode("create")&&ke.isRole("manager"))&&(ke.newStatusOnSave=ke.requestStatuses[_.statusNames.approved].value)}function ee(){return!ke.request.status_id||!n.includes(["cancelled","rejected"],H(ke.request.status_id).name)}function te(e){var t=ke.getStatusFromValue(ke.request.status_id);return!!t&&t.name===e}function ne(e){return ke.request&&ke.request.request_type===e}function ae(e){return ke.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Le===e}function se(){return h.all().then(function(e){ke.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return ke.loading.entitlements=!0,g.all({contact_id:ke.request.contact_id,period_id:ke.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){ke.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Ie=e.contactId})}function le(){return ke.selectedContactId?m.find(ke.selectedContactId).then(function(e){ke.managedContacts=[e]}):ke.isRole("admin")?m.all().then(function(e){ke.managedContacts=n.remove(e.list,function(e){return e.id!==Ie})}):m.find(Ie).then(function(e){return e.leaveManagees()}).then(function(e){ke.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){ke.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,ke.request),ke.errors=[],ke.dismissModal()}function pe(){["from","to"].forEach(function(e){ke.request[e+"_date"]=Se[e+"_date"]})}function he(e){if(ke.absenceTypes=fe(Pe.types,e),!ke.absenceTypes.length)return r.reject(Oe)}function ve(){ke.period=n.find(ke.absencePeriods,function(e){return ke.isMode("create")?e.current:re(ke.request,e)})}function ge(){ke.isMode("create")?(ke.selectedAbsenceType=ke.absenceTypes[0],ke.request.type_id=ke.selectedAbsenceType.id):ke.selectedAbsenceType=n.find(ke.absenceTypes,function(e){return e.id===ke.request.type_id})}function be(){Se=e.copy(ke.request.attributes())}function ye(){var e;ke.request.id?(e=[ke.requestStatuses[_.statusNames.approved].value,ke.requestStatuses[_.statusNames.adminApproved].value,ke.requestStatuses[_.statusNames.rejected].value,ke.requestStatuses[_.statusNames.cancelled].value],ke.mode="edit",ke.isRole("staff")&&e.indexOf(ke.request.status_id)>-1&&(ke.mode="view")):ke.mode="create"}function _e(){var e=ke.request.status_id;if(!ke.isMode("view")&&!ke.submitting)return ke.submitting=!0,I(),A(),ke.request.isValid().then(ee()&&O).then(k).then(!ke.request.change_balance&&pe).then(qe).then(function(){return ke.isMode("edit")?Ae():M()}).catch(function(t){ke.request.status_id=e,t&&W(t)}).finally(function(){ke.submitting=!1})}function qe(){return r.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function we(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return ke.request.update().then($e).then(function(){ke.isRole("manager")?me("LeaveRequest::updatedByManager"):(ke.isRole("staff")||ke.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Ie="",Oe="No entitlement",Le="",Me=[],ke=n.assign(this,f);ke.absencePeriods=[],ke.absenceTypes=[],ke.canManage=!1,ke.contactName=null,ke.errors=[],ke.loading={absenceTypes:!0,entitlements:!0},ke.managedContacts=[],ke.mode="",ke.newStatusOnSave=null,ke.period={},ke.postContactSelection=!1,ke.requestStatuses={},ke.selectedAbsenceType={},ke.staffMemberSelectionComplete=!1,ke.submitting=!1,ke.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},ke.canChangeAbsenceType=S,ke.canSubmit=T,ke.closeAlert=L,ke.deleteLeaveRequest=x,ke.dismissModal=E,ke.getStatuses=U,ke.getStatusFromValue=H,ke.initAfterContactSelection=G,ke.initRequestAttributes=X,ke.isLeaveStatus=te,ke.isLeaveType=ne,ke.isMode=ae,ke.isRole=oe,ke.submit=_e,ke.updateAbsenceType=we,function(){ke.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return ke.canManage&&!ke.isMode("edit")&&le()}).then(function(){if(ke.selectedContactId&&(ke.request.contact_id=ke.selectedContactId),ke.request.contact_id)return ke.initAfterContactSelection()}).catch(W).finally(function(){ke.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(t){return t.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM),define("leave-absences/admin-dashboard/modules/config",["common/angular","leave-absences/admin-dashboard/modules/settings"],function(e){return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(e,t,n,a,r,o){var s={format:["DateFormat",function(e){return e.getDateFormat()}]};r.debugEnabled(o.debug),t.defaults.stripTrailingSlashes=!1,a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:s}).state("calendar",{url:"/calendar",template:'',resolve:s}).state("leave-balances",{url:"/leave-balances",template:"",resolve:s})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function t(e,t){e.debug("Component: admin-dashboard-container"),t.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",t]})}), define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/admin-dashboard":n+"/admin-dashboard"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js index 6ec92696a82..cffb5875b44 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js @@ -8,7 +8,7 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))h.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),h.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var v=s(u||{}),h=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+h.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,v)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,v)),m.$$inheritedValues=f(o.$$values,v),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,v)),o.then(i,u));for(var q=0,$=h.length;q<$;q+=3)a.hasOwnProperty(h[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(h[q],h[q+1],h[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(h.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(v[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return v[t]=new Y.Param(t,n,a,r),v[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},v=this.params=r?r.params.$$new():new Y.ParamSet,h=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=h}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:v,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,v=!0,h=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(v=e),v},this.defaultSquashPolicy=function(e){if(!j(e))return h;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return h=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!v.type.is(e))throw new Error("Default value ("+e+") for parameter '"+v.id+"' is not an instance of Type ("+v.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(v.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?v.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var v=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return h;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[D]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),h(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=M[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&h.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),h.update(!0),w.current)}).then(null,function(a){return a===R?S:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||h.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=R(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==v){d=n.$new(),v=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(h)}}var f,m,p,v,h=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=R(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function R(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function D(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function I(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function O(e,t){return{relative:S(e)||t.$current,inherit:!0}}function L(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=D(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=W(O(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=I(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function M(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=I(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function k(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return v.push(u),h[s]=r,function(){var e=v.indexOf(u);-1!==e&&v.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function x(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function E(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),h.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",h),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n){function a(e){e.absencePeriods&&c.absencePeriods.length&&(c.filters.period_id=o().id),e.absenceTypes&&c.absenceTypes.length&&(c.filters.type_id=s().id),(e.loggedInContactId||e.userRole)&&(c.filters.managed_by="manager"===c.userRole?c.loggedInContactId:void 0),r()&&c.submitFilters()}function r(){return e.every(c.filters,function(e){return null!==e})}function o(){return e.find(c.absencePeriods,function(e){return e.current})||c.absencePeriods.reduce(function(e,n){return t(e.end_date).isAfter(n.end_date)?e:n})}function s(){return c.absenceTypes.reduce(function(e,t){return e.title.localeCompare(t.title)?e:t})}function i(e){return e.current?"Current Period ("+e.title+")":e.title}function u(){n.$emit("LeaveBalanceFilters::update",c.filters)}var c=this;c.filters={period_id:null,type_id:null,managed_by:null},c.$onChanges=a,c.labelPeriod=i,c.submitFilters=u}n.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,t){return e.extend({all:function(e,n,a,r,o){return t.getLeaveBalances(this.processFilters(e),n,a,r,o)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){return r.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function p(){return o.all().then(o.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function v(){return s.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function h(){return n.all([m(),p(),v(),g(),q()]).catch(function(e){u.error("Error",e)})}function g(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function b(){return P.loading.report=!0,i.all(w,P.pagination,void 0,void 0,!1).then(function(e){P.report=y(e.list),P.reportCount=e.total}).catch(function(e){u.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function y(n){return n.map(function(n){return n=e.copy(n),n.absence_types=t.indexBy(n.absence_types,function(e){return e.id}),n})}function _(){a.$on("LeaveBalanceFilters::update",C),c.subscribe("LeaveRequest::new",$)}function q(){return f(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function $(e){C(e,w)}function C(e,t){w=t,P.pagination.page=1,A(),P.loadReportCurrentPage()}function A(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+w.type_id})}var w={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.loadReportCurrentPage=b,function(){_(),h().then(function(){P.loading.component=!1})}()}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(h.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(h.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=h.filters.userSettings.assignedTo.type;return f(e).then(function(e){h.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return h.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(m(),null,"display_name").then(function(e){return e.list})}function d(){return v?a.resolve(v):s.all()}function f(e){return"me"===e?r.leaveManagees(h.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function m(){return{department:h.filters.userSettings.department?h.filters.userSettings.department.value:null,level_type:h.filters.userSettings.level_type?h.filters.userSettings.level_type.value:null,location:h.filters.userSettings.location?h.filters.userSettings.location.value:null,region:h.filters.userSettings.region?h.filters.userSettings.region.value:null,id:{IN:h.filters.userSettings.contact?[h.filters.userSettings.contact.id]:h.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

","

People I approve filter displays only staff members who you approve leave for.

","

People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

"].join(""))}n.debug("LeaveCalendarAdminController");var v,h;return{init:function(e){return h=e,h.showContactDetailsLink=!0,h.showContactName=!0,h.showFilters=!0,h.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],h.filters.userSettings.assignedTo=h.filtersByAssignee[0],h.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(M.selectedPeriod.start_date).clone().startOf("month"),a=n(M.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");M.months=e}function p(){s.$new().$watch(function(){return M.selectedMonths},function(t,n){null===n||e.equals(t,n)||D()})}function v(e){M.injectMonths=!0,I("injected").then(function(){D(e)}).then(function(){M.loading.calendar=!1})}function h(){O=a("LeaveCalendar"+t.capitalize(L)+"Controller").init(M)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){M.absencePeriods=t.sortBy(e,"start_date"),M.selectedPeriod=t.find(M.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return O.loadContacts().then(function(e){M.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){M.filters.optionValues.regions=e.hrjc_region,M.filters.optionValues.locations=e.hrjc_location,M.filters.optionValues.levelTypes=e.hrjc_level_type,M.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){M.supportData.absenceTypes=e[0],M.supportData.publicHolidays=e[1],M.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,M.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,M.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,M.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return M.injectMonths&&(e=I("destroyed"),M.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function R(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){M.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){v("contacts"===e)})}function D(e){var n=M.selectedMonths.length?M.months.filter(function(e){return t.includes(M.selectedMonths,e.index)}):M.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){M.selectedMonths=[n().month()]}function T(){return M.roleOverride?r.resolve().then(function(){L=M.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){L=e[0]?"admin":e[1]?"manager":"staff"})}function I(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===M.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var O,L,M=this;M.absencePeriods=[],M.contacts=[],M.contactIdsToReduceTo=null,M.injectMonths=!1,M.months=[],M.selectedMonths=null,M.selectedPeriod=null,M.showContactName=!1,M.showFilters=!1,M.supportData={},M.loading={calendar:!0,page:!0},M.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},M.labelPeriod=g,M.refresh=R,function(){T().then(p).then(h).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return M.showFilters?$():t.noop}).then(function(){v()}).then(function(){M.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function v(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function h(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),v())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){h()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function v(e){O(e),B(e)}function h(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",x)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",v)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?v(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function R(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function D(){return[R(u.statusNames.approved),R(u.statusNames.adminApproved),R(u.statusNames.awaitingApproval),R(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([I(),T()]).then(g).then(k).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:D()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function I(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function O(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function L(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function M(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function k(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return M(e,t.id)}))}))}function x(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function E(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(v(t),-1!==D().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=L,W.contactsList=m,W.getContactUrl=h,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}), -define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(v(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):v(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function v(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function h(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=h,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function v(e){return q.mode===e}function h(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=v,q.onBeforeSubmit=h,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f,m){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function v(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function g(e){var t;return s.resolve().then(function(){X(e),"from"===e&&K(),B("hours")&&(_(e),"from"!==e||pe.uiOptions.multipleDays||_("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return C(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return s.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return V()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(B("hours"))return W(e).then(function(){ne(e,!0)})}).then(function(){if(oe(),!t)return Y();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(S)}function b(){return oe(),Y()}function y(){return pe.uiOptions.toDate=null,X("to"),s.resolve().then(function(){if(B("hours")&&pe.uiOptions.fromDate)return _("from"),!pe.uiOptions.multipleDays&&_("to"),W("from").then(function(){ne("from",!0)}).then(oe)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&Y)}function _(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&o&&r&&(o=P(o).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=P(r).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function $(t,n){return t?(t=h(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):A(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):s.reject([])}function C(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function A(e,n){return e=t(e),s.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function w(){return pe.request?pe.request.request_type:pe.leaveType||null}function P(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function R(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(Q).catch(S)}function D(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function S(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function T(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?Y():R()}function I(){var e=pe.request.attributes();return pe.uiOptions.fromDate=v(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=v(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function O(e){o.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){B("days")||+e==+t||(se(),pe.performBalanceChangeCalculation())})}function L(){me.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){ce()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",Y))}function M(){pe.isMode("edit")&&(pe.isLeaveStatus(u.statusNames.approved)||pe.isLeaveStatus(u.statusNames.adminApproved))&&(fe={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function k(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(D(a.min,n)<=0||D(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function x(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return s.all(e.map(W)).then(function(){["from","to"].forEach(function(e){k(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(se)}function E(){["from","to"].forEach(function(e){O(e),j(e)})}function j(e){o.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){B("days")||t===n||(oe(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function B(e){return pe.selectedAbsenceType.calculation_unit_name===e}function N(e){return pe.request.request_type===e}function F(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return $(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function H(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function W(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(h(t)).then(function(t){ve[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return ve[e]={},S(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):s.resolve()}function V(){return c.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function G(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function Y(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(Q).catch(S).finally(function(){pe.loading.balanceChange=!1})):s.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function J(){return h(pe.request.from_date)===h(pe.request.to_date)}function K(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,X("to"))}function X(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,oe(),se(),ie()}function Q(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=v(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=v(pe.period.end_date)}function ee(){return!pe.isMode("create")&&J()||pe.isMode("create")&&(N("sickness")||B("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,s.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,s=n.multipleDays&&"from"===a?r.max:n.times.to.time,i=ve[a].number_of_hours?D(o,s).toString():"0";r.maxAmount=i,t&&(r.amount=r.maxAmount)}function ae(){fe&&fe.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=fe.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function re(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function oe(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?h(e.fromDate):null,pe.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),B("hours")&&!N("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function se(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ue(){e.forEach(me,function(e){e()})}function ce(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return re(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),s.resolve().then(e&&ee).then(function(){if(e&&B("hours"))return W("from").then(function(){ne("from",!0)})}).then(e&&oe).then(Y)}function le(e){return pe.absenceTypes=e,re(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,X("to")),ae(),Y()}function de(e){var t=P(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(P(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(P(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var fe=null,me=[],pe=this,ve={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=u.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:G},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=v,pe.convertDateToServerFormat=h,pe.dateChangeHandler=g,pe.dateTypeChangeHandler=b,pe.daysSelectionModeChangeHandler=y,pe.isLeaveType=N,pe.isNotWorkingDay=F,pe.performBalanceChangeCalculation=Y,pe.$onDestroy=ue,function(){n("RequestModalDetails"+e.capitalize(w(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",pe),L(),pe.initChildController().then(function(){return s.all([V(),H()])}).then(!pe.isMode("create")&&I).then(ee).then(function(){if(!pe.isMode("create")&&B("hours"))return x().then(oe)}).then(!pe.isMode("create")&&Z).then(M).then(ae).then(T).then(function(){pe.isMode("view")||N("toil")||E()}).catch(S).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?R.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(R.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){R=e})}function A(e){return!e.attachment_id||T.canManage}function w(){e.forEach(D,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var R=[],D=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=w,T.canRemoveAttachment=A,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=v,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"},{type:"toil",icon:"calendar-plus-o",label:"Overtime"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{btnClass:"@",contactId:"<",selectedContactId:"<",isSelfRecord:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function v(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function h(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?R(e):n.all([R("table"),R("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function R(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function D(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:M(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:x(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function I(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function O(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function L(e,t,n,a){d.openModal.apply(d,arguments)}function M(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function k(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function x(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=k(n)),n.length)return{IN:n}}function E(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=v,U.getAbsenceTypeByID=h,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=L,U.refresh=E,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),I(),P(),S(),D(),O()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["leave-absences/shared/modules/controllers"],function(e){function t(e,t,n,a){function r(){return a.request.calculateBalanceChange(a.selectedAbsenceType.calculation_unit_name)}function o(){var e=a.request,t=!!e.from_date&&!!e.to_date,n=a.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function s(){return a.canCalculateChange()}function i(){return n.resolve()}t.debug("RequestModalDetailsLeaveController"),a.calculateBalanceChange=r,a.canCalculateChange=o,a.canSubmit=s,a.initChildController=i}e.controller("RequestModalDetailsLeaveController",t),t.$inject=["$controller","$log","$q","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s){function i(){ -return s.balance.change.amount=+s.request.toil_to_accrue,n.resolve(s.balance.change)}function u(){return m().catch(function(e){return e.length&&(s.errors=e),n.reject(e)}).then(function(e){return o.calculateToilExpiryDate(s.request.type_id,e)}).then(function(e){return s.request.toil_expiry_date=e,s.uiOptions.expiryDate=new Date(e),e})}function c(){return!!s.request.toil_to_accrue}function l(){var e=s.uiOptions.multipleDays&&!!s.request.to_date,t=!s.uiOptions.multipleDays&&!!s.request.from_date,n=t||e,a=A.from_date!==s.request.from_date||A.to_date!==s.request.to_date;return s.canDisplayToilExpirationField&&n&&w.hasExpirationFromAdminSettings&&a}function d(){return!!(s.request.from_date&&s.request.to_date&&s.request.toil_duration&&s.request.toil_to_accrue)}function f(){s.request.toil_expiry_date=!1,s.uiOptions.expiryDate=null}function m(){var e=s.uiOptions.multipleDays,t=s.request;return p({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function p(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return n.reject([t])}return e.value?n.resolve(e.value):n.reject([])}function v(){var e=s.isMode("create")&&w.hasExpirationFromAdminSettings,t=w.hasPreviousExpirationDate,n=s.isLeaveType("toil"),a=s.canManage;s.canDisplayToilExpirationField=n&&(a||e||t)}function h(){return w.hasPreviousExpirationDate=s.isMode("edit")&&!!s.request.toil_expiry_date,o.canExpire(s.request.type_id).then(function(e){w.hasExpirationFromAdminSettings=e})}function g(){return s.request.to_date_type=s.request.from_date_type="1",h().then(v).then(b).then(_)}function b(){s.canManage&&(s.uiOptions.expiryDate=s.convertDateFormatFromServer(s.request.toil_expiry_date))}function y(){s.isMode("view")||a.$watch(function(){return s.request.toil_to_accrue},function(e,t){+e!=+t&&s.performBalanceChangeCalculation()})}function _(){return r.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){s.toilAmounts=e.indexBy(t,"value")})}function q(){A=angular.copy(s.request.attributes())}function $(){return l()?u().catch(n.resolve):n.resolve()}function C(){s.uiOptions.expiryDate&&(s.request.toil_expiry_date=s.convertDateToServerFormat(s.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var A,w={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};s.canDisplayToilExpirationField=!1,s.calculateBalanceChange=i,s.canCalculateChange=c,s.canSubmit=d,s.clearExpiryDate=f,s.initChildController=g,s.onDateChangeExtended=$,s.setDaysSelectionModeExtended=$,s.updateExpiryDate=C,function(){y(),q()}()}t.controller("RequestModalDetailsToilController",n),n.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function v(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function h(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?v.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([h.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([h.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={toilDurationHours:"0",toilDurationMinutes:"0",request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},transformAttributes:function(e){var t=Number(e.toil_duration);return t&&(e.toilDurationHours=Math.floor(t/60).toString(),e.toilDurationMinutes=(t%60).toString()),e},updateDuration:function(){this.toil_duration=60*Number(this.toilDurationHours)+Number(this.toilDurationMinutes)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files","toilDurationHours","toilDurationMinutes"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,v,h,g,b,y,_,q,$,C){function A(e){"days"===ke.selectedAbsenceType.calculation_unit_name?delete ke.request[e+"_date_amount"]:delete ke.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=ke.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==ke.request.status_id&&d.publish("ManagerBadge:: Update Count")}function R(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function D(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!ke.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=R();return ke.isMode("edit")&&(e=e&&(V()||D())),ke.canManage&&ke.requestStatuses&&(e=e&&!!ke.getStatusFromValue(ke.newStatusOnSave)),(e=e&&!!ke.period.id)&&!ke.isMode("view")}function I(){ke.isSelfRecord?ke.request.status_id=ke.requestStatuses[_.statusNames.awaitingApproval].value:ke.canManage&&(ke.request.status_id=ke.newStatusOnSave||ke.request.status_id)}function O(){if(ke.isMode("edit")&&!ke.isRole("staff")&&"toil"!==F())return ke.request.calculateBalanceChange(ke.selectedAbsenceType.calculation_unit_name).then(function(e){if(+ke.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function L(){ke.errors=[]}function M(){return ke.request.create().then($e).then(function(){me("LeaveRequest::new")})}function k(){ee()&&!ke.isRole("staff")&&(ke.request.change_balance=!0)}function x(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return ke.request.delete().then(function(){ke.dismissModal(),d.publish("LeaveRequest::delete",ke.request)})}})}function E(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(ke.getStatusFromValue(ke.request.status_id).name)}function N(e){return n.map(Re[e],function(e){return ke.requestStatuses[e]})}function F(){return ke.request?ke.request.request_type:ke.leaveType||null}function U(){return!ke.request||e.equals({},ke.requestStatuses)?[]:ke.request.status_id?B():N("none")}function H(e){return n.find(ke.requestStatuses,function(t){return t.value===e})}function W(e){ke.errors=n.isArray(e)?e:[e],ke.loading.absenceTypes=!1,ke.submitting=!1}function V(){return!e.equals(Se,ke.request.attributes())||ke.canManage&&ke.newStatusOnSave}function G(){return ke.postContactSelection=!0,ke.staffMemberSelectionComplete=!1,ke.request.contact_id?r.resolve().then(ie).then(ue).then(ve).then(ge).then(Z).then(z).then(ke.isMode("edit")?be:n.noop).then(function(){ke.postContactSelection=!1,ke.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Oe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Re.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Re.awaiting_approval=e,Re.more_information_required=e,Re.rejected=e,Re.approved=e,Re.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return ke.canManage?m.find(ke.request.contact_id).then(function(e){ke.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(ve).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",ke.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){De++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function K(){var e,t;ke.request=ke.leaveRequest||null,e=F(),t=ke.initRequestAttributes(),"leave"===e?ke.request=y.init(t):"sickness"===e?ke.request=q.init(t):"toil"===e&&(ke.request=$.init(t))}function X(){var e={};return ke.request?e=ke.request.attributes():ke.canManage||(e={contact_id:Ie}),e}function Q(){if(Le="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Le="admin")}).then(function(){return"staff"===Le&&u(_.permissions.ssp.manage).then(function(e){e&&(Le="manager")})}).finally(function(){ke.canManage=ke.isRole("manager")||ke.isRole("admin")})}function Z(){(ke.isRole("admin")||ke.isMode("create")&&ke.isRole("manager"))&&(ke.newStatusOnSave=ke.requestStatuses[_.statusNames.approved].value)}function ee(){return!ke.request.status_id||!n.includes(["cancelled","rejected"],H(ke.request.status_id).name)}function te(e){var t=ke.getStatusFromValue(ke.request.status_id);return!!t&&t.name===e}function ne(e){return ke.request&&ke.request.request_type===e}function ae(e){return ke.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Le===e}function se(){return v.all().then(function(e){ke.absencePeriods=e})}function ie(){return h.all(j()).then(h.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return ke.loading.entitlements=!0,g.all({contact_id:ke.request.contact_id,period_id:ke.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){ke.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Ie=e.contactId})}function le(){return ke.selectedContactId?m.find(ke.selectedContactId).then(function(e){ke.managedContacts=[e]}):ke.isRole("admin")?m.all().then(function(e){ke.managedContacts=n.remove(e.list,function(e){return e.id!==Ie})}):m.find(Ie).then(function(e){return e.leaveManagees()}).then(function(e){ke.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){ke.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,ke.request),ke.errors=[],ke.dismissModal()}function pe(){["from","to"].forEach(function(e){ke.request[e+"_date"]=Se[e+"_date"]})}function ve(e){if(ke.absenceTypes=fe(Pe.types,e),!ke.absenceTypes.length)return r.reject(Oe)}function he(){ke.period=n.find(ke.absencePeriods,function(e){return ke.isMode("create")?e.current:re(ke.request,e)})}function ge(){ke.isMode("create")?(ke.selectedAbsenceType=ke.absenceTypes[0],ke.request.type_id=ke.selectedAbsenceType.id):ke.selectedAbsenceType=n.find(ke.absenceTypes,function(e){return e.id===ke.request.type_id})}function be(){Se=e.copy(ke.request.attributes())}function ye(){var e;ke.request.id?(e=[ke.requestStatuses[_.statusNames.approved].value,ke.requestStatuses[_.statusNames.adminApproved].value,ke.requestStatuses[_.statusNames.rejected].value,ke.requestStatuses[_.statusNames.cancelled].value],ke.mode="edit",ke.isRole("staff")&&e.indexOf(ke.request.status_id)>-1&&(ke.mode="view")):ke.mode="create"}function _e(){var e=ke.request.status_id;if(!ke.isMode("view")&&!ke.submitting)return ke.submitting=!0,I(),w(),ke.request.isValid().then(ee()&&O).then(k).then(!ke.request.change_balance&&pe).then(qe).then(function(){return ke.isMode("edit")?we():M()}).catch(function(t){ke.request.status_id=e,t&&W(t)}).finally(function(){ke.submitting=!1})}function qe(){return r.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===De&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return De>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return ke.request.update().then($e).then(function(){ke.isRole("manager")?me("LeaveRequest::updatedByManager"):(ke.isRole("staff")||ke.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,Re={},De=0,Se={},Te=[],Ie="",Oe="No entitlement",Le="",Me=[],ke=n.assign(this,f);ke.absencePeriods=[],ke.absenceTypes=[],ke.canManage=!1,ke.contactName=null,ke.errors=[],ke.loading={absenceTypes:!0,entitlements:!0},ke.managedContacts=[],ke.mode="",ke.newStatusOnSave=null,ke.period={},ke.postContactSelection=!1,ke.requestStatuses={},ke.selectedAbsenceType={},ke.staffMemberSelectionComplete=!1,ke.submitting=!1,ke.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},ke.canChangeAbsenceType=S,ke.canSubmit=T,ke.closeAlert=L,ke.deleteLeaveRequest=x,ke.dismissModal=E,ke.getStatuses=U,ke.getStatusFromValue=H,ke.initAfterContactSelection=G,ke.initRequestAttributes=X,ke.isLeaveStatus=te,ke.isLeaveType=ne,ke.isMode=ae,ke.isRole=oe,ke.submit=_e,ke.updateAbsenceType=Ae,function(){ke.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(he).then(function(){return ke.canManage&&!ke.isMode("edit")&&le()}).then(function(){if(ke.selectedContactId&&(ke.request.contact_id=ke.selectedContactId),ke.request.contact_id)return ke.initAfterContactSelection()}).catch(W).finally(function(){ke.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e){define("leave-absences/manager-leave/modules/config",["common/angular","leave-absences/manager-leave/modules/settings"],function(t){return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/manager-leave/requests"),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM), +define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(v(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):v(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function v(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function h(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=h,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function v(e){return q.mode===e}function h(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=v,q.onBeforeSubmit=h,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f,m){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function v(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function g(e){var t;return s.resolve().then(function(){X(e),"from"===e&&K(),B("hours")&&(_(e),"from"!==e||pe.uiOptions.multipleDays||_("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return C(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return s.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return V()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(B("hours"))return W(e).then(function(){ne(e,!0)})}).then(function(){if(oe(),!t)return Y();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(S)}function b(){return oe(),Y()}function y(){return pe.uiOptions.toDate=null,X("to"),s.resolve().then(function(){if(B("hours")&&pe.uiOptions.fromDate)return _("from"),!pe.uiOptions.multipleDays&&_("to"),W("from").then(function(){ne("from",!0)}).then(oe)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&Y)}function _(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&o&&r&&(o=P(o).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=P(r).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function $(t,n){return t?(t=h(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):A(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):s.reject([])}function C(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function A(e,n){return e=t(e),s.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function w(){return pe.request?pe.request.request_type:pe.leaveType||null}function P(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function R(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(Q).catch(S)}function D(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function S(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function T(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?Y():R()}function I(){var e=pe.request.attributes();return pe.uiOptions.fromDate=v(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=v(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function O(e){o.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){B("days")||+e==+t||(se(),pe.performBalanceChangeCalculation())})}function L(){me.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){ce()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",Y))}function M(){pe.isMode("edit")&&(pe.isLeaveStatus(u.statusNames.approved)||pe.isLeaveStatus(u.statusNames.adminApproved))&&(fe={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function k(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(D(a.min,n)<=0||D(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function x(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return s.all(e.map(W)).then(function(){["from","to"].forEach(function(e){k(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(se)}function E(){["from","to"].forEach(function(e){O(e),j(e)})}function j(e){o.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){B("days")||t===n||(oe(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function B(e){return pe.selectedAbsenceType.calculation_unit_name===e}function N(e){return pe.request.request_type===e}function F(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return $(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function H(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function W(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(h(t)).then(function(t){ve[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return ve[e]={},S(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):s.resolve()}function V(){return c.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function G(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function Y(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(Q).catch(S).finally(function(){pe.loading.balanceChange=!1})):s.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function J(){return h(pe.request.from_date)===h(pe.request.to_date)}function K(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,X("to"))}function X(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,oe(),se(),ie()}function Q(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=v(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=v(pe.period.end_date)}function ee(){return!pe.isMode("create")&&J()||pe.isMode("create")&&(N("sickness")||B("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,s.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,s=n.multipleDays&&"from"===a?r.max:n.times.to.time,i=ve[a].number_of_hours?D(o,s).toString():"0";r.maxAmount=i,t&&(r.amount=r.maxAmount)}function ae(){fe&&fe.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=fe.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function re(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function oe(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?h(e.fromDate):null,pe.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),B("hours")&&!N("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function se(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ue(){e.forEach(me,function(e){e()})}function ce(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return re(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),s.resolve().then(e&&ee).then(function(){if(e&&B("hours"))return W("from").then(function(){ne("from",!0)})}).then(e&&oe).then(Y)}function le(e){return pe.absenceTypes=e,re(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,X("to")),ae(),Y()}function de(e){var t=P(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(P(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(P(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var fe=null,me=[],pe=this,ve={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=u.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:G},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=v,pe.convertDateToServerFormat=h,pe.dateChangeHandler=g,pe.dateTypeChangeHandler=b,pe.daysSelectionModeChangeHandler=y,pe.isLeaveType=N,pe.isNotWorkingDay=F,pe.performBalanceChangeCalculation=Y,pe.$onDestroy=ue,function(){n("RequestModalDetails"+e.capitalize(w(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",pe),L(),pe.initChildController().then(function(){return s.all([V(),H()])}).then(!pe.isMode("create")&&I).then(ee).then(function(){if(!pe.isMode("create")&&B("hours"))return x().then(oe)}).then(!pe.isMode("create")&&Z).then(M).then(ae).then(T).then(function(){pe.isMode("view")||N("toil")||E()}).catch(S).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?R.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(R.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){R=e})}function A(e){return!e.attachment_id||T.canManage}function w(){e.forEach(D,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var R=[],D=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=w,T.canRemoveAttachment=A,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=v,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",selectedContactId:"<",isSelfRecord:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function v(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function h(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?R(e):n.all([R("table"),R("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function R(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function D(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:M(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:x(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function I(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function O(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function L(e,t,n,a){d.openModal.apply(d,arguments)}function M(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function k(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function x(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=k(n)),n.length)return{IN:n}}function E(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=v,U.getAbsenceTypeByID=h,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=L,U.refresh=E,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),I(),P(),S(),D(),O()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["leave-absences/shared/modules/controllers"],function(e){function t(e,t,n,a){function r(){return a.request.calculateBalanceChange(a.selectedAbsenceType.calculation_unit_name)}function o(){var e=a.request,t=!!e.from_date&&!!e.to_date,n=a.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function s(){return a.canCalculateChange()}function i(){return n.resolve()}t.debug("RequestModalDetailsLeaveController"),a.calculateBalanceChange=r,a.canCalculateChange=o,a.canSubmit=s,a.initChildController=i}e.controller("RequestModalDetailsLeaveController",t),t.$inject=["$controller","$log","$q","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s){function i(){return s.balance.change.amount=+s.request.toil_to_accrue,n.resolve(s.balance.change)}function u(){ +return m().catch(function(e){return e.length&&(s.errors=e),n.reject(e)}).then(function(e){return o.calculateToilExpiryDate(s.request.type_id,e)}).then(function(e){return s.request.toil_expiry_date=e,s.uiOptions.expiryDate=new Date(e),e})}function c(){return!!s.request.toil_to_accrue}function l(){var e=s.uiOptions.multipleDays&&!!s.request.to_date,t=!s.uiOptions.multipleDays&&!!s.request.from_date,n=t||e,a=A.from_date!==s.request.from_date||A.to_date!==s.request.to_date;return s.canDisplayToilExpirationField&&n&&w.hasExpirationFromAdminSettings&&a}function d(){return!!(s.request.from_date&&s.request.to_date&&s.request.toil_duration&&s.request.toil_to_accrue)}function f(){s.request.toil_expiry_date=!1,s.uiOptions.expiryDate=null}function m(){var e=s.uiOptions.multipleDays,t=s.request;return p({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function p(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return n.reject([t])}return e.value?n.resolve(e.value):n.reject([])}function v(){var e=s.isMode("create")&&w.hasExpirationFromAdminSettings,t=w.hasPreviousExpirationDate,n=s.isLeaveType("toil"),a=s.canManage;s.canDisplayToilExpirationField=n&&(a||e||t)}function h(){return w.hasPreviousExpirationDate=s.isMode("edit")&&!!s.request.toil_expiry_date,o.canExpire(s.request.type_id).then(function(e){w.hasExpirationFromAdminSettings=e})}function g(){return s.request.to_date_type=s.request.from_date_type="1",h().then(v).then(b).then(_)}function b(){s.canManage&&(s.uiOptions.expiryDate=s.convertDateFormatFromServer(s.request.toil_expiry_date))}function y(){s.isMode("view")||a.$watch(function(){return s.request.toil_to_accrue},function(e,t){+e!=+t&&s.performBalanceChangeCalculation()})}function _(){return r.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){s.toilAmounts=e.indexBy(t,"value")})}function q(){A=angular.copy(s.request.attributes())}function $(){return l()?u().catch(n.resolve):n.resolve()}function C(){s.uiOptions.expiryDate&&(s.request.toil_expiry_date=s.convertDateToServerFormat(s.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var A,w={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};s.canDisplayToilExpirationField=!1,s.calculateBalanceChange=i,s.canCalculateChange=c,s.canSubmit=d,s.clearExpiryDate=f,s.initChildController=g,s.onDateChangeExtended=$,s.setDaysSelectionModeExtended=$,s.updateExpiryDate=C,function(){y(),q()}()}t.controller("RequestModalDetailsToilController",n),n.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function v(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function h(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?v.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([h.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([h.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={toilDurationHours:"0",toilDurationMinutes:"0",request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},transformAttributes:function(e){var t=Number(e.toil_duration);return t&&(e.toilDurationHours=Math.floor(t/60).toString(),e.toilDurationMinutes=(t%60).toString()),e},updateDuration:function(){this.toil_duration=60*Number(this.toilDurationHours)+Number(this.toilDurationMinutes)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files","toilDurationHours","toilDurationMinutes"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,v,h,g,b,y,_,q,$,C){function A(e){"days"===ke.selectedAbsenceType.calculation_unit_name?delete ke.request[e+"_date_amount"]:delete ke.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=ke.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==ke.request.status_id&&d.publish("ManagerBadge:: Update Count")}function R(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function D(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!ke.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=R();return ke.isMode("edit")&&(e=e&&(V()||D())),ke.canManage&&ke.requestStatuses&&(e=e&&!!ke.getStatusFromValue(ke.newStatusOnSave)),(e=e&&!!ke.period.id)&&!ke.isMode("view")}function I(){ke.isSelfRecord?ke.request.status_id=ke.requestStatuses[_.statusNames.awaitingApproval].value:ke.canManage&&(ke.request.status_id=ke.newStatusOnSave||ke.request.status_id)}function O(){if(ke.isMode("edit")&&!ke.isRole("staff")&&"toil"!==F())return ke.request.calculateBalanceChange(ke.selectedAbsenceType.calculation_unit_name).then(function(e){if(+ke.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function L(){ke.errors=[]}function M(){return ke.request.create().then($e).then(function(){me("LeaveRequest::new")})}function k(){ee()&&!ke.isRole("staff")&&(ke.request.change_balance=!0)}function x(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return ke.request.delete().then(function(){ke.dismissModal(),d.publish("LeaveRequest::delete",ke.request)})}})}function E(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(ke.getStatusFromValue(ke.request.status_id).name)}function N(e){return n.map(Re[e],function(e){return ke.requestStatuses[e]})}function F(){return ke.request?ke.request.request_type:ke.leaveType||null}function U(){return!ke.request||e.equals({},ke.requestStatuses)?[]:ke.request.status_id?B():N("none")}function H(e){return n.find(ke.requestStatuses,function(t){return t.value===e})}function W(e){ke.errors=n.isArray(e)?e:[e],ke.loading.absenceTypes=!1,ke.submitting=!1}function V(){return!e.equals(Se,ke.request.attributes())||ke.canManage&&ke.newStatusOnSave}function G(){return ke.postContactSelection=!0,ke.staffMemberSelectionComplete=!1,ke.request.contact_id?r.resolve().then(ie).then(ue).then(ve).then(ge).then(Z).then(z).then(ke.isMode("edit")?be:n.noop).then(function(){ke.postContactSelection=!1,ke.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Oe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Re.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Re.awaiting_approval=e,Re.more_information_required=e,Re.rejected=e,Re.approved=e,Re.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return ke.canManage?m.find(ke.request.contact_id).then(function(e){ke.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(ve).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",ke.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){De++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function K(){var e,t;ke.request=ke.leaveRequest||null,e=F(),t=ke.initRequestAttributes(),"leave"===e?ke.request=y.init(t):"sickness"===e?ke.request=q.init(t):"toil"===e&&(ke.request=$.init(t))}function X(){var e={};return ke.request?e=ke.request.attributes():ke.canManage||(e={contact_id:Ie}),e}function Q(){if(Le="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Le="admin")}).then(function(){return"staff"===Le&&u(_.permissions.ssp.manage).then(function(e){e&&(Le="manager")})}).finally(function(){ke.canManage=ke.isRole("manager")||ke.isRole("admin")})}function Z(){(ke.isRole("admin")||ke.isMode("create")&&ke.isRole("manager"))&&(ke.newStatusOnSave=ke.requestStatuses[_.statusNames.approved].value)}function ee(){return!ke.request.status_id||!n.includes(["cancelled","rejected"],H(ke.request.status_id).name)}function te(e){var t=ke.getStatusFromValue(ke.request.status_id);return!!t&&t.name===e}function ne(e){return ke.request&&ke.request.request_type===e}function ae(e){return ke.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Le===e}function se(){return v.all().then(function(e){ke.absencePeriods=e})}function ie(){return h.all(j()).then(h.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return ke.loading.entitlements=!0,g.all({contact_id:ke.request.contact_id,period_id:ke.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){ke.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Ie=e.contactId})}function le(){return ke.selectedContactId?m.find(ke.selectedContactId).then(function(e){ke.managedContacts=[e]}):ke.isRole("admin")?m.all().then(function(e){ke.managedContacts=n.remove(e.list,function(e){return e.id!==Ie})}):m.find(Ie).then(function(e){return e.leaveManagees()}).then(function(e){ke.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){ke.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,ke.request),ke.errors=[],ke.dismissModal()}function pe(){["from","to"].forEach(function(e){ke.request[e+"_date"]=Se[e+"_date"]})}function ve(e){if(ke.absenceTypes=fe(Pe.types,e),!ke.absenceTypes.length)return r.reject(Oe)}function he(){ke.period=n.find(ke.absencePeriods,function(e){return ke.isMode("create")?e.current:re(ke.request,e)})}function ge(){ke.isMode("create")?(ke.selectedAbsenceType=ke.absenceTypes[0],ke.request.type_id=ke.selectedAbsenceType.id):ke.selectedAbsenceType=n.find(ke.absenceTypes,function(e){return e.id===ke.request.type_id})}function be(){Se=e.copy(ke.request.attributes())}function ye(){var e;ke.request.id?(e=[ke.requestStatuses[_.statusNames.approved].value,ke.requestStatuses[_.statusNames.adminApproved].value,ke.requestStatuses[_.statusNames.rejected].value,ke.requestStatuses[_.statusNames.cancelled].value],ke.mode="edit",ke.isRole("staff")&&e.indexOf(ke.request.status_id)>-1&&(ke.mode="view")):ke.mode="create"}function _e(){var e=ke.request.status_id;if(!ke.isMode("view")&&!ke.submitting)return ke.submitting=!0,I(),w(),ke.request.isValid().then(ee()&&O).then(k).then(!ke.request.change_balance&&pe).then(qe).then(function(){return ke.isMode("edit")?we():M()}).catch(function(t){ke.request.status_id=e,t&&W(t)}).finally(function(){ke.submitting=!1})}function qe(){return r.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===De&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return De>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return ke.request.update().then($e).then(function(){ke.isRole("manager")?me("LeaveRequest::updatedByManager"):(ke.isRole("staff")||ke.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,Re={},De=0,Se={},Te=[],Ie="",Oe="No entitlement",Le="",Me=[],ke=n.assign(this,f);ke.absencePeriods=[],ke.absenceTypes=[],ke.canManage=!1,ke.contactName=null,ke.errors=[],ke.loading={absenceTypes:!0,entitlements:!0},ke.managedContacts=[],ke.mode="",ke.newStatusOnSave=null,ke.period={},ke.postContactSelection=!1,ke.requestStatuses={},ke.selectedAbsenceType={},ke.staffMemberSelectionComplete=!1,ke.submitting=!1,ke.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},ke.canChangeAbsenceType=S,ke.canSubmit=T,ke.closeAlert=L,ke.deleteLeaveRequest=x,ke.dismissModal=E,ke.getStatuses=U,ke.getStatusFromValue=H,ke.initAfterContactSelection=G,ke.initRequestAttributes=X,ke.isLeaveStatus=te,ke.isLeaveType=ne,ke.isMode=ae,ke.isRole=oe,ke.submit=_e,ke.updateAbsenceType=Ae,function(){ke.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(he).then(function(){return ke.canManage&&!ke.isMode("edit")&&le()}).then(function(){if(ke.selectedContactId&&(ke.request.contact_id=ke.selectedContactId),ke.request.contact_id)return ke.initAfterContactSelection()}).catch(W).finally(function(){ke.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e){define("leave-absences/manager-leave/modules/config",["common/angular","leave-absences/manager-leave/modules/settings"],function(t){return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/manager-leave/requests"),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM), define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","leave-absences/shared/ui-router","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js index c7c7261a4b2..3758089832d 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js @@ -9,5 +9,5 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return V(new(V(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return V({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=V({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),V(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=V({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){V(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){V(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],w={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,V(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(V({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(w,function(e,t){g[t]=new y(V({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(w,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return V(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);V(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,V(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){A.$current.navigable==t&&c(e,n)||A.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=A.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=L[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(A.$current=t,A.current=t.self,A.params=n,W(A.params,m),A.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),A.current)}).then(null,function(a){return a===D?S:A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(A.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},A.is=function(e,t,a){a=V({relative:A.$current},a||{});var r=f(e,a.relative);return j(r)?A.$current===r&&(!t||c(r.params.$$values(t),m)):n},A.includes=function(e,t,a){if(a=V({relative:A.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=A.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(A.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function I(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function x(e,t){return{relative:S(e)||t.$current,inherit:!0}}function O(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=V(x(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=I(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function L(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=I(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function k(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function E(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,V=t.extend,W=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,V(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return f(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(m(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function f(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function m(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

","

People I approve filter displays only staff members who you approve leave for.

","

People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

"].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(L.selectedPeriod.start_date).clone().startOf("month"),a=n(L.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");L.months=e}function p(){s.$new().$watch(function(){return L.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){L.injectMonths=!0,I("injected").then(function(){R(e)}).then(function(){L.loading.calendar=!1})}function v(){x=a("LeaveCalendar"+t.capitalize(O)+"Controller").init(L)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){L.absencePeriods=t.sortBy(e,"start_date"),L.selectedPeriod=t.find(L.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return x.loadContacts().then(function(e){L.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){L.filters.optionValues.regions=e.hrjc_region,L.filters.optionValues.locations=e.hrjc_location,L.filters.optionValues.levelTypes=e.hrjc_level_type,L.filters.optionValues.departments=e.hrjc_department})}function w(){return l.all()}function C(){return r.all([y(),w(),_()]).then(function(e){L.supportData.absenceTypes=e[0],L.supportData.publicHolidays=e[1],L.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,L.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,L.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,L.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return L.injectMonths&&(e=I("destroyed"),L.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){ e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){L.loading.calendar=!0}).then(A).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=L.selectedMonths.length?L.months.filter(function(e){return t.includes(L.selectedMonths,e.index)}):L.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){L.selectedMonths=[n().month()]}function T(){return L.roleOverride?r.resolve().then(function(){O=L.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){O=e[0]?"admin":e[1]?"manager":"staff"})}function I(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===L.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var x,O,L=this;L.absencePeriods=[],L.contacts=[],L.contactIdsToReduceTo=null,L.injectMonths=!1,L.months=[],L.selectedMonths=null,L.selectedPeriod=null,L.showContactName=!1,L.showFilters=!1,L.supportData={},L.loading={calendar:!0,page:!0},L.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},L.labelPeriod=g,L.refresh=D,function(){T().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),C()])}).then(function(){return L.showFilters?$():t.noop}).then(function(){h()}).then(function(){L.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(V.period.start_date)&&r.isSameOrBefore(V.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return V.showOnlyWithLeaveRequests?V.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):V.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){x(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return V.contactIdsToReduceTo&&(V.contacts=V.contacts.filter(function(t){return e.includes(V.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){V.supportData.dayTypes=e.indexBy(V.supportData.dayTypes,"name"),V.supportData.leaveRequestStatuses=e.indexBy(V.supportData.leaveRequestStatuses,"value"),V.supportData.publicHolidays=e.transform(V.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",M)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=V.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function w(e){return!!V.supportData.publicHolidays[p(e).valueOf()]}function C(t){var n=V.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===V.month.index&&r.year()===V.month.year&&a.push(e.find(V.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(V.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function S(){return V.month.loading=!0,a.all([I(),T()]).then(g).then(k).then(function(){N=!0}).then(function(){V.month.loading=!1})}function T(){return s.all({from_date:{to:V.month.days[V.month.days.length-1].date},to_date:{from:V.month.days[0].date},status_id:{IN:R()},contact_id:{IN:V.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(V.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function I(){var t=V.month.days[0].date,n=V.month.days[V.month.days.length-1].date;return o.get(V.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function x(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function O(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function L(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:w(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?C(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function k(){return a.all(V.month.days.map(function(e){return a.all(V.contacts.map(function(t){return L(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===V.month.index})?V.visible=!1:(V.currentPage=0,V.visible=!0,(a||!N)&&S())}function E(t){var n=e.find(V.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(A(e).map(function(t){return L(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},V=this;V.currentPage=0,V.pageSize=20,V.visible=!1,V.showContactName=!!V.showContactName,V.showOnlyWithLeaveRequests=!!V.showOnlyWithLeaveRequests,V.$onDestroy=O,V.contactsList=m,V.getContactUrl=v,function(){var e=t().month(V.month.index).year(V.month.year);b(),_(),V.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=w[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(w,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:w[e].label,isDirectAction:w[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,w={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f,m){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function h(e){return t(e,u.serverDateFormat).toDate()}function v(e){return t(e).format(u.serverDateFormat)}function g(e){var t;return s.resolve().then(function(){X(e),"from"===e&&K(),B("hours")&&(_(e),"from"!==e||pe.uiOptions.multipleDays||_("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return w(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return s.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return W()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(B("hours"))return V(e).then(function(){ne(e,!0)})}).then(function(){if(oe(),!t)return Y();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(S)}function b(){return oe(),Y()}function y(){return pe.uiOptions.toDate=null,X("to"),s.resolve().then(function(){if(B("hours")&&pe.uiOptions.fromDate)return _("from"),!pe.uiOptions.multipleDays&&_("to"),V("from").then(function(){ne("from",!0)}).then(oe)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&Y)}function _(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&o&&r&&(o=P(o).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=P(r).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function $(t,n){return t?(t=v(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):C(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):s.reject([])}function w(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function C(e,n){return e=t(e),s.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function A(){return pe.request?pe.request.request_type:pe.leaveType||null}function P(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(Q).catch(S)}function R(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function S(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function T(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?Y():D()}function I(){var e=pe.request.attributes();return pe.uiOptions.fromDate=h(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=h(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function x(e){o.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){B("days")||+e==+t||(se(),pe.performBalanceChangeCalculation())})}function O(){me.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){ce()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",Y))}function L(){pe.isMode("edit")&&(pe.isLeaveStatus(u.statusNames.approved)||pe.isLeaveStatus(u.statusNames.adminApproved))&&(fe={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function k(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(R(a.min,n)<=0||R(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function M(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return s.all(e.map(V)).then(function(){["from","to"].forEach(function(e){k(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(se)}function E(){["from","to"].forEach(function(e){x(e),j(e)})}function j(e){o.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){B("days")||t===n||(oe(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function B(e){return pe.selectedAbsenceType.calculation_unit_name===e}function N(e){return pe.request.request_type===e}function F(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return $(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function H(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function V(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(v(t)).then(function(t){he[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return he[e]={},S(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):s.resolve()}function W(){return c.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function G(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function Y(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(Q).catch(S).finally(function(){pe.loading.balanceChange=!1})):s.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function J(){return v(pe.request.from_date)===v(pe.request.to_date)}function K(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,X("to"))}function X(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,oe(),se(),ie()}function Q(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=h(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=h(pe.period.end_date)}function ee(){return!pe.isMode("create")&&J()||pe.isMode("create")&&(N("sickness")||B("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,s.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,s=n.multipleDays&&"from"===a?r.max:n.times.to.time,i=he[a].number_of_hours?R(o,s).toString():"0";r.maxAmount=i,t&&(r.amount=r.maxAmount)}function ae(){fe&&fe.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=fe.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function re(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function oe(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?v(e.fromDate):null,pe.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),B("hours")&&!N("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function se(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ue(){e.forEach(me,function(e){e()})}function ce(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return re(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),s.resolve().then(e&&ee).then(function(){if(e&&B("hours"))return V("from").then(function(){ne("from",!0)})}).then(e&&oe).then(Y)}function le(e){return pe.absenceTypes=e,re(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,X("to")),ae(),Y()}function de(e){var t=P(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(P(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(P(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var fe=null,me=[],pe=this,he={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=u.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:G},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=h,pe.convertDateToServerFormat=v,pe.dateChangeHandler=g,pe.dateTypeChangeHandler=b,pe.daysSelectionModeChangeHandler=y,pe.isLeaveType=N,pe.isNotWorkingDay=F,pe.performBalanceChangeCalculation=Y,pe.$onDestroy=ue,function(){n("RequestModalDetails"+e.capitalize(A(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",pe),O(),pe.initChildController().then(function(){return s.all([W(),H()])}).then(!pe.isMode("create")&&I).then(ee).then(function(){if(!pe.isMode("create")&&B("hours"))return M().then(oe)}).then(!pe.isMode("create")&&Z).then(L).then(ae).then(T).then(function(){pe.isMode("view")||N("toil")||E()}).catch(S).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function w(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function C(e){return!e.attachment_id||T.canManage}function A(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=A,T.canRemoveAttachment=C,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=h,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([w(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{ -type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"},{type:"toil",icon:"calendar-plus-o",label:"Overtime"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{btnClass:"@",contactId:"<",selectedContactId:"<",isSelfRecord:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,r,o,s,i,u,c,l,d,f){function m(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),H.sections.other.open&&m(e,H.sections.other)}function h(){Object.values(H.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):H.refresh()}function g(t){t.dataIndex=e.indexBy(t.data,"id")}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function y(){return o.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.selectedPeriod=e.find(H.absencePeriods,function(e){return!0===e.current})})}function _(){return s.all().then(s.loadCalculationUnits).then(function(t){H.absenceTypes=t,H.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return D("approved",{status_id:F(f.statusNames.approved)})}function $(){return n.all([u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,null,!0),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(f.statusNames.approved)]),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(f.statusNames.awaitingApproval),F(f.statusNames.moreInformationRequired)])]).then(function(e){H.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function w(){return i.all({contact_id:H.contactId,period_id:H.selectedPeriod.id},!0).then(function(e){H.entitlements=e}).then(function(){H.absenceTypesFiltered=H.absenceTypes.filter(function(t){var n=e.find(H.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function C(){return i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id},H.entitlements).then(function(){return L(H.entitlements)}).then(function(e){H.sections.entitlements.data=e})}function A(){return n.all([i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id,expired:!0}),P({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:L(e[0]),expiredTOILS:k(e[1].list)})}).then(function(t){H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function P(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function D(e,t){return P(t).then(function(t){H.sections[e].data=t.list})}function R(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(x))}function S(){return D("other",{status_id:{in:[F(f.statusNames.rejected),F(f.statusNames.cancelled)]}})}function T(){return D("pending",{status_id:{in:[F(f.statusNames.awaitingApproval),F(f.statusNames.moreInformationRequired)]}})}function I(){return D("holidays",{public_holiday:!0})}function x(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function O(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function L(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function k(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([w(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([R(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&x(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:E,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:C},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:I},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:T},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([O(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([w(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["leave-absences/shared/modules/controllers"],function(e){function t(e,t,n,a){function r(){return a.request.calculateBalanceChange(a.selectedAbsenceType.calculation_unit_name)}function o(){var e=a.request,t=!!e.from_date&&!!e.to_date,n=a.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function s(){return a.canCalculateChange()}function i(){return n.resolve()}t.debug("RequestModalDetailsLeaveController"),a.calculateBalanceChange=r,a.canCalculateChange=o,a.canSubmit=s,a.initChildController=i}e.controller("RequestModalDetailsLeaveController",t),t.$inject=["$controller","$log","$q","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s){function i(){return s.balance.change.amount=+s.request.toil_to_accrue,n.resolve(s.balance.change)}function u(){return m().catch(function(e){return e.length&&(s.errors=e),n.reject(e)}).then(function(e){return o.calculateToilExpiryDate(s.request.type_id,e)}).then(function(e){return s.request.toil_expiry_date=e,s.uiOptions.expiryDate=new Date(e),e})}function c(){return!!s.request.toil_to_accrue}function l(){var e=s.uiOptions.multipleDays&&!!s.request.to_date,t=!s.uiOptions.multipleDays&&!!s.request.from_date,n=t||e,a=C.from_date!==s.request.from_date||C.to_date!==s.request.to_date;return s.canDisplayToilExpirationField&&n&&A.hasExpirationFromAdminSettings&&a}function d(){return!!(s.request.from_date&&s.request.to_date&&s.request.toil_duration&&s.request.toil_to_accrue)}function f(){s.request.toil_expiry_date=!1,s.uiOptions.expiryDate=null}function m(){var e=s.uiOptions.multipleDays,t=s.request;return p({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function p(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return n.reject([t])}return e.value?n.resolve(e.value):n.reject([])}function h(){var e=s.isMode("create")&&A.hasExpirationFromAdminSettings,t=A.hasPreviousExpirationDate,n=s.isLeaveType("toil"),a=s.canManage;s.canDisplayToilExpirationField=n&&(a||e||t)}function v(){return A.hasPreviousExpirationDate=s.isMode("edit")&&!!s.request.toil_expiry_date,o.canExpire(s.request.type_id).then(function(e){A.hasExpirationFromAdminSettings=e})}function g(){return s.request.to_date_type=s.request.from_date_type="1",v().then(h).then(b).then(_)}function b(){s.canManage&&(s.uiOptions.expiryDate=s.convertDateFormatFromServer(s.request.toil_expiry_date))}function y(){s.isMode("view")||a.$watch(function(){return s.request.toil_to_accrue},function(e,t){+e!=+t&&s.performBalanceChangeCalculation()})}function _(){return r.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){s.toilAmounts=e.indexBy(t,"value")})}function q(){C=angular.copy(s.request.attributes())}function $(){return l()?u().catch(n.resolve):n.resolve()}function w(){s.uiOptions.expiryDate&&(s.request.toil_expiry_date=s.convertDateToServerFormat(s.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var C,A={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};s.canDisplayToilExpirationField=!1,s.calculateBalanceChange=i,s.canCalculateChange=c,s.canSubmit=d,s.clearExpiryDate=f,s.initChildController=g,s.onDateChangeExtended=$,s.setDaysSelectionModeExtended=$,s.updateExpiryDate=w,function(){y(),q()}()}t.controller("RequestModalDetailsToilController",n),n.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={toilDurationHours:"0",toilDurationMinutes:"0",request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},transformAttributes:function(e){var t=Number(e.toil_duration);return t&&(e.toilDurationHours=Math.floor(t/60).toString(),e.toilDurationMinutes=(t%60).toString()),e},updateDuration:function(){this.toil_duration=60*Number(this.toilDurationHours)+Number(this.toilDurationMinutes)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files","toilDurationHours","toilDurationMinutes"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,w){function C(e){"days"===ke.selectedAbsenceType.calculation_unit_name?delete ke.request[e+"_date_amount"]:delete ke.request[e+"_date_type"]}function A(){["from","to"].forEach(C)}function P(){var e=ke.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==ke.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Le.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Le.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!ke.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return ke.isMode("edit")&&(e=e&&(W()||R())),ke.canManage&&ke.requestStatuses&&(e=e&&!!ke.getStatusFromValue(ke.newStatusOnSave)),(e=e&&!!ke.period.id)&&!ke.isMode("view")}function I(){ke.isSelfRecord?ke.request.status_id=ke.requestStatuses[_.statusNames.awaitingApproval].value:ke.canManage&&(ke.request.status_id=ke.newStatusOnSave||ke.request.status_id)}function x(){if(ke.isMode("edit")&&!ke.isRole("staff")&&"toil"!==F())return ke.request.calculateBalanceChange(ke.selectedAbsenceType.calculation_unit_name).then(function(e){if(+ke.balance.change.amount!=+e.amount)return w.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function O(){ke.errors=[]}function L(){return ke.request.create().then($e).then(function(){me("LeaveRequest::new")})}function k(){ee()&&!ke.isRole("staff")&&(ke.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return ke.request.delete().then(function(){ke.dismissModal(),d.publish("LeaveRequest::delete",ke.request)})}})}function E(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(ke.getStatusFromValue(ke.request.status_id).name)}function N(e){return n.map(De[e],function(e){return ke.requestStatuses[e]})}function F(){return ke.request?ke.request.request_type:ke.leaveType||null}function U(){return!ke.request||e.equals({},ke.requestStatuses)?[]:ke.request.status_id?B():N("none")}function H(e){return n.find(ke.requestStatuses,function(t){return t.value===e})}function V(e){ke.errors=n.isArray(e)?e:[e],ke.loading.absenceTypes=!1,ke.submitting=!1}function W(){return!e.equals(Se,ke.request.attributes())||ke.canManage&&ke.newStatusOnSave}function G(){return ke.postContactSelection=!0,ke.staffMemberSelectionComplete=!1,ke.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(ke.isMode("edit")?be:n.noop).then(function(){ke.postContactSelection=!1,ke.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==xe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return ke.canManage?m.find(ke.request.contact_id).then(function(e){ke.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",ke.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){V(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",we),s.$on("LeaveRequestPopup::addTab",function(e,t){Le.push(t)})}function K(){var e,t;ke.request=ke.leaveRequest||null,e=F(),t=ke.initRequestAttributes(),"leave"===e?ke.request=y.init(t):"sickness"===e?ke.request=q.init(t):"toil"===e&&(ke.request=$.init(t))}function X(){var e={};return ke.request?e=ke.request.attributes():ke.canManage||(e={contact_id:Ie}),e}function Q(){if(Oe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Oe="admin")}).then(function(){return"staff"===Oe&&u(_.permissions.ssp.manage).then(function(e){e&&(Oe="manager")})}).finally(function(){ke.canManage=ke.isRole("manager")||ke.isRole("admin")})}function Z(){(ke.isRole("admin")||ke.isMode("create")&&ke.isRole("manager"))&&(ke.newStatusOnSave=ke.requestStatuses[_.statusNames.approved].value)}function ee(){return!ke.request.status_id||!n.includes(["cancelled","rejected"],H(ke.request.status_id).name)}function te(e){var t=ke.getStatusFromValue(ke.request.status_id);return!!t&&t.name===e}function ne(e){return ke.request&&ke.request.request_type===e}function ae(e){return ke.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Oe===e}function se(){return h.all().then(function(e){ke.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return ke.loading.entitlements=!0,g.all({contact_id:ke.request.contact_id,period_id:ke.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){ke.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Ie=e.contactId})}function le(){return ke.selectedContactId?m.find(ke.selectedContactId).then(function(e){ke.managedContacts=[e]}):ke.isRole("admin")?m.all().then(function(e){ke.managedContacts=n.remove(e.list,function(e){return e.id!==Ie})}):m.find(Ie).then(function(e){return e.leaveManagees()}).then(function(e){ke.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){ke.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,ke.request),ke.errors=[],ke.dismissModal()}function pe(){["from","to"].forEach(function(e){ke.request[e+"_date"]=Se[e+"_date"]})}function he(e){if(ke.absenceTypes=fe(Pe.types,e),!ke.absenceTypes.length)return r.reject(xe)}function ve(){ke.period=n.find(ke.absencePeriods,function(e){return ke.isMode("create")?e.current:re(ke.request,e)})}function ge(){ke.isMode("create")?(ke.selectedAbsenceType=ke.absenceTypes[0],ke.request.type_id=ke.selectedAbsenceType.id):ke.selectedAbsenceType=n.find(ke.absenceTypes,function(e){return e.id===ke.request.type_id})}function be(){Se=e.copy(ke.request.attributes())}function ye(){var e;ke.request.id?(e=[ke.requestStatuses[_.statusNames.approved].value,ke.requestStatuses[_.statusNames.adminApproved].value,ke.requestStatuses[_.statusNames.rejected].value,ke.requestStatuses[_.statusNames.cancelled].value],ke.mode="edit",ke.isRole("staff")&&e.indexOf(ke.request.status_id)>-1&&(ke.mode="view")):ke.mode="create"}function _e(){var e=ke.request.status_id;if(!ke.isMode("view")&&!ke.submitting)return ke.submitting=!0,I(),A(),ke.request.isValid().then(ee()&&x).then(k).then(!ke.request.change_balance&&pe).then(qe).then(function(){return ke.isMode("edit")?Ae():L()}).catch(function(t){ke.request.status_id=e,t&&V(t)}).finally(function(){ke.submitting=!1})}function qe(){return r.all(Le.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function we(){Te.forEach(function(e){e()})}function Ce(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return ke.request.update().then($e).then(function(){ke.isRole("manager")?me("LeaveRequest::updatedByManager"):(ke.isRole("staff")||ke.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Ie="",xe="No entitlement",Oe="",Le=[],ke=n.assign(this,f);ke.absencePeriods=[],ke.absenceTypes=[],ke.canManage=!1,ke.contactName=null,ke.errors=[],ke.loading={absenceTypes:!0,entitlements:!0},ke.managedContacts=[],ke.mode="",ke.newStatusOnSave=null,ke.period={},ke.postContactSelection=!1,ke.requestStatuses={},ke.selectedAbsenceType={},ke.staffMemberSelectionComplete=!1,ke.submitting=!1,ke.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},ke.canChangeAbsenceType=S,ke.canSubmit=T,ke.closeAlert=O,ke.deleteLeaveRequest=M,ke.dismissModal=E,ke.getStatuses=U,ke.getStatusFromValue=H,ke.initAfterContactSelection=G,ke.initRequestAttributes=X,ke.isLeaveStatus=te,ke.isLeaveType=ne,ke.isMode=ae,ke.isRole=oe,ke.submit=_e,ke.updateAbsenceType=Ce,function(){ke.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return ke.canManage&&!ke.isMode("edit")&&le()}).then(function(){if(ke.selectedContactId&&(ke.request.contact_id=ke.selectedContactId),ke.request.contact_id)return ke.initAfterContactSelection()}).catch(V).finally(function(){ke.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM),define("leave-absences/my-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/models/option-group","common/modules/dialog","common/services/check-permissions","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/my-leave/components/my-leave-container.component","leave-absences/my-leave/modules/config"],function(e){return e.module("my-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.mocks","common.models","common.services","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","my-leave.components","my-leave.config"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/my-leave":n+"/my-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/my-leave/app"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-my-leave]"),["my-leave"])})})}(CRM,require),define("my-leave",function(){}); +type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",selectedContactId:"<",isSelfRecord:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,r,o,s,i,u,c,l,d,f){function m(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),H.sections.other.open&&m(e,H.sections.other)}function h(){Object.values(H.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):H.refresh()}function g(t){t.dataIndex=e.indexBy(t.data,"id")}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function y(){return o.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.selectedPeriod=e.find(H.absencePeriods,function(e){return!0===e.current})})}function _(){return s.all().then(s.loadCalculationUnits).then(function(t){H.absenceTypes=t,H.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return D("approved",{status_id:F(f.statusNames.approved)})}function $(){return n.all([u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,null,!0),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(f.statusNames.approved)]),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(f.statusNames.awaitingApproval),F(f.statusNames.moreInformationRequired)])]).then(function(e){H.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function w(){return i.all({contact_id:H.contactId,period_id:H.selectedPeriod.id},!0).then(function(e){H.entitlements=e}).then(function(){H.absenceTypesFiltered=H.absenceTypes.filter(function(t){var n=e.find(H.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function C(){return i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id},H.entitlements).then(function(){return L(H.entitlements)}).then(function(e){H.sections.entitlements.data=e})}function A(){return n.all([i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id,expired:!0}),P({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:L(e[0]),expiredTOILS:k(e[1].list)})}).then(function(t){H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function P(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function D(e,t){return P(t).then(function(t){H.sections[e].data=t.list})}function R(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(x))}function S(){return D("other",{status_id:{in:[F(f.statusNames.rejected),F(f.statusNames.cancelled)]}})}function T(){return D("pending",{status_id:{in:[F(f.statusNames.awaitingApproval),F(f.statusNames.moreInformationRequired)]}})}function I(){return D("holidays",{public_holiday:!0})}function x(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function O(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function L(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function k(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([w(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([R(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&x(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:E,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:C},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:I},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:T},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([O(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([w(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["leave-absences/shared/modules/controllers"],function(e){function t(e,t,n,a){function r(){return a.request.calculateBalanceChange(a.selectedAbsenceType.calculation_unit_name)}function o(){var e=a.request,t=!!e.from_date&&!!e.to_date,n=a.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function s(){return a.canCalculateChange()}function i(){return n.resolve()}t.debug("RequestModalDetailsLeaveController"),a.calculateBalanceChange=r,a.canCalculateChange=o,a.canSubmit=s,a.initChildController=i}e.controller("RequestModalDetailsLeaveController",t),t.$inject=["$controller","$log","$q","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s){function i(){return s.balance.change.amount=+s.request.toil_to_accrue,n.resolve(s.balance.change)}function u(){return m().catch(function(e){return e.length&&(s.errors=e),n.reject(e)}).then(function(e){return o.calculateToilExpiryDate(s.request.type_id,e)}).then(function(e){return s.request.toil_expiry_date=e,s.uiOptions.expiryDate=new Date(e),e})}function c(){return!!s.request.toil_to_accrue}function l(){var e=s.uiOptions.multipleDays&&!!s.request.to_date,t=!s.uiOptions.multipleDays&&!!s.request.from_date,n=t||e,a=C.from_date!==s.request.from_date||C.to_date!==s.request.to_date;return s.canDisplayToilExpirationField&&n&&A.hasExpirationFromAdminSettings&&a}function d(){return!!(s.request.from_date&&s.request.to_date&&s.request.toil_duration&&s.request.toil_to_accrue)}function f(){s.request.toil_expiry_date=!1,s.uiOptions.expiryDate=null}function m(){var e=s.uiOptions.multipleDays,t=s.request;return p({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function p(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return n.reject([t])}return e.value?n.resolve(e.value):n.reject([])}function h(){var e=s.isMode("create")&&A.hasExpirationFromAdminSettings,t=A.hasPreviousExpirationDate,n=s.isLeaveType("toil"),a=s.canManage;s.canDisplayToilExpirationField=n&&(a||e||t)}function v(){return A.hasPreviousExpirationDate=s.isMode("edit")&&!!s.request.toil_expiry_date,o.canExpire(s.request.type_id).then(function(e){A.hasExpirationFromAdminSettings=e})}function g(){return s.request.to_date_type=s.request.from_date_type="1",v().then(h).then(b).then(_)}function b(){s.canManage&&(s.uiOptions.expiryDate=s.convertDateFormatFromServer(s.request.toil_expiry_date))}function y(){s.isMode("view")||a.$watch(function(){return s.request.toil_to_accrue},function(e,t){+e!=+t&&s.performBalanceChangeCalculation()})}function _(){return r.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){s.toilAmounts=e.indexBy(t,"value")})}function q(){C=angular.copy(s.request.attributes())}function $(){return l()?u().catch(n.resolve):n.resolve()}function w(){s.uiOptions.expiryDate&&(s.request.toil_expiry_date=s.convertDateToServerFormat(s.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var C,A={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};s.canDisplayToilExpirationField=!1,s.calculateBalanceChange=i,s.canCalculateChange=c,s.canSubmit=d,s.clearExpiryDate=f,s.initChildController=g,s.onDateChangeExtended=$,s.setDaysSelectionModeExtended=$,s.updateExpiryDate=w,function(){y(),q()}()}t.controller("RequestModalDetailsToilController",n),n.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={toilDurationHours:"0",toilDurationMinutes:"0",request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},transformAttributes:function(e){var t=Number(e.toil_duration);return t&&(e.toilDurationHours=Math.floor(t/60).toString(),e.toilDurationMinutes=(t%60).toString()),e},updateDuration:function(){this.toil_duration=60*Number(this.toilDurationHours)+Number(this.toilDurationMinutes)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files","toilDurationHours","toilDurationMinutes"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,w){function C(e){"days"===ke.selectedAbsenceType.calculation_unit_name?delete ke.request[e+"_date_amount"]:delete ke.request[e+"_date_type"]}function A(){["from","to"].forEach(C)}function P(){var e=ke.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==ke.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Le.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Le.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!ke.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return ke.isMode("edit")&&(e=e&&(W()||R())),ke.canManage&&ke.requestStatuses&&(e=e&&!!ke.getStatusFromValue(ke.newStatusOnSave)),(e=e&&!!ke.period.id)&&!ke.isMode("view")}function I(){ke.isSelfRecord?ke.request.status_id=ke.requestStatuses[_.statusNames.awaitingApproval].value:ke.canManage&&(ke.request.status_id=ke.newStatusOnSave||ke.request.status_id)}function x(){if(ke.isMode("edit")&&!ke.isRole("staff")&&"toil"!==F())return ke.request.calculateBalanceChange(ke.selectedAbsenceType.calculation_unit_name).then(function(e){if(+ke.balance.change.amount!=+e.amount)return w.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function O(){ke.errors=[]}function L(){return ke.request.create().then($e).then(function(){me("LeaveRequest::new")})}function k(){ee()&&!ke.isRole("staff")&&(ke.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return ke.request.delete().then(function(){ke.dismissModal(),d.publish("LeaveRequest::delete",ke.request)})}})}function E(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(ke.getStatusFromValue(ke.request.status_id).name)}function N(e){return n.map(De[e],function(e){return ke.requestStatuses[e]})}function F(){return ke.request?ke.request.request_type:ke.leaveType||null}function U(){return!ke.request||e.equals({},ke.requestStatuses)?[]:ke.request.status_id?B():N("none")}function H(e){return n.find(ke.requestStatuses,function(t){return t.value===e})}function V(e){ke.errors=n.isArray(e)?e:[e],ke.loading.absenceTypes=!1,ke.submitting=!1}function W(){return!e.equals(Se,ke.request.attributes())||ke.canManage&&ke.newStatusOnSave}function G(){return ke.postContactSelection=!0,ke.staffMemberSelectionComplete=!1,ke.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(ke.isMode("edit")?be:n.noop).then(function(){ke.postContactSelection=!1,ke.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==xe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return ke.canManage?m.find(ke.request.contact_id).then(function(e){ke.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",ke.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){V(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",we),s.$on("LeaveRequestPopup::addTab",function(e,t){Le.push(t)})}function K(){var e,t;ke.request=ke.leaveRequest||null,e=F(),t=ke.initRequestAttributes(),"leave"===e?ke.request=y.init(t):"sickness"===e?ke.request=q.init(t):"toil"===e&&(ke.request=$.init(t))}function X(){var e={};return ke.request?e=ke.request.attributes():ke.canManage||(e={contact_id:Ie}),e}function Q(){if(Oe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Oe="admin")}).then(function(){return"staff"===Oe&&u(_.permissions.ssp.manage).then(function(e){e&&(Oe="manager")})}).finally(function(){ke.canManage=ke.isRole("manager")||ke.isRole("admin")})}function Z(){(ke.isRole("admin")||ke.isMode("create")&&ke.isRole("manager"))&&(ke.newStatusOnSave=ke.requestStatuses[_.statusNames.approved].value)}function ee(){return!ke.request.status_id||!n.includes(["cancelled","rejected"],H(ke.request.status_id).name)}function te(e){var t=ke.getStatusFromValue(ke.request.status_id);return!!t&&t.name===e}function ne(e){return ke.request&&ke.request.request_type===e}function ae(e){return ke.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Oe===e}function se(){return h.all().then(function(e){ke.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return ke.loading.entitlements=!0,g.all({contact_id:ke.request.contact_id,period_id:ke.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){ke.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Ie=e.contactId})}function le(){return ke.selectedContactId?m.find(ke.selectedContactId).then(function(e){ke.managedContacts=[e]}):ke.isRole("admin")?m.all().then(function(e){ke.managedContacts=n.remove(e.list,function(e){return e.id!==Ie})}):m.find(Ie).then(function(e){return e.leaveManagees()}).then(function(e){ke.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){ke.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,ke.request),ke.errors=[],ke.dismissModal()}function pe(){["from","to"].forEach(function(e){ke.request[e+"_date"]=Se[e+"_date"]})}function he(e){if(ke.absenceTypes=fe(Pe.types,e),!ke.absenceTypes.length)return r.reject(xe)}function ve(){ke.period=n.find(ke.absencePeriods,function(e){return ke.isMode("create")?e.current:re(ke.request,e)})}function ge(){ke.isMode("create")?(ke.selectedAbsenceType=ke.absenceTypes[0],ke.request.type_id=ke.selectedAbsenceType.id):ke.selectedAbsenceType=n.find(ke.absenceTypes,function(e){return e.id===ke.request.type_id})}function be(){Se=e.copy(ke.request.attributes())}function ye(){var e;ke.request.id?(e=[ke.requestStatuses[_.statusNames.approved].value,ke.requestStatuses[_.statusNames.adminApproved].value,ke.requestStatuses[_.statusNames.rejected].value,ke.requestStatuses[_.statusNames.cancelled].value],ke.mode="edit",ke.isRole("staff")&&e.indexOf(ke.request.status_id)>-1&&(ke.mode="view")):ke.mode="create"}function _e(){var e=ke.request.status_id;if(!ke.isMode("view")&&!ke.submitting)return ke.submitting=!0,I(),A(),ke.request.isValid().then(ee()&&x).then(k).then(!ke.request.change_balance&&pe).then(qe).then(function(){return ke.isMode("edit")?Ae():L()}).catch(function(t){ke.request.status_id=e,t&&V(t)}).finally(function(){ke.submitting=!1})}function qe(){return r.all(Le.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function we(){Te.forEach(function(e){e()})}function Ce(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return ke.request.update().then($e).then(function(){ke.isRole("manager")?me("LeaveRequest::updatedByManager"):(ke.isRole("staff")||ke.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Ie="",xe="No entitlement",Oe="",Le=[],ke=n.assign(this,f);ke.absencePeriods=[],ke.absenceTypes=[],ke.canManage=!1,ke.contactName=null,ke.errors=[],ke.loading={absenceTypes:!0,entitlements:!0},ke.managedContacts=[],ke.mode="",ke.newStatusOnSave=null,ke.period={},ke.postContactSelection=!1,ke.requestStatuses={},ke.selectedAbsenceType={},ke.staffMemberSelectionComplete=!1,ke.submitting=!1,ke.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},ke.canChangeAbsenceType=S,ke.canSubmit=T,ke.closeAlert=O,ke.deleteLeaveRequest=M,ke.dismissModal=E,ke.getStatuses=U,ke.getStatusFromValue=H,ke.initAfterContactSelection=G,ke.initRequestAttributes=X,ke.isLeaveStatus=te,ke.isLeaveType=ne,ke.isMode=ae,ke.isRole=oe,ke.submit=_e,ke.updateAbsenceType=Ce,function(){ke.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return ke.canManage&&!ke.isMode("edit")&&le()}).then(function(){if(ke.selectedContactId&&(ke.request.contact_id=ke.selectedContactId),ke.request.contact_id)return ke.initAfterContactSelection()}).catch(V).finally(function(){ke.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM),define("leave-absences/my-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/models/option-group","common/modules/dialog","common/services/check-permissions","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/my-leave/components/my-leave-container.component","leave-absences/my-leave/modules/config"],function(e){return e.module("my-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.mocks","common.models","common.services","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","my-leave.components","my-leave.config"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/my-leave":n+"/my-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/my-leave/app"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-my-leave]"),["my-leave"])})})}(CRM,require),define("my-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-record-actions.component.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-record-actions.component.js index a913af5cbcb..638441ccb48 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-record-actions.component.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-record-actions.component.js @@ -7,7 +7,6 @@ define([ ], function (components) { components.component('leaveRequestRecordActions', { bindings: { - btnClass: '@', contactId: '<', selectedContactId: '<', isSelfRecord: '<' @@ -27,8 +26,7 @@ define([ vm.leaveRequestOptions = [ { type: 'leave', icon: 'briefcase', label: 'Leave' }, - { type: 'sickness', icon: 'stethoscope', label: 'Sickness' }, - { type: 'toil', icon: 'calendar-plus-o', label: 'Overtime' } + { type: 'sickness', icon: 'stethoscope', label: 'Sickness' } ]; vm.openLeavePopup = openLeavePopup; diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-request-record-actions.component.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-request-record-actions.component.spec.js index 74cb56f24ca..7888174f7bb 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-request-record-actions.component.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-request-record-actions.component.spec.js @@ -37,7 +37,7 @@ define([ return option.type; }); - expect(options).toEqual(['leave', 'sickness', 'toil']); + expect(options).toEqual(['leave', 'sickness']); }); }); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave-request-record-actions.scss b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave-request-record-actions.scss new file mode 100644 index 00000000000..3004229de9e --- /dev/null +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave-request-record-actions.scss @@ -0,0 +1,34 @@ +leave-request-record-actions { + display: block; + margin-bottom: $crm-panel-nested-indent; + + .fa, + .btn-group { + margin-right: $crm-gap-medium; + } +} + +leave-request-record-actions .btn-toolbar { + margin-left: 0; + overflow: inherit; + + .btn-group, + .btn { + margin-left: 0; + } +} + +@media screen and (max-width: $screen-xs-max) { + leave-request-record-actions { + .btn-group, + .btn { + display: block; + width: 100%; + } + + .btn-group { + margin-bottom: $crm-gap-medium; + margin-right: 0; + } + } +} diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave.scss b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave.scss index 2788714152a..6f4c41aa631 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave.scss +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave.scss @@ -4,7 +4,7 @@ $leave-taller-input-height: 40px; margin-right: 5px; position: relative; top: 1px; - width: calc(100% - 80px); + width: 100%; select { height: $leave-taller-input-height; @@ -15,18 +15,3 @@ $leave-taller-input-height: 40px; width: $leave-taller-input-height; } } - -leave-request-record-actions { - .dropdown-menu { - left: auto; - right: 0; - } - - .dropdown-toggle { - height: $leave-taller-input-height; - } - - i.fa { - margin-right: 8px; - } -} diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_absence-tab-page.scss b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_absence-tab-page.scss index 6787c3be2d1..656300104a6 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_absence-tab-page.scss +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_absence-tab-page.scss @@ -1,12 +1,4 @@ .absence-tab-page { - .btn-group { - margin-bottom: 20px; - - > .btn { - border-color: transparent !important; - } - } - .tab-pane { padding: 0 !important; } @@ -14,4 +6,8 @@ .tab-content { background-color: transparent !important; } + + leave-request-record-actions { + margin-bottom: 20px; + } } diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_admin-dashboard-page.scss b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_admin-dashboard-page.scss index 7486864d8e1..310180921de 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_admin-dashboard-page.scss +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_admin-dashboard-page.scss @@ -3,7 +3,9 @@ $content-container-margin: 16px; @at-root { .page-civicrm-leaveandabsences-dashboard { - h1.page-title, + + /* stylelint-disable selector-max-id */ + .page-title, #branding { display: none !important; } @@ -12,6 +14,7 @@ $content-container-margin: 16px; margin: 0; padding: 0; } + /* stylelint-enable */ } .admin-dashboard-page { @@ -19,33 +22,29 @@ $content-container-margin: 16px; .crm_page__topbar { height: 65px; + } - .dropdown-toggle { - margin: 15px 30px 0 0 !important; - - +ul { - margin-right: 30px !important; - } - } + leave-request-record-actions { + margin: 12px 30px 0 0; } .chr_admin-dashboard_side-nav { + background-color: $crm-white; + height: calc(100% - 12px); overflow: hidden; - width: $navigation-column-width; position: absolute; - height: calc(100% - 12px); - background-color: $crm-white; + width: $navigation-column-width; - li.active { + .active { background: $gray-light; } } .chr_admin-dashboard_content { float: right; - width: calc(100% - #{$navigation-column-width} - #{$content-container-margin} * 2); margin: $content-container-margin; margin-bottom: 0; + width: calc(100% - #{$navigation-column-width} - #{$content-container-margin} * 2); } } } diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-record-actions.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-record-actions.html index d17bf608bd7..13bea9c9691 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-record-actions.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-record-actions.html @@ -1,14 +1,26 @@ -
- + +
+ -
From 8189ea1cd1a784939845408a9e595dc3b8d4fc39 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Tue, 20 Mar 2018 17:01:42 +0000 Subject: [PATCH 060/203] PCHR-3426: Fix work pattern tab layout --- .../absence-tab/components/absence-tab-work-patterns.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/absence-tab/components/absence-tab-work-patterns.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/absence-tab/components/absence-tab-work-patterns.html index 1841e0ae6b5..77106b7ed35 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/absence-tab/components/absence-tab-work-patterns.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/absence-tab/components/absence-tab-work-patterns.html @@ -1,8 +1,8 @@ -
+

-

+

From a06a7d10d1b9ccf3d496dd873f95479da6bcdfda Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Tue, 20 Mar 2018 17:34:37 +0000 Subject: [PATCH 061/203] PCHR-3426: Improve components positions --- .../css/leaveandabsence.css | 2 +- .../scss/components/_leave-request-record-actions.scss | 1 - .../scss/pages/_absence-tab-page.scss | 2 +- .../scss/pages/_admin-dashboard-page.scss | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/css/leaveandabsence.css b/uk.co.compucorp.civicrm.hrleaveandabsences/css/leaveandabsence.css index 3f0b2ede710..e7827dc794f 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/css/leaveandabsence.css +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/css/leaveandabsence.css @@ -1 +1 @@ -#bootstrap-theme .chr_disabled{opacity:0.5;pointer-events:none}#bootstrap-theme .table-condensed>thead>tr>th{background:#fff !important;padding:8px 5px}#bootstrap-theme .table-condensed-mixed>thead>tr>th,#bootstrap-theme .table-condensed-mixed>thead>tr>td,#bootstrap-theme .table-condensed-mixed>tbody>tr>th,#bootstrap-theme .table-condensed-mixed>tbody>tr>td{padding-left:5px;padding-right:5px}#bootstrap-theme .table-condensed>tbody>tr>td:first-child,#bootstrap-theme .table-condensed>tbody>tr>th:first-child,#bootstrap-theme .table-condensed>thead>tr>td:first-child,#bootstrap-theme .table-condensed>thead>tr>th:first-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>td:first-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>th:first-child,#bootstrap-theme .table-condensed-mixed>thead>tr>td:first-child,#bootstrap-theme .table-condensed-mixed>thead>tr>th:first-child{padding-left:20px}#bootstrap-theme .table-condensed>tbody>tr>td:last-child,#bootstrap-theme .table-condensed>tbody>tr>th:last-child,#bootstrap-theme .table-condensed>thead>tr>td:last-child,#bootstrap-theme .table-condensed>thead>tr>th:last-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>td:last-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>th:last-child,#bootstrap-theme .table-condensed-mixed>thead>tr>td:last-child,#bootstrap-theme .table-condensed-mixed>thead>tr>th:last-child{padding-right:20px}#bootstrap-theme .table-nested{overflow-y:hidden;position:relative}#bootstrap-theme .table-nested:before{box-shadow:inset 0px 6px 9px -6px rgba(0,0,0,0.2);content:'';display:block;height:10px;left:0;position:absolute;top:0;width:100%;z-index:10}#bootstrap-theme .table-nested:after{box-shadow:inset 0px -4px 9px -6px rgba(0,0,0,0.2);content:'';display:block;height:10px;left:0;position:absolute;bottom:0;width:100%;z-index:10}#bootstrap-theme .table-nested>table,#bootstrap-theme .table-nested>.table{background-color:#fff}#bootstrap-theme .table-nested>table>tbody>tr>td:first-child,#bootstrap-theme .table-nested>table>tbody>tr>th:first-child,#bootstrap-theme .table-nested>table>thead>tr>td:first-child,#bootstrap-theme .table-nested>table>thead>tr>th:first-child,#bootstrap-theme .table-nested>.table>tbody>tr>td:first-child,#bootstrap-theme .table-nested>.table>tbody>tr>th:first-child,#bootstrap-theme .table-nested>.table>thead>tr>td:first-child,#bootstrap-theme .table-nested>.table>thead>tr>th:first-child{padding-left:30px;position:relative}#bootstrap-theme .table-nested>table>tbody>tr>td:first-child:before,#bootstrap-theme .table-nested>table>tbody>tr>th:first-child:before,#bootstrap-theme .table-nested>table>thead>tr>td:first-child:before,#bootstrap-theme .table-nested>table>thead>tr>th:first-child:before,#bootstrap-theme .table-nested>.table>tbody>tr>td:first-child:before,#bootstrap-theme .table-nested>.table>tbody>tr>th:first-child:before,#bootstrap-theme .table-nested>.table>thead>tr>td:first-child:before,#bootstrap-theme .table-nested>.table>thead>tr>th:first-child:before{background:#c2cfd8;content:'';display:block;height:110%;left:0;position:absolute;top:0;width:10px;z-index:2}#bootstrap-theme .table-nested>table>tbody>tr>td:last-child,#bootstrap-theme .table-nested>table>tbody>tr>th:last-child,#bootstrap-theme .table-nested>table>thead>tr>td:last-child,#bootstrap-theme .table-nested>table>thead>tr>th:last-child,#bootstrap-theme .table-nested>.table>tbody>tr>td:last-child,#bootstrap-theme .table-nested>.table>tbody>tr>th:last-child,#bootstrap-theme .table-nested>.table>thead>tr>td:last-child,#bootstrap-theme .table-nested>.table>thead>tr>th:last-child{padding-right:30px;position:relative}#bootstrap-theme .table-nested>table>tbody>tr>td:last-child:after,#bootstrap-theme .table-nested>table>tbody>tr>th:last-child:after,#bootstrap-theme .table-nested>table>thead>tr>td:last-child:after,#bootstrap-theme .table-nested>table>thead>tr>th:last-child:after,#bootstrap-theme .table-nested>.table>tbody>tr>td:last-child:after,#bootstrap-theme .table-nested>.table>tbody>tr>th:last-child:after,#bootstrap-theme .table-nested>.table>thead>tr>td:last-child:after,#bootstrap-theme .table-nested>.table>thead>tr>th:last-child:after{background:#c2cfd8;content:'';display:block;height:110%;right:0;position:absolute;top:0;width:10px;z-index:2}@media screen and (max-width: 767px){#bootstrap-theme .table-nested.table-responsive{border:0;margin-bottom:0}}#bootstrap-theme .table-nested-cell{padding:0 !important}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(1){width:40%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(2){width:15%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(3){width:35%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(4){width:10%}#bootstrap-theme .chr_absence-work-pattern__work-pattern-listing{display:inline-block}#bootstrap-theme .chr_absence-work-pattern__alert{margin-bottom:0 !important}#bootstrap-theme .annual-entitlement-change-log-component thead td{min-width:100px}#bootstrap-theme .annual-entitlement-change-log-component thead .annual-entitlement-change-log-component__comments{min-width:300px}#bootstrap-theme .chr_annual-entitlements__period{width:130px}#bootstrap-theme .chr_annual-entitlements__edit-entitlements{width:150px}#bootstrap-theme .chr_contract-entitlements__position{width:140px}@media (max-width: 992px){#bootstrap-theme .chr_leave-balance-tab .chr_leave-balance-tab__filter:not(:last-child){padding-bottom:15px}}#bootstrap-theme .chr_leave-balance-tab__body{padding:0}@media (min-width: 1200px){#bootstrap-theme .chr_leave-calendar__dates-container .chr_leave-calendar{table-layout:fixed}}#bootstrap-theme .chr_leave-calendar__names-container .chr_leave-calendar{table-layout:fixed}#bootstrap-theme .chr_leave-calendar__day{font-size:10px !important;line-height:1.4em !important;padding:10px !important;text-align:center !important}@media (min-width: 1200px){#bootstrap-theme .chr_leave-calendar__day{padding:10px 0 !important}}#bootstrap-theme .chr_leave-calendar__day--disabled{opacity:0.5}#bootstrap-theme .chr_leave-calendar__day--current{color:#0071bd !important}#bootstrap-theme .chr_leave-calendar__item{color:#FFF;display:block;font-size:10px;height:100%;position:relative;text-align:center;text-transform:uppercase;width:100%}#bootstrap-theme .chr_leave-calendar__item>span{bottom:0;left:0;margin:auto;position:absolute;right:0;top:0;height:1.2em}#bootstrap-theme .chr_leave-calendar__item>.chr_leave-calendar__time-unit{font-size:7px;height:1em;margin-left:-1px}#bootstrap-theme .chr_leave-calendar__item>a{cursor:pointer;bottom:0;left:0;margin:auto;position:absolute;right:0;top:0}#bootstrap-theme .chr_leave-calendar__item--disabled{cursor:not-allowed;opacity:0.5}#bootstrap-theme .chr_leave-calendar__item--type--late{background-color:#eca67e;border-color:#eca67e}#bootstrap-theme .chr_leave-calendar__item--type--non-working{background-color:#41afcb !important;border-color:#41afcb}#bootstrap-theme .chr_leave-calendar__item--type--public-holiday{background-color:#8ec68a !important;border-color:#8ec68a}#bootstrap-theme .chr_leave-calendar__item--type--weekend{background-color:#c7cbd0 !important;border-color:#c7cbd0}#bootstrap-theme .chr_leave-calendar__item--alt{background:#FFF !important;border:1px solid transparent;color:#464354}#bootstrap-theme .chr_leave-calendar__item--requested:before{background:#c7cbd0;content:'';display:block;height:.5em;position:absolute;width:100%;top:0}#bootstrap-theme .chr_leave-calendar__item--toil-requested:before{background:red;content:'';display:block;height:.5em;left:-1px;position:absolute;width:calc(100% + 2px);top:-1px}#bootstrap-theme .chr_leave-calendar__items>td{overflow:hidden;height:35px;padding:0 !important}#bootstrap-theme .chr_leave-calendar__items leave-calendar-day{display:block;height:100%}#bootstrap-theme .chr_leave-calendar__legend__title{font-size:12px}#bootstrap-theme .chr_leave-calendar__legend>.row:not(:first-child){margin-top:20px}#bootstrap-theme .chr_leave-calendar__legend .chr_leave-calendar__legend__entry{margin-top:10px}@media (min-width: 768px){#bootstrap-theme .chr_leave-calendar__legend .chr_leave-calendar__legend__entry{margin-top:0}}#bootstrap-theme .chr_leave-calendar__legend__entry{overflow:auto}#bootstrap-theme .chr_leave-calendar__legend__entry+#bootstrap-theme .chr_leave-calendar__legend__entry{margin-top:10px}#bootstrap-theme .chr_leave-calendar__legend__entry>.chr_leave-calendar__item{font-size:8px;height:20px;margin-right:10px;position:absolute;width:20px}#bootstrap-theme .chr_leave-calendar__legend__label{display:inline-block;font-size:12px;margin-left:26px}#bootstrap-theme .chr_leave-calendar__month-header{background:#f3f6f7}#bootstrap-theme .chr_leave-calendar__month-header .panel-title{font-size:16px}#bootstrap-theme td.chr_leave-calendar__name,#bootstrap-theme th.chr_leave-calendar__name{font-size:12px !important;line-height:100%;padding:0 20px !important;text-align:left;text-overflow:ellipsis;width:100%}#bootstrap-theme th.chr_leave-calendar__name,#bootstrap-theme th.chr_leave-calendar__day{height:49px}#bootstrap-theme th.chr_leave-calendar__name{padding-bottom:10px !important}#bootstrap-theme td.chr_leave-calendar__name{vertical-align:middle !important}#bootstrap-theme .chr_leave-calendar__pagination{font-size:10px;text-align:center}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"]{outline:none;padding:0;line-height:1em}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"] .fa{color:#555}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"][disabled] .fa{opacity:0.5}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"]:hover:not([disabled]) .fa{color:#464354}#bootstrap-theme .chr_leave-calendar__pagination-next{border-top:none}#bootstrap-theme .chr_leave-calendar__pagination-next th{height:24px;padding:4px 0 6px !important}#bootstrap-theme .chr_leave-calendar__pagination-next .chr_leave-calendar__pagination{padding-right:3px !important}#bootstrap-theme .chr_leave-calendar__month-container{margin:0}#bootstrap-theme .chr_leave-calendar__month-container>div{padding:0}#bootstrap-theme .chr_leave-calendar__dates-container{overflow-x:auto}#bootstrap-theme .chr_leave-calendar__admin-filters-hint{display:inline-block;font-size:20px;vertical-align:middle}#bootstrap-theme .chr_leave-calendar__admin-filters-select{width:calc(100% - 50px);display:inline-block;margin-right:20px}#bootstrap-theme .chr_leave-report .dropdown-toggle{color:#464354;padding:0 10px}#bootstrap-theme .chr_leave-report .dropdown-toggle:hover{background:#e6e6e6}#bootstrap-theme .chr_leave-report table{table-layout:fixed}#bootstrap-theme .chr_leave-report table thead th,#bootstrap-theme .chr_leave-report table tbody td{padding:8px 5px}#bootstrap-theme .chr_leave-report__label{color:#464354;font-weight:700}#bootstrap-theme .chr_leave-report__label>.fa{margin-right:5px}#bootstrap-theme .chr_leave-report__label--toggle{cursor:pointer;user-select:none}#bootstrap-theme .chr_leave-report__heading{background-color:#f3f6f7;border-bottom:1px solid #dadcde}#bootstrap-theme .chr_leave-report__heading .chr_leave-report__export-button{line-height:2.4}#bootstrap-theme .chr_leave-report__table table,#bootstrap-theme .chr_leave-report__table .table{border-collapse:separate}#bootstrap-theme .chr_leave-report__table table>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>tbody>tr:first-child>td{border-top-width:0}#bootstrap-theme .chr_leave-report__table table>thead+tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>thead+tbody>tr:first-child>td{border-top-width:1px}#bootstrap-theme .chr_leave-report__table table:not(.table-bordered):not(.table-condensed)>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table:not(.table-bordered):not(.table-condensed)>tbody>tr:first-child>td{border-color:#f3f6f7}#bootstrap-theme .chr_leave-report__table table>thead>tr>th,#bootstrap-theme .chr_leave-report__table .table>thead>tr>th{background:#f3f6f7;border-bottom:0;color:#464354;text-transform:capitalize}#bootstrap-theme .chr_leave-report__table table>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>tbody>tr:first-child>td{border-color:#e8eef0 !important}#bootstrap-theme .chr_leave-report__table table>tfoot>tr,#bootstrap-theme .chr_leave-report__table .table>tfoot>tr{background:#f3f6f7}#bootstrap-theme .chr_leave-report__table>table>thead>tr>th,#bootstrap-theme .chr_leave-report__table>.table>thead>tr>th{padding-bottom:13px;padding-top:13px}#bootstrap-theme .chr_leave-report__table-container{overflow:auto}#bootstrap-theme .chr_leave-report__table-container .panel{display:inline-block;min-width:100%}#bootstrap-theme .chr_leave-report__table__heading--action{width:45px}#bootstrap-theme .chr_leave-report__table__heading--label{width:280px}#bootstrap-theme .chr_leave-report__table__heading--dates{width:170px}#bootstrap-theme .chr_leave-report__table__heading--status{width:180px}#bootstrap-theme .chr_leave-report__table__heading--type{width:65px;word-break:break-word}#bootstrap-theme .chr_leave-request-comment{margin-top:10px}#bootstrap-theme .chr_leave-request-comment__text{border-bottom:1px solid #e8eef0;color:#c2cfd8;margin-right:10px;padding-bottom:20px}#bootstrap-theme .chr_leave-request-files_list{height:150px;overflow-y:auto;margin-top:20px;margin-bottom:20px}#bootstrap-theme .chr_leave-request-files_meta{margin-bottom:10px}#bootstrap-theme .chr_leave-request-files_upload{border:dashed 1px #464354;padding:20px}#bootstrap-theme .chr_leave-request-files_upload_action{padding:5px}#bootstrap-theme .chr_leave-request-files_file-name{display:inline-block;max-width:240px;overflow:hidden;text-overflow:ellipsis;vertical-align:bottom}#bootstrap-theme .chr_leave-request-files_delete{margin-top:-7px}#bootstrap-theme .chr_leave-request-modal .modal-title{font-size:18px !important}#bootstrap-theme .chr_leave-request-modal .table-responsive{border:0}#bootstrap-theme .chr_leave-request-modal .chr_leave-request-date-picker-container .input-group{width:100%}@media screen and (max-width: 767px){#bootstrap-theme .chr_leave-request-modal .chr_leave-request-date-picker-container{margin-bottom:10px}}#bootstrap-theme .chr_leave-request-modal__chevron{font-size:0.6em;margin-right:5px;vertical-align:middle}#bootstrap-theme .chr_leave-request-modal__comments{height:230px;margin-bottom:20px;overflow:auto}#bootstrap-theme .chr_leave-request-modal__comments_empty{margin-bottom:20px}#bootstrap-theme .chr_leave-request-modal__footer{margin:0}#bootstrap-theme .chr_leave-request-modal__delete{margin-left:15px;margin-top:8px}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container{margin-bottom:20px}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container ul{opacity:1 !important}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container:not(.ui-select-multiple) input{width:100% !important}#bootstrap-theme .chr_leave-request-modal__form-group,#bootstrap-theme .chr_leave-request-modal__required-documents>div{margin-bottom:15px}#bootstrap-theme .chr_leave-request-modal__response{padding:20px 20px 0}#bootstrap-theme .chr_leave-request-modal__response label{font-size:17px;margin-top:-3px}#bootstrap-theme .chr_leave-request-modal__response .chr_wysiwyg{margin-top:15px}#bootstrap-theme .chr_leave-request-modal__required-documents input{margin-right:5px}#bootstrap-theme .chr_leave-request-modal__small_spinner>div.chr_spinner{margin-top:18px;min-height:initial}#bootstrap-theme .chr_leave-request-modal__tab input[uib-datepicker-popup]{font-size:13px}#bootstrap-theme .chr_leave-request-modal__table{border:1px solid #f3f6f7;margin-bottom:15px !important}#bootstrap-theme .chr_leave-request-modal__user-info{font-size:17px;padding:20px}#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(1){color:#464354}#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(2){color:#555}@media screen and (min-width: 480px){#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(2){border-left:1px solid #e8eef0}}#bootstrap-theme .chr_leave-request-modal__span-expiry{display:inline-block;margin-top:7px}#bootstrap-theme .chr_leave-request-modal__expiry-clear{position:absolute;right:3.5em;top:0.6em;z-index:2}#bootstrap-theme .chr_leave-request-modal__small-text{font-size:80%}#bootstrap-theme .chr_leave-request-modal__custom-deduction-toggling-row{margin-top:-5px}@media screen and (min-width: 768px){#bootstrap-theme .chr_leave-request-modal__custom-deduction-label{text-align:right}}@media screen and (max-width: 767px){#bootstrap-theme .chr_leave-request-modal__custom-deduction-label{margin-bottom:10px}}#bootstrap-theme .chr_leave-request-modal .form-group{overflow:inherit !important}#bootstrap-theme .chr_leave-request-modal .alert{margin-bottom:0 !important}#bootstrap-theme .chr_leave-request-modal input[uib-datepicker-popup]{box-shadow:none !important;background-color:inherit !important;color:inherit !important;cursor:pointer !important;border-right:none}#bootstrap-theme leave-request-record-actions{display:block;margin-bottom:20px}#bootstrap-theme leave-request-record-actions .fa,#bootstrap-theme leave-request-record-actions .btn-group{margin-right:8px}#bootstrap-theme leave-request-record-actions .btn-toolbar{margin-left:0;overflow:inherit}#bootstrap-theme leave-request-record-actions .btn-toolbar .btn-group,#bootstrap-theme leave-request-record-actions .btn-toolbar .btn{margin-left:0}@media screen and (max-width: 767px){#bootstrap-theme leave-request-record-actions .btn-group,#bootstrap-theme leave-request-record-actions .btn{display:block;width:100%}#bootstrap-theme leave-request-record-actions .btn-group{margin-bottom:8px;margin-right:0}}#bootstrap-theme .leave-widget h4{color:#4d4d69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px}#bootstrap-theme .leave-widget__types>table,#bootstrap-theme .leave-widget__sickness>table,#bootstrap-theme .leave-widget__next-leave>table{border:none}#bootstrap-theme .leave-widget__types>table thead tr th,#bootstrap-theme .leave-widget__sickness>table thead tr th,#bootstrap-theme .leave-widget__next-leave>table thead tr th{color:#4d4d69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px;background:none;width:35%}#bootstrap-theme .leave-widget__types>table thead tr th:first-child,#bootstrap-theme .leave-widget__sickness>table thead tr th:first-child,#bootstrap-theme .leave-widget__next-leave>table thead tr th:first-child{width:65%}#bootstrap-theme .leave-widget__types>table tbody tr td,#bootstrap-theme .leave-widget__sickness>table tbody tr td,#bootstrap-theme .leave-widget__next-leave>table tbody tr td{color:#0071bd;font-size:16px;font-weight:600;padding-bottom:9px}#bootstrap-theme .leave-widget__types>table tbody tr td:first-child,#bootstrap-theme .leave-widget__sickness>table tbody tr td:first-child,#bootstrap-theme .leave-widget__next-leave>table tbody tr td:first-child{color:#464354}#bootstrap-theme .leave-widget hr{border-color:#DEE4ED;margin-bottom:25px;margin-top:25px}#bootstrap-theme .leave-widget__sickness h4{margin-top:18px}#bootstrap-theme .leave-widget__next-leave h3{font-size:16px;margin-bottom:16px;margin-top:0}#bootstrap-theme .leave-widget__next-leave__deduction{font-size:16px;font-weight:600;color:#464354}#bootstrap-theme .chr_leave__page-selector-dropdown{margin-right:5px;position:relative;top:1px;width:100%}#bootstrap-theme .chr_leave__page-selector-dropdown select{height:40px}#bootstrap-theme .chr_leave__page-selector-dropdown .crm_custom-select__arrow{line-height:40px;width:40px}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;border-bottom:1px solid #dadcde;margin:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header .panel-title{margin-top:7px;display:inline-block}@media screen and (max-width: 992px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header>div:not(:last-child),#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header .panel-title{padding-bottom:20px}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter{display:inline-block;margin-top:7px;white-space:nowrap}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter .fa{font-size:0.6em;margin-right:5px;margin-top:-2px;vertical-align:middle}@media screen and (max-width: 991px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter{margin-top:15px}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;border-bottom:1px solid #dadcde;margin:0;padding-top:15px}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>*{padding-left:10px !important;padding-right:10px !important}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>div:not(:last-child){padding-bottom:20px}}@media screen and (min-width: 992px) and (max-width: 1199px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>.no_gutter{padding-bottom:0 !important}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body{margin:0;padding:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body [class^="col-"],#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body [class*=" col-"]{padding:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body a{cursor:pointer}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container{padding-left:10px;padding-right:10px;background-color:#f7f7f9}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container>div{padding-left:15px;padding-right:15px}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .form-group{overflow:inherit !important}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .panel{background-image:none !important}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .panel-body,#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .chr_vertical_tabs{background-color:#f7f7f9}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] input[type="search"]{width:100% !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header .checkbox{margin-top:5px}#bootstrap-theme .page-manager-leave .chr_manage_leave_requests .btn-sm{font-size:100% !important}#bootstrap-theme .chr_manager_calendar__header{padding-left:10px;padding-right:10px;padding-top:15px;margin:0;background-color:#f7f7f9;border-bottom:1px solid #dadcde}#bootstrap-theme .chr_manager_calendar__header>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manager_calendar__header .checkbox{margin:0}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manager_calendar__header>div:not(:last-child){padding-bottom:20px}}#bootstrap-theme .chr_manager_calendar__sub-header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;margin:0}#bootstrap-theme .chr_manager_calendar__sub-header>*{padding-left:10px !important;padding-right:10px !important}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manager_calendar__sub-header>div:not(:last-child){padding-bottom:20px}#bootstrap-theme .chr_manager_calendar__sub-header .ui-select-container{height:auto}}#bootstrap-theme .time-amount-picker .crm_custom-select{display:inline-block;margin-right:2px}#bootstrap-theme .time-amount-picker .crm_custom-select:nth-child(2){margin-left:10px}#bootstrap-theme .absence-tab-page .tab-pane{padding:0 !important}#bootstrap-theme .absence-tab-page .tab-content{background-color:transparent !important}#bootstrap-theme .absence-tab-page leave-request-record-actions{margin-bottom:20px}#bootstrap-theme .crm-absence_type-form-block .crm-section .label{width:35%}#bootstrap-theme .crm-absence_type-form-block .crm-section .content{margin-left:40%}#bootstrap-theme .crm-absence_type-form-block .toil-option,#bootstrap-theme .crm-absence_type-form-block .carry-forward-option,#bootstrap-theme .crm-absence_type-form-block .toil-expiration,#bootstrap-theme .crm-absence_type-form-block .carry-forward-expiration-duration,#bootstrap-theme .crm-absence_type-form-block .carry-forward-expiration-date{display:none}#bootstrap-theme .crm-absence_type-form-block .sp-replacer{padding:2px}#bootstrap-theme .crm-absence_type-form-block .sp-preview{height:15px;width:15px}#bootstrap-theme .crm-absence_type-form-block .sp-dd{height:0;line-height:15px;font-size:9px}.page-civicrm-leaveandabsences-dashboard .page-title,.page-civicrm-leaveandabsences-dashboard #branding{display:none !important}.page-civicrm-leaveandabsences-dashboard #page{margin:0;padding:0}.admin-dashboard-page{position:relative}.admin-dashboard-page .crm_page__topbar{height:65px}.admin-dashboard-page leave-request-record-actions{margin:12px 30px 0 0}.admin-dashboard-page .chr_admin-dashboard_side-nav{background-color:#fff;height:calc(100% - 12px);overflow:hidden;position:absolute;width:170px}.admin-dashboard-page .chr_admin-dashboard_side-nav .active{background:#e8eef0}.admin-dashboard-page .chr_admin-dashboard_content{float:right;margin:16px;margin-bottom:0;width:calc(100% - 170px - 16px * 2)}#bootstrap-theme #calculation-details{background:#fff}#bootstrap-theme #calculation-details .base-contractual-entitlement{color:#0071bd}#bootstrap-theme #calculation-details .working-days-to-work{color:#44cb7e}#bootstrap-theme #calculation-details .working-days-in-period{color:#e6ab5e}#bootstrap-theme #calculation-details .contract-1-pro-rata{color:#E6807F}#bootstrap-theme #calculation-details .contract-2-pro-rata{color:#797300}#bootstrap-theme #calculation-details .contract-3-pro-rata{color:#904E1E}#bootstrap-theme #calculation-details .contract-4-pro-rata{color:#0511B1}#bootstrap-theme #calculation-details .contract-5-pro-rata{color:#4B9609}#bootstrap-theme #calculation-details .calculation-pro-rata{color:#95c0ff}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body{padding-top:20px;padding-bottom:20px}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body .row:first-child h3{margin-top:0}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body h3{margin-bottom:20px}#bootstrap-theme .crm-leave-and-absences-form-block .panel-footer .crm-button:last-child{margin-right:0}#bootstrap-theme.crm-leave-and-balance-import .panel{background-color:#fff}#bootstrap-theme.crm-leave-and-balance-import .panel-header{position:relative}#bootstrap-theme.crm-leave-and-balance-import .panel-header h2{padding:10px 20px}#bootstrap-theme.crm-leave-and-balance-import .panel-body .row:not(:last-child){padding-bottom:2em}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats .label{display:none}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats label{font-weight:normal !important}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats td{border:0;padding:0}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block{box-shadow:none;padding:0}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table{margin-bottom:2em;width:100%}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table th{padding:10px 20px;border-right:none}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table th,#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table td{padding:5px}#bootstrap-theme.crm-leave-and-balance-import #preview-counts,#bootstrap-theme.crm-leave-and-balance-import #summary-counts{box-shadow:none;margin-bottom:2em;width:100%}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td{background-color:#f2dede !important;color:#cf3458}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td a,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td a{color:#bd2d4e;font-weight:bold}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td a:hover,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td a:hover{color:#0062a4}#bootstrap-theme.manage-entitlements-form .wider-hr{margin-left:-20px;margin-right:-20px;border-width:2px}#bootstrap-theme.manage-entitlements-form .wider-row{margin-left:-20px;margin-right:-20px}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters{padding:15px 0;text-align:center}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .override-filters label{display:inline-block}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .override-filters label:before{display:none}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .absence-type-filter{margin-right:10px}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .col-sm-4:last-child{text-align:right}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list{margin-bottom:0}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement-header .title{float:left;width:65%}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement-header .actions{float:right}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list tr.hidden{display:none}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .absence-type{color:#fff;display:inline-block;padding:5px}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement .overridden-proposed-entitlement,#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement .calculation-unit{display:none}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .borderless-button{background-color:transparent;border:0;cursor:pointer}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .add-comment{font-size:1.1em}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .comment-text{display:none}#bootstrap-theme.manage-entitlements-form .manage-entitlements-form__filters{padding-bottom:1em}#bootstrap-theme.manage-entitlements-form .table{background:#f9f9f9;border-top:1px solid #e8eef0;border-bottom:1px solid #e8eef0;margin-bottom:2em}#bootstrap-theme.manage-entitlements-form .table th{background:#f3f6f7 !important}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header{border-left:1px solid #e8eef0;border-right:1px solid #e8eef0;background:#e4ebed !important;min-width:200px}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .row>div{display:table-cell;float:none;vertical-align:bottom}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .fa{color:#4d4d69}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .action-button-container{padding:0}#bootstrap-theme.manage-entitlements-form .table td.proposed-entitlement{border-left:1px solid #e8eef0;border-right:1px solid #e8eef0;background:white}#bootstrap-theme.manage-entitlements-form .table span.absence-type{border-radius:3px;padding:0 5px}#bootstrap-theme.manage-entitlements-form .table tbody .fa{color:#0071bd}#bootstrap-theme.manage-entitlements-form .crm-container .CRM_HRLeaveAndAbsences_Form_ManageEntitlements .crm-button-type-next{float:right !important}#bootstrap-theme.manage-entitlements-form .panel-footer{border-top:none}#add-comment-dialog{display:none}#add-comment-dialog .calculation_comment{box-sizing:border-box;padding:10px;width:100%}#bootstrap-theme .crm-work-pattern-form-block .ui-tabs.ui-widget-content{background:none}#bootstrap-theme .work-pattern-calendar .number-of-weeks{padding:15px 0 15px 0}#bootstrap-theme .work-pattern-calendar .work-pattern-week{border-top:1px solid rgba(0,0,0,0.2);padding:15px 0 15px 0;margin-bottom:15px}#bootstrap-theme .work-pattern-calendar .work-pattern-week.hidden-week{display:none}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-number{float:left;font-weight:bold;padding:5px 0 15px 5px}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days{table-layout:fixed}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-hours{float:right;padding:5px 5px 15px 0}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-hours .number-of-hours{font-weight:bold}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days td{padding:5px 10px 5px 10px}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days input{min-width:0;text-align:center}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days select{min-width:0;width:100% !important}#bootstrap-theme .work-pattern-calendar .work-pattern-week .hours-row td{padding-top:15px;padding-bottom:15px;border-top:1px solid rgba(0,0,0,0.2);border-bottom:1px solid rgba(0,0,0,0.2)}.caret{display:inline-block;width:0;height:0;margin-left:2px;vertical-align:middle;border-top:4px dashed;border-top:4px solid \9;border-right:4px solid transparent;border-left:4px solid transparent}.dropup,.dropdown{position:relative}.dropdown-toggle:focus{outline:0}.dropdown-menu{position:absolute;top:100%;left:0;z-index:1000;display:none;float:left;min-width:160px;padding:5px 0;margin:2px 0 0;list-style:none;font-size:13px;text-align:left;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.15);border-radius:2px;-webkit-box-shadow:0 6px 12px rgba(0,0,0,0.175);box-shadow:0 6px 12px rgba(0,0,0,0.175);background-clip:padding-box}.dropdown-menu.pull-right{right:0;left:auto}.dropdown-menu .divider{height:1px;margin:9px 0;overflow:hidden;background-color:#e5e5e5}.dropdown-menu>li>a{display:block;padding:3px 20px;clear:both;font-weight:normal;line-height:1.5384615385;color:#4d4d69;white-space:nowrap}.dropdown-menu>li>a:hover,.dropdown-menu>li>a:focus{text-decoration:none;color:#42425a;background-color:#f3f6f7}.dropdown-menu>.active>a,.dropdown-menu>.active>a:hover,.dropdown-menu>.active>a:focus{color:#fff;text-decoration:none;outline:0;background-color:#0071bd}.dropdown-menu>.disabled>a,.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{color:#e8eef0}.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{text-decoration:none;background-color:transparent;background-image:none;filter:progid:DXImageTransform.Microsoft.gradient(enabled = false);cursor:not-allowed}.open>.dropdown-menu{display:block}.open>a{outline:0}.dropdown-menu-right{left:auto;right:0}.dropdown-menu-left{left:0;right:auto}.dropdown-header{display:block;padding:3px 20px;font-size:12px;line-height:1.5384615385;color:#464354;white-space:nowrap}.dropdown-backdrop{position:fixed;left:0;right:0;bottom:0;top:0;z-index:990}.pull-right>.dropdown-menu{right:0;left:auto}.dropup .caret,.navbar-fixed-bottom .dropdown .caret{border-top:0;border-bottom:4px dashed;border-bottom:4px solid \9;content:""}.dropup .dropdown-menu,.navbar-fixed-bottom .dropdown .dropdown-menu{top:auto;bottom:100%;margin-bottom:2px}@media (min-width: 768px){.navbar-right .dropdown-menu{right:0;left:auto}.navbar-right .dropdown-menu-left{left:0;right:auto}}.dropdown-header{padding:11px 20px}.dropdown-menu{-webkit-box-shadow:0 3px 18px 0 rgba(48,40,40,0.25);box-shadow:0 3px 18px 0 rgba(48,40,40,0.25);border:0;margin:0;padding:0}.dropdown-menu>li{border:0;margin:0;padding:0}.dropdown-menu>li>a{padding:11px 20px} +#bootstrap-theme .chr_disabled{opacity:0.5;pointer-events:none}#bootstrap-theme .table-condensed>thead>tr>th{background:#fff !important;padding:8px 5px}#bootstrap-theme .table-condensed-mixed>thead>tr>th,#bootstrap-theme .table-condensed-mixed>thead>tr>td,#bootstrap-theme .table-condensed-mixed>tbody>tr>th,#bootstrap-theme .table-condensed-mixed>tbody>tr>td{padding-left:5px;padding-right:5px}#bootstrap-theme .table-condensed>tbody>tr>td:first-child,#bootstrap-theme .table-condensed>tbody>tr>th:first-child,#bootstrap-theme .table-condensed>thead>tr>td:first-child,#bootstrap-theme .table-condensed>thead>tr>th:first-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>td:first-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>th:first-child,#bootstrap-theme .table-condensed-mixed>thead>tr>td:first-child,#bootstrap-theme .table-condensed-mixed>thead>tr>th:first-child{padding-left:20px}#bootstrap-theme .table-condensed>tbody>tr>td:last-child,#bootstrap-theme .table-condensed>tbody>tr>th:last-child,#bootstrap-theme .table-condensed>thead>tr>td:last-child,#bootstrap-theme .table-condensed>thead>tr>th:last-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>td:last-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>th:last-child,#bootstrap-theme .table-condensed-mixed>thead>tr>td:last-child,#bootstrap-theme .table-condensed-mixed>thead>tr>th:last-child{padding-right:20px}#bootstrap-theme .table-nested{overflow-y:hidden;position:relative}#bootstrap-theme .table-nested:before{box-shadow:inset 0px 6px 9px -6px rgba(0,0,0,0.2);content:'';display:block;height:10px;left:0;position:absolute;top:0;width:100%;z-index:10}#bootstrap-theme .table-nested:after{box-shadow:inset 0px -4px 9px -6px rgba(0,0,0,0.2);content:'';display:block;height:10px;left:0;position:absolute;bottom:0;width:100%;z-index:10}#bootstrap-theme .table-nested>table,#bootstrap-theme .table-nested>.table{background-color:#fff}#bootstrap-theme .table-nested>table>tbody>tr>td:first-child,#bootstrap-theme .table-nested>table>tbody>tr>th:first-child,#bootstrap-theme .table-nested>table>thead>tr>td:first-child,#bootstrap-theme .table-nested>table>thead>tr>th:first-child,#bootstrap-theme .table-nested>.table>tbody>tr>td:first-child,#bootstrap-theme .table-nested>.table>tbody>tr>th:first-child,#bootstrap-theme .table-nested>.table>thead>tr>td:first-child,#bootstrap-theme .table-nested>.table>thead>tr>th:first-child{padding-left:30px;position:relative}#bootstrap-theme .table-nested>table>tbody>tr>td:first-child:before,#bootstrap-theme .table-nested>table>tbody>tr>th:first-child:before,#bootstrap-theme .table-nested>table>thead>tr>td:first-child:before,#bootstrap-theme .table-nested>table>thead>tr>th:first-child:before,#bootstrap-theme .table-nested>.table>tbody>tr>td:first-child:before,#bootstrap-theme .table-nested>.table>tbody>tr>th:first-child:before,#bootstrap-theme .table-nested>.table>thead>tr>td:first-child:before,#bootstrap-theme .table-nested>.table>thead>tr>th:first-child:before{background:#c2cfd8;content:'';display:block;height:110%;left:0;position:absolute;top:0;width:10px;z-index:2}#bootstrap-theme .table-nested>table>tbody>tr>td:last-child,#bootstrap-theme .table-nested>table>tbody>tr>th:last-child,#bootstrap-theme .table-nested>table>thead>tr>td:last-child,#bootstrap-theme .table-nested>table>thead>tr>th:last-child,#bootstrap-theme .table-nested>.table>tbody>tr>td:last-child,#bootstrap-theme .table-nested>.table>tbody>tr>th:last-child,#bootstrap-theme .table-nested>.table>thead>tr>td:last-child,#bootstrap-theme .table-nested>.table>thead>tr>th:last-child{padding-right:30px;position:relative}#bootstrap-theme .table-nested>table>tbody>tr>td:last-child:after,#bootstrap-theme .table-nested>table>tbody>tr>th:last-child:after,#bootstrap-theme .table-nested>table>thead>tr>td:last-child:after,#bootstrap-theme .table-nested>table>thead>tr>th:last-child:after,#bootstrap-theme .table-nested>.table>tbody>tr>td:last-child:after,#bootstrap-theme .table-nested>.table>tbody>tr>th:last-child:after,#bootstrap-theme .table-nested>.table>thead>tr>td:last-child:after,#bootstrap-theme .table-nested>.table>thead>tr>th:last-child:after{background:#c2cfd8;content:'';display:block;height:110%;right:0;position:absolute;top:0;width:10px;z-index:2}@media screen and (max-width: 767px){#bootstrap-theme .table-nested.table-responsive{border:0;margin-bottom:0}}#bootstrap-theme .table-nested-cell{padding:0 !important}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(1){width:40%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(2){width:15%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(3){width:35%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(4){width:10%}#bootstrap-theme .chr_absence-work-pattern__work-pattern-listing{display:inline-block}#bootstrap-theme .chr_absence-work-pattern__alert{margin-bottom:0 !important}#bootstrap-theme .annual-entitlement-change-log-component thead td{min-width:100px}#bootstrap-theme .annual-entitlement-change-log-component thead .annual-entitlement-change-log-component__comments{min-width:300px}#bootstrap-theme .chr_annual-entitlements__period{width:130px}#bootstrap-theme .chr_annual-entitlements__edit-entitlements{width:150px}#bootstrap-theme .chr_contract-entitlements__position{width:140px}@media (max-width: 992px){#bootstrap-theme .chr_leave-balance-tab .chr_leave-balance-tab__filter:not(:last-child){padding-bottom:15px}}#bootstrap-theme .chr_leave-balance-tab__body{padding:0}@media (min-width: 1200px){#bootstrap-theme .chr_leave-calendar__dates-container .chr_leave-calendar{table-layout:fixed}}#bootstrap-theme .chr_leave-calendar__names-container .chr_leave-calendar{table-layout:fixed}#bootstrap-theme .chr_leave-calendar__day{font-size:10px !important;line-height:1.4em !important;padding:10px !important;text-align:center !important}@media (min-width: 1200px){#bootstrap-theme .chr_leave-calendar__day{padding:10px 0 !important}}#bootstrap-theme .chr_leave-calendar__day--disabled{opacity:0.5}#bootstrap-theme .chr_leave-calendar__day--current{color:#0071bd !important}#bootstrap-theme .chr_leave-calendar__item{color:#FFF;display:block;font-size:10px;height:100%;position:relative;text-align:center;text-transform:uppercase;width:100%}#bootstrap-theme .chr_leave-calendar__item>span{bottom:0;left:0;margin:auto;position:absolute;right:0;top:0;height:1.2em}#bootstrap-theme .chr_leave-calendar__item>.chr_leave-calendar__time-unit{font-size:7px;height:1em;margin-left:-1px}#bootstrap-theme .chr_leave-calendar__item>a{cursor:pointer;bottom:0;left:0;margin:auto;position:absolute;right:0;top:0}#bootstrap-theme .chr_leave-calendar__item--disabled{cursor:not-allowed;opacity:0.5}#bootstrap-theme .chr_leave-calendar__item--type--late{background-color:#eca67e;border-color:#eca67e}#bootstrap-theme .chr_leave-calendar__item--type--non-working{background-color:#41afcb !important;border-color:#41afcb}#bootstrap-theme .chr_leave-calendar__item--type--public-holiday{background-color:#8ec68a !important;border-color:#8ec68a}#bootstrap-theme .chr_leave-calendar__item--type--weekend{background-color:#c7cbd0 !important;border-color:#c7cbd0}#bootstrap-theme .chr_leave-calendar__item--alt{background:#FFF !important;border:1px solid transparent;color:#464354}#bootstrap-theme .chr_leave-calendar__item--requested:before{background:#c7cbd0;content:'';display:block;height:.5em;position:absolute;width:100%;top:0}#bootstrap-theme .chr_leave-calendar__item--toil-requested:before{background:red;content:'';display:block;height:.5em;left:-1px;position:absolute;width:calc(100% + 2px);top:-1px}#bootstrap-theme .chr_leave-calendar__items>td{overflow:hidden;height:35px;padding:0 !important}#bootstrap-theme .chr_leave-calendar__items leave-calendar-day{display:block;height:100%}#bootstrap-theme .chr_leave-calendar__legend__title{font-size:12px}#bootstrap-theme .chr_leave-calendar__legend>.row:not(:first-child){margin-top:20px}#bootstrap-theme .chr_leave-calendar__legend .chr_leave-calendar__legend__entry{margin-top:10px}@media (min-width: 768px){#bootstrap-theme .chr_leave-calendar__legend .chr_leave-calendar__legend__entry{margin-top:0}}#bootstrap-theme .chr_leave-calendar__legend__entry{overflow:auto}#bootstrap-theme .chr_leave-calendar__legend__entry+#bootstrap-theme .chr_leave-calendar__legend__entry{margin-top:10px}#bootstrap-theme .chr_leave-calendar__legend__entry>.chr_leave-calendar__item{font-size:8px;height:20px;margin-right:10px;position:absolute;width:20px}#bootstrap-theme .chr_leave-calendar__legend__label{display:inline-block;font-size:12px;margin-left:26px}#bootstrap-theme .chr_leave-calendar__month-header{background:#f3f6f7}#bootstrap-theme .chr_leave-calendar__month-header .panel-title{font-size:16px}#bootstrap-theme td.chr_leave-calendar__name,#bootstrap-theme th.chr_leave-calendar__name{font-size:12px !important;line-height:100%;padding:0 20px !important;text-align:left;text-overflow:ellipsis;width:100%}#bootstrap-theme th.chr_leave-calendar__name,#bootstrap-theme th.chr_leave-calendar__day{height:49px}#bootstrap-theme th.chr_leave-calendar__name{padding-bottom:10px !important}#bootstrap-theme td.chr_leave-calendar__name{vertical-align:middle !important}#bootstrap-theme .chr_leave-calendar__pagination{font-size:10px;text-align:center}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"]{outline:none;padding:0;line-height:1em}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"] .fa{color:#555}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"][disabled] .fa{opacity:0.5}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"]:hover:not([disabled]) .fa{color:#464354}#bootstrap-theme .chr_leave-calendar__pagination-next{border-top:none}#bootstrap-theme .chr_leave-calendar__pagination-next th{height:24px;padding:4px 0 6px !important}#bootstrap-theme .chr_leave-calendar__pagination-next .chr_leave-calendar__pagination{padding-right:3px !important}#bootstrap-theme .chr_leave-calendar__month-container{margin:0}#bootstrap-theme .chr_leave-calendar__month-container>div{padding:0}#bootstrap-theme .chr_leave-calendar__dates-container{overflow-x:auto}#bootstrap-theme .chr_leave-calendar__admin-filters-hint{display:inline-block;font-size:20px;vertical-align:middle}#bootstrap-theme .chr_leave-calendar__admin-filters-select{width:calc(100% - 50px);display:inline-block;margin-right:20px}#bootstrap-theme .chr_leave-report .dropdown-toggle{color:#464354;padding:0 10px}#bootstrap-theme .chr_leave-report .dropdown-toggle:hover{background:#e6e6e6}#bootstrap-theme .chr_leave-report table{table-layout:fixed}#bootstrap-theme .chr_leave-report table thead th,#bootstrap-theme .chr_leave-report table tbody td{padding:8px 5px}#bootstrap-theme .chr_leave-report__label{color:#464354;font-weight:700}#bootstrap-theme .chr_leave-report__label>.fa{margin-right:5px}#bootstrap-theme .chr_leave-report__label--toggle{cursor:pointer;user-select:none}#bootstrap-theme .chr_leave-report__heading{background-color:#f3f6f7;border-bottom:1px solid #dadcde}#bootstrap-theme .chr_leave-report__heading .chr_leave-report__export-button{line-height:2.4}#bootstrap-theme .chr_leave-report__table table,#bootstrap-theme .chr_leave-report__table .table{border-collapse:separate}#bootstrap-theme .chr_leave-report__table table>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>tbody>tr:first-child>td{border-top-width:0}#bootstrap-theme .chr_leave-report__table table>thead+tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>thead+tbody>tr:first-child>td{border-top-width:1px}#bootstrap-theme .chr_leave-report__table table:not(.table-bordered):not(.table-condensed)>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table:not(.table-bordered):not(.table-condensed)>tbody>tr:first-child>td{border-color:#f3f6f7}#bootstrap-theme .chr_leave-report__table table>thead>tr>th,#bootstrap-theme .chr_leave-report__table .table>thead>tr>th{background:#f3f6f7;border-bottom:0;color:#464354;text-transform:capitalize}#bootstrap-theme .chr_leave-report__table table>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>tbody>tr:first-child>td{border-color:#e8eef0 !important}#bootstrap-theme .chr_leave-report__table table>tfoot>tr,#bootstrap-theme .chr_leave-report__table .table>tfoot>tr{background:#f3f6f7}#bootstrap-theme .chr_leave-report__table>table>thead>tr>th,#bootstrap-theme .chr_leave-report__table>.table>thead>tr>th{padding-bottom:13px;padding-top:13px}#bootstrap-theme .chr_leave-report__table-container{overflow:auto}#bootstrap-theme .chr_leave-report__table-container .panel{display:inline-block;min-width:100%}#bootstrap-theme .chr_leave-report__table__heading--action{width:45px}#bootstrap-theme .chr_leave-report__table__heading--label{width:280px}#bootstrap-theme .chr_leave-report__table__heading--dates{width:170px}#bootstrap-theme .chr_leave-report__table__heading--status{width:180px}#bootstrap-theme .chr_leave-report__table__heading--type{width:65px;word-break:break-word}#bootstrap-theme .chr_leave-request-comment{margin-top:10px}#bootstrap-theme .chr_leave-request-comment__text{border-bottom:1px solid #e8eef0;color:#c2cfd8;margin-right:10px;padding-bottom:20px}#bootstrap-theme .chr_leave-request-files_list{height:150px;overflow-y:auto;margin-top:20px;margin-bottom:20px}#bootstrap-theme .chr_leave-request-files_meta{margin-bottom:10px}#bootstrap-theme .chr_leave-request-files_upload{border:dashed 1px #464354;padding:20px}#bootstrap-theme .chr_leave-request-files_upload_action{padding:5px}#bootstrap-theme .chr_leave-request-files_file-name{display:inline-block;max-width:240px;overflow:hidden;text-overflow:ellipsis;vertical-align:bottom}#bootstrap-theme .chr_leave-request-files_delete{margin-top:-7px}#bootstrap-theme .chr_leave-request-modal .modal-title{font-size:18px !important}#bootstrap-theme .chr_leave-request-modal .table-responsive{border:0}#bootstrap-theme .chr_leave-request-modal .chr_leave-request-date-picker-container .input-group{width:100%}@media screen and (max-width: 767px){#bootstrap-theme .chr_leave-request-modal .chr_leave-request-date-picker-container{margin-bottom:10px}}#bootstrap-theme .chr_leave-request-modal__chevron{font-size:0.6em;margin-right:5px;vertical-align:middle}#bootstrap-theme .chr_leave-request-modal__comments{height:230px;margin-bottom:20px;overflow:auto}#bootstrap-theme .chr_leave-request-modal__comments_empty{margin-bottom:20px}#bootstrap-theme .chr_leave-request-modal__footer{margin:0}#bootstrap-theme .chr_leave-request-modal__delete{margin-left:15px;margin-top:8px}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container{margin-bottom:20px}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container ul{opacity:1 !important}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container:not(.ui-select-multiple) input{width:100% !important}#bootstrap-theme .chr_leave-request-modal__form-group,#bootstrap-theme .chr_leave-request-modal__required-documents>div{margin-bottom:15px}#bootstrap-theme .chr_leave-request-modal__response{padding:20px 20px 0}#bootstrap-theme .chr_leave-request-modal__response label{font-size:17px;margin-top:-3px}#bootstrap-theme .chr_leave-request-modal__response .chr_wysiwyg{margin-top:15px}#bootstrap-theme .chr_leave-request-modal__required-documents input{margin-right:5px}#bootstrap-theme .chr_leave-request-modal__small_spinner>div.chr_spinner{margin-top:18px;min-height:initial}#bootstrap-theme .chr_leave-request-modal__tab input[uib-datepicker-popup]{font-size:13px}#bootstrap-theme .chr_leave-request-modal__table{border:1px solid #f3f6f7;margin-bottom:15px !important}#bootstrap-theme .chr_leave-request-modal__user-info{font-size:17px;padding:20px}#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(1){color:#464354}#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(2){color:#555}@media screen and (min-width: 480px){#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(2){border-left:1px solid #e8eef0}}#bootstrap-theme .chr_leave-request-modal__span-expiry{display:inline-block;margin-top:7px}#bootstrap-theme .chr_leave-request-modal__expiry-clear{position:absolute;right:3.5em;top:0.6em;z-index:2}#bootstrap-theme .chr_leave-request-modal__small-text{font-size:80%}#bootstrap-theme .chr_leave-request-modal__custom-deduction-toggling-row{margin-top:-5px}@media screen and (min-width: 768px){#bootstrap-theme .chr_leave-request-modal__custom-deduction-label{text-align:right}}@media screen and (max-width: 767px){#bootstrap-theme .chr_leave-request-modal__custom-deduction-label{margin-bottom:10px}}#bootstrap-theme .chr_leave-request-modal .form-group{overflow:inherit !important}#bootstrap-theme .chr_leave-request-modal .alert{margin-bottom:0 !important}#bootstrap-theme .chr_leave-request-modal input[uib-datepicker-popup]{box-shadow:none !important;background-color:inherit !important;color:inherit !important;cursor:pointer !important;border-right:none}#bootstrap-theme leave-request-record-actions{display:block}#bootstrap-theme leave-request-record-actions .fa,#bootstrap-theme leave-request-record-actions .btn-group{margin-right:8px}#bootstrap-theme leave-request-record-actions .btn-toolbar{margin-left:0;overflow:inherit}#bootstrap-theme leave-request-record-actions .btn-toolbar .btn-group,#bootstrap-theme leave-request-record-actions .btn-toolbar .btn{margin-left:0}@media screen and (max-width: 767px){#bootstrap-theme leave-request-record-actions .btn-group,#bootstrap-theme leave-request-record-actions .btn{display:block;width:100%}#bootstrap-theme leave-request-record-actions .btn-group{margin-bottom:8px;margin-right:0}}#bootstrap-theme .leave-widget h4{color:#4d4d69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px}#bootstrap-theme .leave-widget__types>table,#bootstrap-theme .leave-widget__sickness>table,#bootstrap-theme .leave-widget__next-leave>table{border:none}#bootstrap-theme .leave-widget__types>table thead tr th,#bootstrap-theme .leave-widget__sickness>table thead tr th,#bootstrap-theme .leave-widget__next-leave>table thead tr th{color:#4d4d69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px;background:none;width:35%}#bootstrap-theme .leave-widget__types>table thead tr th:first-child,#bootstrap-theme .leave-widget__sickness>table thead tr th:first-child,#bootstrap-theme .leave-widget__next-leave>table thead tr th:first-child{width:65%}#bootstrap-theme .leave-widget__types>table tbody tr td,#bootstrap-theme .leave-widget__sickness>table tbody tr td,#bootstrap-theme .leave-widget__next-leave>table tbody tr td{color:#0071bd;font-size:16px;font-weight:600;padding-bottom:9px}#bootstrap-theme .leave-widget__types>table tbody tr td:first-child,#bootstrap-theme .leave-widget__sickness>table tbody tr td:first-child,#bootstrap-theme .leave-widget__next-leave>table tbody tr td:first-child{color:#464354}#bootstrap-theme .leave-widget hr{border-color:#DEE4ED;margin-bottom:25px;margin-top:25px}#bootstrap-theme .leave-widget__sickness h4{margin-top:18px}#bootstrap-theme .leave-widget__next-leave h3{font-size:16px;margin-bottom:16px;margin-top:0}#bootstrap-theme .leave-widget__next-leave__deduction{font-size:16px;font-weight:600;color:#464354}#bootstrap-theme .chr_leave__page-selector-dropdown{margin-right:5px;position:relative;top:1px;width:100%}#bootstrap-theme .chr_leave__page-selector-dropdown select{height:40px}#bootstrap-theme .chr_leave__page-selector-dropdown .crm_custom-select__arrow{line-height:40px;width:40px}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;border-bottom:1px solid #dadcde;margin:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header .panel-title{margin-top:7px;display:inline-block}@media screen and (max-width: 992px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header>div:not(:last-child),#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header .panel-title{padding-bottom:20px}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter{display:inline-block;margin-top:7px;white-space:nowrap}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter .fa{font-size:0.6em;margin-right:5px;margin-top:-2px;vertical-align:middle}@media screen and (max-width: 991px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter{margin-top:15px}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;border-bottom:1px solid #dadcde;margin:0;padding-top:15px}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>*{padding-left:10px !important;padding-right:10px !important}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>div:not(:last-child){padding-bottom:20px}}@media screen and (min-width: 992px) and (max-width: 1199px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>.no_gutter{padding-bottom:0 !important}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body{margin:0;padding:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body [class^="col-"],#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body [class*=" col-"]{padding:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body a{cursor:pointer}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container{padding-left:10px;padding-right:10px;background-color:#f7f7f9}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container>div{padding-left:15px;padding-right:15px}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .form-group{overflow:inherit !important}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .panel{background-image:none !important}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .panel-body,#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .chr_vertical_tabs{background-color:#f7f7f9}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] input[type="search"]{width:100% !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header .checkbox{margin-top:5px}#bootstrap-theme .page-manager-leave .chr_manage_leave_requests .btn-sm{font-size:100% !important}#bootstrap-theme .chr_manager_calendar__header{padding-left:10px;padding-right:10px;padding-top:15px;margin:0;background-color:#f7f7f9;border-bottom:1px solid #dadcde}#bootstrap-theme .chr_manager_calendar__header>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manager_calendar__header .checkbox{margin:0}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manager_calendar__header>div:not(:last-child){padding-bottom:20px}}#bootstrap-theme .chr_manager_calendar__sub-header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;margin:0}#bootstrap-theme .chr_manager_calendar__sub-header>*{padding-left:10px !important;padding-right:10px !important}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manager_calendar__sub-header>div:not(:last-child){padding-bottom:20px}#bootstrap-theme .chr_manager_calendar__sub-header .ui-select-container{height:auto}}#bootstrap-theme .time-amount-picker .crm_custom-select{display:inline-block;margin-right:2px}#bootstrap-theme .time-amount-picker .crm_custom-select:nth-child(2){margin-left:10px}#bootstrap-theme .absence-tab-page .tab-pane{padding:0 !important}#bootstrap-theme .absence-tab-page .tab-content{background-color:transparent !important}#bootstrap-theme .absence-tab-page leave-request-record-actions{margin-bottom:20px}#bootstrap-theme .crm-absence_type-form-block .crm-section .label{width:35%}#bootstrap-theme .crm-absence_type-form-block .crm-section .content{margin-left:40%}#bootstrap-theme .crm-absence_type-form-block .toil-option,#bootstrap-theme .crm-absence_type-form-block .carry-forward-option,#bootstrap-theme .crm-absence_type-form-block .toil-expiration,#bootstrap-theme .crm-absence_type-form-block .carry-forward-expiration-duration,#bootstrap-theme .crm-absence_type-form-block .carry-forward-expiration-date{display:none}#bootstrap-theme .crm-absence_type-form-block .sp-replacer{padding:2px}#bootstrap-theme .crm-absence_type-form-block .sp-preview{height:15px;width:15px}#bootstrap-theme .crm-absence_type-form-block .sp-dd{height:0;line-height:15px;font-size:9px}.page-civicrm-leaveandabsences-dashboard .page-title,.page-civicrm-leaveandabsences-dashboard #branding{display:none !important}.page-civicrm-leaveandabsences-dashboard #page{margin:0;padding:0}.admin-dashboard-page{position:relative}.admin-dashboard-page .crm_page__topbar{height:65px}.admin-dashboard-page leave-request-record-actions{margin:12px 16px 0 0}.admin-dashboard-page .chr_admin-dashboard_side-nav{background-color:#fff;height:calc(100% - 12px);overflow:hidden;position:absolute;width:170px}.admin-dashboard-page .chr_admin-dashboard_side-nav .active{background:#e8eef0}.admin-dashboard-page .chr_admin-dashboard_content{float:right;margin:16px;margin-bottom:0;width:calc(100% - 170px - 16px * 2)}#bootstrap-theme #calculation-details{background:#fff}#bootstrap-theme #calculation-details .base-contractual-entitlement{color:#0071bd}#bootstrap-theme #calculation-details .working-days-to-work{color:#44cb7e}#bootstrap-theme #calculation-details .working-days-in-period{color:#e6ab5e}#bootstrap-theme #calculation-details .contract-1-pro-rata{color:#E6807F}#bootstrap-theme #calculation-details .contract-2-pro-rata{color:#797300}#bootstrap-theme #calculation-details .contract-3-pro-rata{color:#904E1E}#bootstrap-theme #calculation-details .contract-4-pro-rata{color:#0511B1}#bootstrap-theme #calculation-details .contract-5-pro-rata{color:#4B9609}#bootstrap-theme #calculation-details .calculation-pro-rata{color:#95c0ff}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body{padding-top:20px;padding-bottom:20px}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body .row:first-child h3{margin-top:0}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body h3{margin-bottom:20px}#bootstrap-theme .crm-leave-and-absences-form-block .panel-footer .crm-button:last-child{margin-right:0}#bootstrap-theme.crm-leave-and-balance-import .panel{background-color:#fff}#bootstrap-theme.crm-leave-and-balance-import .panel-header{position:relative}#bootstrap-theme.crm-leave-and-balance-import .panel-header h2{padding:10px 20px}#bootstrap-theme.crm-leave-and-balance-import .panel-body .row:not(:last-child){padding-bottom:2em}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats .label{display:none}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats label{font-weight:normal !important}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats td{border:0;padding:0}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block{box-shadow:none;padding:0}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table{margin-bottom:2em;width:100%}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table th{padding:10px 20px;border-right:none}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table th,#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table td{padding:5px}#bootstrap-theme.crm-leave-and-balance-import #preview-counts,#bootstrap-theme.crm-leave-and-balance-import #summary-counts{box-shadow:none;margin-bottom:2em;width:100%}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td{background-color:#f2dede !important;color:#cf3458}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td a,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td a{color:#bd2d4e;font-weight:bold}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td a:hover,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td a:hover{color:#0062a4}#bootstrap-theme.manage-entitlements-form .wider-hr{margin-left:-20px;margin-right:-20px;border-width:2px}#bootstrap-theme.manage-entitlements-form .wider-row{margin-left:-20px;margin-right:-20px}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters{padding:15px 0;text-align:center}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .override-filters label{display:inline-block}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .override-filters label:before{display:none}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .absence-type-filter{margin-right:10px}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .col-sm-4:last-child{text-align:right}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list{margin-bottom:0}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement-header .title{float:left;width:65%}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement-header .actions{float:right}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list tr.hidden{display:none}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .absence-type{color:#fff;display:inline-block;padding:5px}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement .overridden-proposed-entitlement,#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement .calculation-unit{display:none}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .borderless-button{background-color:transparent;border:0;cursor:pointer}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .add-comment{font-size:1.1em}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .comment-text{display:none}#bootstrap-theme.manage-entitlements-form .manage-entitlements-form__filters{padding-bottom:1em}#bootstrap-theme.manage-entitlements-form .table{background:#f9f9f9;border-top:1px solid #e8eef0;border-bottom:1px solid #e8eef0;margin-bottom:2em}#bootstrap-theme.manage-entitlements-form .table th{background:#f3f6f7 !important}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header{border-left:1px solid #e8eef0;border-right:1px solid #e8eef0;background:#e4ebed !important;min-width:200px}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .row>div{display:table-cell;float:none;vertical-align:bottom}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .fa{color:#4d4d69}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .action-button-container{padding:0}#bootstrap-theme.manage-entitlements-form .table td.proposed-entitlement{border-left:1px solid #e8eef0;border-right:1px solid #e8eef0;background:white}#bootstrap-theme.manage-entitlements-form .table span.absence-type{border-radius:3px;padding:0 5px}#bootstrap-theme.manage-entitlements-form .table tbody .fa{color:#0071bd}#bootstrap-theme.manage-entitlements-form .crm-container .CRM_HRLeaveAndAbsences_Form_ManageEntitlements .crm-button-type-next{float:right !important}#bootstrap-theme.manage-entitlements-form .panel-footer{border-top:none}#add-comment-dialog{display:none}#add-comment-dialog .calculation_comment{box-sizing:border-box;padding:10px;width:100%}#bootstrap-theme .crm-work-pattern-form-block .ui-tabs.ui-widget-content{background:none}#bootstrap-theme .work-pattern-calendar .number-of-weeks{padding:15px 0 15px 0}#bootstrap-theme .work-pattern-calendar .work-pattern-week{border-top:1px solid rgba(0,0,0,0.2);padding:15px 0 15px 0;margin-bottom:15px}#bootstrap-theme .work-pattern-calendar .work-pattern-week.hidden-week{display:none}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-number{float:left;font-weight:bold;padding:5px 0 15px 5px}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days{table-layout:fixed}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-hours{float:right;padding:5px 5px 15px 0}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-hours .number-of-hours{font-weight:bold}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days td{padding:5px 10px 5px 10px}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days input{min-width:0;text-align:center}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days select{min-width:0;width:100% !important}#bootstrap-theme .work-pattern-calendar .work-pattern-week .hours-row td{padding-top:15px;padding-bottom:15px;border-top:1px solid rgba(0,0,0,0.2);border-bottom:1px solid rgba(0,0,0,0.2)}.caret{display:inline-block;width:0;height:0;margin-left:2px;vertical-align:middle;border-top:4px dashed;border-top:4px solid \9;border-right:4px solid transparent;border-left:4px solid transparent}.dropup,.dropdown{position:relative}.dropdown-toggle:focus{outline:0}.dropdown-menu{position:absolute;top:100%;left:0;z-index:1000;display:none;float:left;min-width:160px;padding:5px 0;margin:2px 0 0;list-style:none;font-size:13px;text-align:left;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.15);border-radius:2px;-webkit-box-shadow:0 6px 12px rgba(0,0,0,0.175);box-shadow:0 6px 12px rgba(0,0,0,0.175);background-clip:padding-box}.dropdown-menu.pull-right{right:0;left:auto}.dropdown-menu .divider{height:1px;margin:9px 0;overflow:hidden;background-color:#e5e5e5}.dropdown-menu>li>a{display:block;padding:3px 20px;clear:both;font-weight:normal;line-height:1.5384615385;color:#4d4d69;white-space:nowrap}.dropdown-menu>li>a:hover,.dropdown-menu>li>a:focus{text-decoration:none;color:#42425a;background-color:#f3f6f7}.dropdown-menu>.active>a,.dropdown-menu>.active>a:hover,.dropdown-menu>.active>a:focus{color:#fff;text-decoration:none;outline:0;background-color:#0071bd}.dropdown-menu>.disabled>a,.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{color:#e8eef0}.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{text-decoration:none;background-color:transparent;background-image:none;filter:progid:DXImageTransform.Microsoft.gradient(enabled = false);cursor:not-allowed}.open>.dropdown-menu{display:block}.open>a{outline:0}.dropdown-menu-right{left:auto;right:0}.dropdown-menu-left{left:0;right:auto}.dropdown-header{display:block;padding:3px 20px;font-size:12px;line-height:1.5384615385;color:#464354;white-space:nowrap}.dropdown-backdrop{position:fixed;left:0;right:0;bottom:0;top:0;z-index:990}.pull-right>.dropdown-menu{right:0;left:auto}.dropup .caret,.navbar-fixed-bottom .dropdown .caret{border-top:0;border-bottom:4px dashed;border-bottom:4px solid \9;content:""}.dropup .dropdown-menu,.navbar-fixed-bottom .dropdown .dropdown-menu{top:auto;bottom:100%;margin-bottom:2px}@media (min-width: 768px){.navbar-right .dropdown-menu{right:0;left:auto}.navbar-right .dropdown-menu-left{left:0;right:auto}}.dropdown-header{padding:11px 20px}.dropdown-menu{-webkit-box-shadow:0 3px 18px 0 rgba(48,40,40,0.25);box-shadow:0 3px 18px 0 rgba(48,40,40,0.25);border:0;margin:0;padding:0}.dropdown-menu>li{border:0;margin:0;padding:0}.dropdown-menu>li>a{padding:11px 20px} diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave-request-record-actions.scss b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave-request-record-actions.scss index 3004229de9e..2690e40bddf 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave-request-record-actions.scss +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave-request-record-actions.scss @@ -1,6 +1,5 @@ leave-request-record-actions { display: block; - margin-bottom: $crm-panel-nested-indent; .fa, .btn-group { diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_absence-tab-page.scss b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_absence-tab-page.scss index 656300104a6..3c9e65ae305 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_absence-tab-page.scss +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_absence-tab-page.scss @@ -8,6 +8,6 @@ } leave-request-record-actions { - margin-bottom: 20px; + margin-bottom: $crm-panel-nested-indent; } } diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_admin-dashboard-page.scss b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_admin-dashboard-page.scss index 310180921de..53017223e46 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_admin-dashboard-page.scss +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_admin-dashboard-page.scss @@ -25,7 +25,7 @@ $content-container-margin: 16px; } leave-request-record-actions { - margin: 12px 30px 0 0; + margin: 12px #{$content-container-margin} 0 0; } .chr_admin-dashboard_side-nav { From f001d3e4282e41a75f0827e567b28a359eca0bb5 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Wed, 21 Mar 2018 13:47:59 +0000 Subject: [PATCH 062/203] PCHR-3426: PR Feedback --- .../css/leaveandabsence.css | 2 +- .../js/angular/dist/absence-tab.min.js | 2 +- .../js/angular/dist/admin-dashboard.min.js | 2 +- .../js/angular/dist/manager-leave.min.js | 2 +- .../js/angular/dist/my-leave.min.js | 2 +- .../leave-request-record-actions.component.js | 4 +-- .../components/_absence-work-patterns.scss | 4 +++ .../_leave-request-record-actions.scss | 35 +++++++++---------- .../scss/pages/_absence-tab-page.scss | 2 +- .../components/absence-tab-container.html | 1 - .../components/absence-tab-work-patterns.html | 8 ++--- .../components/admin-dashboard-container.html | 1 - .../components/manager-leave-container.html | 1 - .../leave-request-record-actions.html | 16 +++++---- 14 files changed, 40 insertions(+), 42 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/css/leaveandabsence.css b/uk.co.compucorp.civicrm.hrleaveandabsences/css/leaveandabsence.css index e7827dc794f..c9cee528612 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/css/leaveandabsence.css +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/css/leaveandabsence.css @@ -1 +1 @@ -#bootstrap-theme .chr_disabled{opacity:0.5;pointer-events:none}#bootstrap-theme .table-condensed>thead>tr>th{background:#fff !important;padding:8px 5px}#bootstrap-theme .table-condensed-mixed>thead>tr>th,#bootstrap-theme .table-condensed-mixed>thead>tr>td,#bootstrap-theme .table-condensed-mixed>tbody>tr>th,#bootstrap-theme .table-condensed-mixed>tbody>tr>td{padding-left:5px;padding-right:5px}#bootstrap-theme .table-condensed>tbody>tr>td:first-child,#bootstrap-theme .table-condensed>tbody>tr>th:first-child,#bootstrap-theme .table-condensed>thead>tr>td:first-child,#bootstrap-theme .table-condensed>thead>tr>th:first-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>td:first-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>th:first-child,#bootstrap-theme .table-condensed-mixed>thead>tr>td:first-child,#bootstrap-theme .table-condensed-mixed>thead>tr>th:first-child{padding-left:20px}#bootstrap-theme .table-condensed>tbody>tr>td:last-child,#bootstrap-theme .table-condensed>tbody>tr>th:last-child,#bootstrap-theme .table-condensed>thead>tr>td:last-child,#bootstrap-theme .table-condensed>thead>tr>th:last-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>td:last-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>th:last-child,#bootstrap-theme .table-condensed-mixed>thead>tr>td:last-child,#bootstrap-theme .table-condensed-mixed>thead>tr>th:last-child{padding-right:20px}#bootstrap-theme .table-nested{overflow-y:hidden;position:relative}#bootstrap-theme .table-nested:before{box-shadow:inset 0px 6px 9px -6px rgba(0,0,0,0.2);content:'';display:block;height:10px;left:0;position:absolute;top:0;width:100%;z-index:10}#bootstrap-theme .table-nested:after{box-shadow:inset 0px -4px 9px -6px rgba(0,0,0,0.2);content:'';display:block;height:10px;left:0;position:absolute;bottom:0;width:100%;z-index:10}#bootstrap-theme .table-nested>table,#bootstrap-theme .table-nested>.table{background-color:#fff}#bootstrap-theme .table-nested>table>tbody>tr>td:first-child,#bootstrap-theme .table-nested>table>tbody>tr>th:first-child,#bootstrap-theme .table-nested>table>thead>tr>td:first-child,#bootstrap-theme .table-nested>table>thead>tr>th:first-child,#bootstrap-theme .table-nested>.table>tbody>tr>td:first-child,#bootstrap-theme .table-nested>.table>tbody>tr>th:first-child,#bootstrap-theme .table-nested>.table>thead>tr>td:first-child,#bootstrap-theme .table-nested>.table>thead>tr>th:first-child{padding-left:30px;position:relative}#bootstrap-theme .table-nested>table>tbody>tr>td:first-child:before,#bootstrap-theme .table-nested>table>tbody>tr>th:first-child:before,#bootstrap-theme .table-nested>table>thead>tr>td:first-child:before,#bootstrap-theme .table-nested>table>thead>tr>th:first-child:before,#bootstrap-theme .table-nested>.table>tbody>tr>td:first-child:before,#bootstrap-theme .table-nested>.table>tbody>tr>th:first-child:before,#bootstrap-theme .table-nested>.table>thead>tr>td:first-child:before,#bootstrap-theme .table-nested>.table>thead>tr>th:first-child:before{background:#c2cfd8;content:'';display:block;height:110%;left:0;position:absolute;top:0;width:10px;z-index:2}#bootstrap-theme .table-nested>table>tbody>tr>td:last-child,#bootstrap-theme .table-nested>table>tbody>tr>th:last-child,#bootstrap-theme .table-nested>table>thead>tr>td:last-child,#bootstrap-theme .table-nested>table>thead>tr>th:last-child,#bootstrap-theme .table-nested>.table>tbody>tr>td:last-child,#bootstrap-theme .table-nested>.table>tbody>tr>th:last-child,#bootstrap-theme .table-nested>.table>thead>tr>td:last-child,#bootstrap-theme .table-nested>.table>thead>tr>th:last-child{padding-right:30px;position:relative}#bootstrap-theme .table-nested>table>tbody>tr>td:last-child:after,#bootstrap-theme .table-nested>table>tbody>tr>th:last-child:after,#bootstrap-theme .table-nested>table>thead>tr>td:last-child:after,#bootstrap-theme .table-nested>table>thead>tr>th:last-child:after,#bootstrap-theme .table-nested>.table>tbody>tr>td:last-child:after,#bootstrap-theme .table-nested>.table>tbody>tr>th:last-child:after,#bootstrap-theme .table-nested>.table>thead>tr>td:last-child:after,#bootstrap-theme .table-nested>.table>thead>tr>th:last-child:after{background:#c2cfd8;content:'';display:block;height:110%;right:0;position:absolute;top:0;width:10px;z-index:2}@media screen and (max-width: 767px){#bootstrap-theme .table-nested.table-responsive{border:0;margin-bottom:0}}#bootstrap-theme .table-nested-cell{padding:0 !important}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(1){width:40%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(2){width:15%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(3){width:35%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(4){width:10%}#bootstrap-theme .chr_absence-work-pattern__work-pattern-listing{display:inline-block}#bootstrap-theme .chr_absence-work-pattern__alert{margin-bottom:0 !important}#bootstrap-theme .annual-entitlement-change-log-component thead td{min-width:100px}#bootstrap-theme .annual-entitlement-change-log-component thead .annual-entitlement-change-log-component__comments{min-width:300px}#bootstrap-theme .chr_annual-entitlements__period{width:130px}#bootstrap-theme .chr_annual-entitlements__edit-entitlements{width:150px}#bootstrap-theme .chr_contract-entitlements__position{width:140px}@media (max-width: 992px){#bootstrap-theme .chr_leave-balance-tab .chr_leave-balance-tab__filter:not(:last-child){padding-bottom:15px}}#bootstrap-theme .chr_leave-balance-tab__body{padding:0}@media (min-width: 1200px){#bootstrap-theme .chr_leave-calendar__dates-container .chr_leave-calendar{table-layout:fixed}}#bootstrap-theme .chr_leave-calendar__names-container .chr_leave-calendar{table-layout:fixed}#bootstrap-theme .chr_leave-calendar__day{font-size:10px !important;line-height:1.4em !important;padding:10px !important;text-align:center !important}@media (min-width: 1200px){#bootstrap-theme .chr_leave-calendar__day{padding:10px 0 !important}}#bootstrap-theme .chr_leave-calendar__day--disabled{opacity:0.5}#bootstrap-theme .chr_leave-calendar__day--current{color:#0071bd !important}#bootstrap-theme .chr_leave-calendar__item{color:#FFF;display:block;font-size:10px;height:100%;position:relative;text-align:center;text-transform:uppercase;width:100%}#bootstrap-theme .chr_leave-calendar__item>span{bottom:0;left:0;margin:auto;position:absolute;right:0;top:0;height:1.2em}#bootstrap-theme .chr_leave-calendar__item>.chr_leave-calendar__time-unit{font-size:7px;height:1em;margin-left:-1px}#bootstrap-theme .chr_leave-calendar__item>a{cursor:pointer;bottom:0;left:0;margin:auto;position:absolute;right:0;top:0}#bootstrap-theme .chr_leave-calendar__item--disabled{cursor:not-allowed;opacity:0.5}#bootstrap-theme .chr_leave-calendar__item--type--late{background-color:#eca67e;border-color:#eca67e}#bootstrap-theme .chr_leave-calendar__item--type--non-working{background-color:#41afcb !important;border-color:#41afcb}#bootstrap-theme .chr_leave-calendar__item--type--public-holiday{background-color:#8ec68a !important;border-color:#8ec68a}#bootstrap-theme .chr_leave-calendar__item--type--weekend{background-color:#c7cbd0 !important;border-color:#c7cbd0}#bootstrap-theme .chr_leave-calendar__item--alt{background:#FFF !important;border:1px solid transparent;color:#464354}#bootstrap-theme .chr_leave-calendar__item--requested:before{background:#c7cbd0;content:'';display:block;height:.5em;position:absolute;width:100%;top:0}#bootstrap-theme .chr_leave-calendar__item--toil-requested:before{background:red;content:'';display:block;height:.5em;left:-1px;position:absolute;width:calc(100% + 2px);top:-1px}#bootstrap-theme .chr_leave-calendar__items>td{overflow:hidden;height:35px;padding:0 !important}#bootstrap-theme .chr_leave-calendar__items leave-calendar-day{display:block;height:100%}#bootstrap-theme .chr_leave-calendar__legend__title{font-size:12px}#bootstrap-theme .chr_leave-calendar__legend>.row:not(:first-child){margin-top:20px}#bootstrap-theme .chr_leave-calendar__legend .chr_leave-calendar__legend__entry{margin-top:10px}@media (min-width: 768px){#bootstrap-theme .chr_leave-calendar__legend .chr_leave-calendar__legend__entry{margin-top:0}}#bootstrap-theme .chr_leave-calendar__legend__entry{overflow:auto}#bootstrap-theme .chr_leave-calendar__legend__entry+#bootstrap-theme .chr_leave-calendar__legend__entry{margin-top:10px}#bootstrap-theme .chr_leave-calendar__legend__entry>.chr_leave-calendar__item{font-size:8px;height:20px;margin-right:10px;position:absolute;width:20px}#bootstrap-theme .chr_leave-calendar__legend__label{display:inline-block;font-size:12px;margin-left:26px}#bootstrap-theme .chr_leave-calendar__month-header{background:#f3f6f7}#bootstrap-theme .chr_leave-calendar__month-header .panel-title{font-size:16px}#bootstrap-theme td.chr_leave-calendar__name,#bootstrap-theme th.chr_leave-calendar__name{font-size:12px !important;line-height:100%;padding:0 20px !important;text-align:left;text-overflow:ellipsis;width:100%}#bootstrap-theme th.chr_leave-calendar__name,#bootstrap-theme th.chr_leave-calendar__day{height:49px}#bootstrap-theme th.chr_leave-calendar__name{padding-bottom:10px !important}#bootstrap-theme td.chr_leave-calendar__name{vertical-align:middle !important}#bootstrap-theme .chr_leave-calendar__pagination{font-size:10px;text-align:center}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"]{outline:none;padding:0;line-height:1em}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"] .fa{color:#555}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"][disabled] .fa{opacity:0.5}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"]:hover:not([disabled]) .fa{color:#464354}#bootstrap-theme .chr_leave-calendar__pagination-next{border-top:none}#bootstrap-theme .chr_leave-calendar__pagination-next th{height:24px;padding:4px 0 6px !important}#bootstrap-theme .chr_leave-calendar__pagination-next .chr_leave-calendar__pagination{padding-right:3px !important}#bootstrap-theme .chr_leave-calendar__month-container{margin:0}#bootstrap-theme .chr_leave-calendar__month-container>div{padding:0}#bootstrap-theme .chr_leave-calendar__dates-container{overflow-x:auto}#bootstrap-theme .chr_leave-calendar__admin-filters-hint{display:inline-block;font-size:20px;vertical-align:middle}#bootstrap-theme .chr_leave-calendar__admin-filters-select{width:calc(100% - 50px);display:inline-block;margin-right:20px}#bootstrap-theme .chr_leave-report .dropdown-toggle{color:#464354;padding:0 10px}#bootstrap-theme .chr_leave-report .dropdown-toggle:hover{background:#e6e6e6}#bootstrap-theme .chr_leave-report table{table-layout:fixed}#bootstrap-theme .chr_leave-report table thead th,#bootstrap-theme .chr_leave-report table tbody td{padding:8px 5px}#bootstrap-theme .chr_leave-report__label{color:#464354;font-weight:700}#bootstrap-theme .chr_leave-report__label>.fa{margin-right:5px}#bootstrap-theme .chr_leave-report__label--toggle{cursor:pointer;user-select:none}#bootstrap-theme .chr_leave-report__heading{background-color:#f3f6f7;border-bottom:1px solid #dadcde}#bootstrap-theme .chr_leave-report__heading .chr_leave-report__export-button{line-height:2.4}#bootstrap-theme .chr_leave-report__table table,#bootstrap-theme .chr_leave-report__table .table{border-collapse:separate}#bootstrap-theme .chr_leave-report__table table>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>tbody>tr:first-child>td{border-top-width:0}#bootstrap-theme .chr_leave-report__table table>thead+tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>thead+tbody>tr:first-child>td{border-top-width:1px}#bootstrap-theme .chr_leave-report__table table:not(.table-bordered):not(.table-condensed)>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table:not(.table-bordered):not(.table-condensed)>tbody>tr:first-child>td{border-color:#f3f6f7}#bootstrap-theme .chr_leave-report__table table>thead>tr>th,#bootstrap-theme .chr_leave-report__table .table>thead>tr>th{background:#f3f6f7;border-bottom:0;color:#464354;text-transform:capitalize}#bootstrap-theme .chr_leave-report__table table>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>tbody>tr:first-child>td{border-color:#e8eef0 !important}#bootstrap-theme .chr_leave-report__table table>tfoot>tr,#bootstrap-theme .chr_leave-report__table .table>tfoot>tr{background:#f3f6f7}#bootstrap-theme .chr_leave-report__table>table>thead>tr>th,#bootstrap-theme .chr_leave-report__table>.table>thead>tr>th{padding-bottom:13px;padding-top:13px}#bootstrap-theme .chr_leave-report__table-container{overflow:auto}#bootstrap-theme .chr_leave-report__table-container .panel{display:inline-block;min-width:100%}#bootstrap-theme .chr_leave-report__table__heading--action{width:45px}#bootstrap-theme .chr_leave-report__table__heading--label{width:280px}#bootstrap-theme .chr_leave-report__table__heading--dates{width:170px}#bootstrap-theme .chr_leave-report__table__heading--status{width:180px}#bootstrap-theme .chr_leave-report__table__heading--type{width:65px;word-break:break-word}#bootstrap-theme .chr_leave-request-comment{margin-top:10px}#bootstrap-theme .chr_leave-request-comment__text{border-bottom:1px solid #e8eef0;color:#c2cfd8;margin-right:10px;padding-bottom:20px}#bootstrap-theme .chr_leave-request-files_list{height:150px;overflow-y:auto;margin-top:20px;margin-bottom:20px}#bootstrap-theme .chr_leave-request-files_meta{margin-bottom:10px}#bootstrap-theme .chr_leave-request-files_upload{border:dashed 1px #464354;padding:20px}#bootstrap-theme .chr_leave-request-files_upload_action{padding:5px}#bootstrap-theme .chr_leave-request-files_file-name{display:inline-block;max-width:240px;overflow:hidden;text-overflow:ellipsis;vertical-align:bottom}#bootstrap-theme .chr_leave-request-files_delete{margin-top:-7px}#bootstrap-theme .chr_leave-request-modal .modal-title{font-size:18px !important}#bootstrap-theme .chr_leave-request-modal .table-responsive{border:0}#bootstrap-theme .chr_leave-request-modal .chr_leave-request-date-picker-container .input-group{width:100%}@media screen and (max-width: 767px){#bootstrap-theme .chr_leave-request-modal .chr_leave-request-date-picker-container{margin-bottom:10px}}#bootstrap-theme .chr_leave-request-modal__chevron{font-size:0.6em;margin-right:5px;vertical-align:middle}#bootstrap-theme .chr_leave-request-modal__comments{height:230px;margin-bottom:20px;overflow:auto}#bootstrap-theme .chr_leave-request-modal__comments_empty{margin-bottom:20px}#bootstrap-theme .chr_leave-request-modal__footer{margin:0}#bootstrap-theme .chr_leave-request-modal__delete{margin-left:15px;margin-top:8px}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container{margin-bottom:20px}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container ul{opacity:1 !important}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container:not(.ui-select-multiple) input{width:100% !important}#bootstrap-theme .chr_leave-request-modal__form-group,#bootstrap-theme .chr_leave-request-modal__required-documents>div{margin-bottom:15px}#bootstrap-theme .chr_leave-request-modal__response{padding:20px 20px 0}#bootstrap-theme .chr_leave-request-modal__response label{font-size:17px;margin-top:-3px}#bootstrap-theme .chr_leave-request-modal__response .chr_wysiwyg{margin-top:15px}#bootstrap-theme .chr_leave-request-modal__required-documents input{margin-right:5px}#bootstrap-theme .chr_leave-request-modal__small_spinner>div.chr_spinner{margin-top:18px;min-height:initial}#bootstrap-theme .chr_leave-request-modal__tab input[uib-datepicker-popup]{font-size:13px}#bootstrap-theme .chr_leave-request-modal__table{border:1px solid #f3f6f7;margin-bottom:15px !important}#bootstrap-theme .chr_leave-request-modal__user-info{font-size:17px;padding:20px}#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(1){color:#464354}#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(2){color:#555}@media screen and (min-width: 480px){#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(2){border-left:1px solid #e8eef0}}#bootstrap-theme .chr_leave-request-modal__span-expiry{display:inline-block;margin-top:7px}#bootstrap-theme .chr_leave-request-modal__expiry-clear{position:absolute;right:3.5em;top:0.6em;z-index:2}#bootstrap-theme .chr_leave-request-modal__small-text{font-size:80%}#bootstrap-theme .chr_leave-request-modal__custom-deduction-toggling-row{margin-top:-5px}@media screen and (min-width: 768px){#bootstrap-theme .chr_leave-request-modal__custom-deduction-label{text-align:right}}@media screen and (max-width: 767px){#bootstrap-theme .chr_leave-request-modal__custom-deduction-label{margin-bottom:10px}}#bootstrap-theme .chr_leave-request-modal .form-group{overflow:inherit !important}#bootstrap-theme .chr_leave-request-modal .alert{margin-bottom:0 !important}#bootstrap-theme .chr_leave-request-modal input[uib-datepicker-popup]{box-shadow:none !important;background-color:inherit !important;color:inherit !important;cursor:pointer !important;border-right:none}#bootstrap-theme leave-request-record-actions{display:block}#bootstrap-theme leave-request-record-actions .fa,#bootstrap-theme leave-request-record-actions .btn-group{margin-right:8px}#bootstrap-theme leave-request-record-actions .btn-toolbar{margin-left:0;overflow:inherit}#bootstrap-theme leave-request-record-actions .btn-toolbar .btn-group,#bootstrap-theme leave-request-record-actions .btn-toolbar .btn{margin-left:0}@media screen and (max-width: 767px){#bootstrap-theme leave-request-record-actions .btn-group,#bootstrap-theme leave-request-record-actions .btn{display:block;width:100%}#bootstrap-theme leave-request-record-actions .btn-group{margin-bottom:8px;margin-right:0}}#bootstrap-theme .leave-widget h4{color:#4d4d69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px}#bootstrap-theme .leave-widget__types>table,#bootstrap-theme .leave-widget__sickness>table,#bootstrap-theme .leave-widget__next-leave>table{border:none}#bootstrap-theme .leave-widget__types>table thead tr th,#bootstrap-theme .leave-widget__sickness>table thead tr th,#bootstrap-theme .leave-widget__next-leave>table thead tr th{color:#4d4d69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px;background:none;width:35%}#bootstrap-theme .leave-widget__types>table thead tr th:first-child,#bootstrap-theme .leave-widget__sickness>table thead tr th:first-child,#bootstrap-theme .leave-widget__next-leave>table thead tr th:first-child{width:65%}#bootstrap-theme .leave-widget__types>table tbody tr td,#bootstrap-theme .leave-widget__sickness>table tbody tr td,#bootstrap-theme .leave-widget__next-leave>table tbody tr td{color:#0071bd;font-size:16px;font-weight:600;padding-bottom:9px}#bootstrap-theme .leave-widget__types>table tbody tr td:first-child,#bootstrap-theme .leave-widget__sickness>table tbody tr td:first-child,#bootstrap-theme .leave-widget__next-leave>table tbody tr td:first-child{color:#464354}#bootstrap-theme .leave-widget hr{border-color:#DEE4ED;margin-bottom:25px;margin-top:25px}#bootstrap-theme .leave-widget__sickness h4{margin-top:18px}#bootstrap-theme .leave-widget__next-leave h3{font-size:16px;margin-bottom:16px;margin-top:0}#bootstrap-theme .leave-widget__next-leave__deduction{font-size:16px;font-weight:600;color:#464354}#bootstrap-theme .chr_leave__page-selector-dropdown{margin-right:5px;position:relative;top:1px;width:100%}#bootstrap-theme .chr_leave__page-selector-dropdown select{height:40px}#bootstrap-theme .chr_leave__page-selector-dropdown .crm_custom-select__arrow{line-height:40px;width:40px}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;border-bottom:1px solid #dadcde;margin:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header .panel-title{margin-top:7px;display:inline-block}@media screen and (max-width: 992px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header>div:not(:last-child),#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header .panel-title{padding-bottom:20px}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter{display:inline-block;margin-top:7px;white-space:nowrap}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter .fa{font-size:0.6em;margin-right:5px;margin-top:-2px;vertical-align:middle}@media screen and (max-width: 991px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter{margin-top:15px}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;border-bottom:1px solid #dadcde;margin:0;padding-top:15px}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>*{padding-left:10px !important;padding-right:10px !important}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>div:not(:last-child){padding-bottom:20px}}@media screen and (min-width: 992px) and (max-width: 1199px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>.no_gutter{padding-bottom:0 !important}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body{margin:0;padding:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body [class^="col-"],#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body [class*=" col-"]{padding:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body a{cursor:pointer}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container{padding-left:10px;padding-right:10px;background-color:#f7f7f9}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container>div{padding-left:15px;padding-right:15px}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .form-group{overflow:inherit !important}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .panel{background-image:none !important}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .panel-body,#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .chr_vertical_tabs{background-color:#f7f7f9}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] input[type="search"]{width:100% !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header .checkbox{margin-top:5px}#bootstrap-theme .page-manager-leave .chr_manage_leave_requests .btn-sm{font-size:100% !important}#bootstrap-theme .chr_manager_calendar__header{padding-left:10px;padding-right:10px;padding-top:15px;margin:0;background-color:#f7f7f9;border-bottom:1px solid #dadcde}#bootstrap-theme .chr_manager_calendar__header>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manager_calendar__header .checkbox{margin:0}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manager_calendar__header>div:not(:last-child){padding-bottom:20px}}#bootstrap-theme .chr_manager_calendar__sub-header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;margin:0}#bootstrap-theme .chr_manager_calendar__sub-header>*{padding-left:10px !important;padding-right:10px !important}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manager_calendar__sub-header>div:not(:last-child){padding-bottom:20px}#bootstrap-theme .chr_manager_calendar__sub-header .ui-select-container{height:auto}}#bootstrap-theme .time-amount-picker .crm_custom-select{display:inline-block;margin-right:2px}#bootstrap-theme .time-amount-picker .crm_custom-select:nth-child(2){margin-left:10px}#bootstrap-theme .absence-tab-page .tab-pane{padding:0 !important}#bootstrap-theme .absence-tab-page .tab-content{background-color:transparent !important}#bootstrap-theme .absence-tab-page leave-request-record-actions{margin-bottom:20px}#bootstrap-theme .crm-absence_type-form-block .crm-section .label{width:35%}#bootstrap-theme .crm-absence_type-form-block .crm-section .content{margin-left:40%}#bootstrap-theme .crm-absence_type-form-block .toil-option,#bootstrap-theme .crm-absence_type-form-block .carry-forward-option,#bootstrap-theme .crm-absence_type-form-block .toil-expiration,#bootstrap-theme .crm-absence_type-form-block .carry-forward-expiration-duration,#bootstrap-theme .crm-absence_type-form-block .carry-forward-expiration-date{display:none}#bootstrap-theme .crm-absence_type-form-block .sp-replacer{padding:2px}#bootstrap-theme .crm-absence_type-form-block .sp-preview{height:15px;width:15px}#bootstrap-theme .crm-absence_type-form-block .sp-dd{height:0;line-height:15px;font-size:9px}.page-civicrm-leaveandabsences-dashboard .page-title,.page-civicrm-leaveandabsences-dashboard #branding{display:none !important}.page-civicrm-leaveandabsences-dashboard #page{margin:0;padding:0}.admin-dashboard-page{position:relative}.admin-dashboard-page .crm_page__topbar{height:65px}.admin-dashboard-page leave-request-record-actions{margin:12px 16px 0 0}.admin-dashboard-page .chr_admin-dashboard_side-nav{background-color:#fff;height:calc(100% - 12px);overflow:hidden;position:absolute;width:170px}.admin-dashboard-page .chr_admin-dashboard_side-nav .active{background:#e8eef0}.admin-dashboard-page .chr_admin-dashboard_content{float:right;margin:16px;margin-bottom:0;width:calc(100% - 170px - 16px * 2)}#bootstrap-theme #calculation-details{background:#fff}#bootstrap-theme #calculation-details .base-contractual-entitlement{color:#0071bd}#bootstrap-theme #calculation-details .working-days-to-work{color:#44cb7e}#bootstrap-theme #calculation-details .working-days-in-period{color:#e6ab5e}#bootstrap-theme #calculation-details .contract-1-pro-rata{color:#E6807F}#bootstrap-theme #calculation-details .contract-2-pro-rata{color:#797300}#bootstrap-theme #calculation-details .contract-3-pro-rata{color:#904E1E}#bootstrap-theme #calculation-details .contract-4-pro-rata{color:#0511B1}#bootstrap-theme #calculation-details .contract-5-pro-rata{color:#4B9609}#bootstrap-theme #calculation-details .calculation-pro-rata{color:#95c0ff}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body{padding-top:20px;padding-bottom:20px}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body .row:first-child h3{margin-top:0}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body h3{margin-bottom:20px}#bootstrap-theme .crm-leave-and-absences-form-block .panel-footer .crm-button:last-child{margin-right:0}#bootstrap-theme.crm-leave-and-balance-import .panel{background-color:#fff}#bootstrap-theme.crm-leave-and-balance-import .panel-header{position:relative}#bootstrap-theme.crm-leave-and-balance-import .panel-header h2{padding:10px 20px}#bootstrap-theme.crm-leave-and-balance-import .panel-body .row:not(:last-child){padding-bottom:2em}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats .label{display:none}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats label{font-weight:normal !important}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats td{border:0;padding:0}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block{box-shadow:none;padding:0}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table{margin-bottom:2em;width:100%}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table th{padding:10px 20px;border-right:none}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table th,#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table td{padding:5px}#bootstrap-theme.crm-leave-and-balance-import #preview-counts,#bootstrap-theme.crm-leave-and-balance-import #summary-counts{box-shadow:none;margin-bottom:2em;width:100%}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td{background-color:#f2dede !important;color:#cf3458}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td a,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td a{color:#bd2d4e;font-weight:bold}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td a:hover,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td a:hover{color:#0062a4}#bootstrap-theme.manage-entitlements-form .wider-hr{margin-left:-20px;margin-right:-20px;border-width:2px}#bootstrap-theme.manage-entitlements-form .wider-row{margin-left:-20px;margin-right:-20px}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters{padding:15px 0;text-align:center}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .override-filters label{display:inline-block}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .override-filters label:before{display:none}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .absence-type-filter{margin-right:10px}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .col-sm-4:last-child{text-align:right}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list{margin-bottom:0}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement-header .title{float:left;width:65%}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement-header .actions{float:right}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list tr.hidden{display:none}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .absence-type{color:#fff;display:inline-block;padding:5px}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement .overridden-proposed-entitlement,#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement .calculation-unit{display:none}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .borderless-button{background-color:transparent;border:0;cursor:pointer}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .add-comment{font-size:1.1em}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .comment-text{display:none}#bootstrap-theme.manage-entitlements-form .manage-entitlements-form__filters{padding-bottom:1em}#bootstrap-theme.manage-entitlements-form .table{background:#f9f9f9;border-top:1px solid #e8eef0;border-bottom:1px solid #e8eef0;margin-bottom:2em}#bootstrap-theme.manage-entitlements-form .table th{background:#f3f6f7 !important}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header{border-left:1px solid #e8eef0;border-right:1px solid #e8eef0;background:#e4ebed !important;min-width:200px}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .row>div{display:table-cell;float:none;vertical-align:bottom}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .fa{color:#4d4d69}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .action-button-container{padding:0}#bootstrap-theme.manage-entitlements-form .table td.proposed-entitlement{border-left:1px solid #e8eef0;border-right:1px solid #e8eef0;background:white}#bootstrap-theme.manage-entitlements-form .table span.absence-type{border-radius:3px;padding:0 5px}#bootstrap-theme.manage-entitlements-form .table tbody .fa{color:#0071bd}#bootstrap-theme.manage-entitlements-form .crm-container .CRM_HRLeaveAndAbsences_Form_ManageEntitlements .crm-button-type-next{float:right !important}#bootstrap-theme.manage-entitlements-form .panel-footer{border-top:none}#add-comment-dialog{display:none}#add-comment-dialog .calculation_comment{box-sizing:border-box;padding:10px;width:100%}#bootstrap-theme .crm-work-pattern-form-block .ui-tabs.ui-widget-content{background:none}#bootstrap-theme .work-pattern-calendar .number-of-weeks{padding:15px 0 15px 0}#bootstrap-theme .work-pattern-calendar .work-pattern-week{border-top:1px solid rgba(0,0,0,0.2);padding:15px 0 15px 0;margin-bottom:15px}#bootstrap-theme .work-pattern-calendar .work-pattern-week.hidden-week{display:none}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-number{float:left;font-weight:bold;padding:5px 0 15px 5px}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days{table-layout:fixed}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-hours{float:right;padding:5px 5px 15px 0}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-hours .number-of-hours{font-weight:bold}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days td{padding:5px 10px 5px 10px}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days input{min-width:0;text-align:center}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days select{min-width:0;width:100% !important}#bootstrap-theme .work-pattern-calendar .work-pattern-week .hours-row td{padding-top:15px;padding-bottom:15px;border-top:1px solid rgba(0,0,0,0.2);border-bottom:1px solid rgba(0,0,0,0.2)}.caret{display:inline-block;width:0;height:0;margin-left:2px;vertical-align:middle;border-top:4px dashed;border-top:4px solid \9;border-right:4px solid transparent;border-left:4px solid transparent}.dropup,.dropdown{position:relative}.dropdown-toggle:focus{outline:0}.dropdown-menu{position:absolute;top:100%;left:0;z-index:1000;display:none;float:left;min-width:160px;padding:5px 0;margin:2px 0 0;list-style:none;font-size:13px;text-align:left;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.15);border-radius:2px;-webkit-box-shadow:0 6px 12px rgba(0,0,0,0.175);box-shadow:0 6px 12px rgba(0,0,0,0.175);background-clip:padding-box}.dropdown-menu.pull-right{right:0;left:auto}.dropdown-menu .divider{height:1px;margin:9px 0;overflow:hidden;background-color:#e5e5e5}.dropdown-menu>li>a{display:block;padding:3px 20px;clear:both;font-weight:normal;line-height:1.5384615385;color:#4d4d69;white-space:nowrap}.dropdown-menu>li>a:hover,.dropdown-menu>li>a:focus{text-decoration:none;color:#42425a;background-color:#f3f6f7}.dropdown-menu>.active>a,.dropdown-menu>.active>a:hover,.dropdown-menu>.active>a:focus{color:#fff;text-decoration:none;outline:0;background-color:#0071bd}.dropdown-menu>.disabled>a,.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{color:#e8eef0}.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{text-decoration:none;background-color:transparent;background-image:none;filter:progid:DXImageTransform.Microsoft.gradient(enabled = false);cursor:not-allowed}.open>.dropdown-menu{display:block}.open>a{outline:0}.dropdown-menu-right{left:auto;right:0}.dropdown-menu-left{left:0;right:auto}.dropdown-header{display:block;padding:3px 20px;font-size:12px;line-height:1.5384615385;color:#464354;white-space:nowrap}.dropdown-backdrop{position:fixed;left:0;right:0;bottom:0;top:0;z-index:990}.pull-right>.dropdown-menu{right:0;left:auto}.dropup .caret,.navbar-fixed-bottom .dropdown .caret{border-top:0;border-bottom:4px dashed;border-bottom:4px solid \9;content:""}.dropup .dropdown-menu,.navbar-fixed-bottom .dropdown .dropdown-menu{top:auto;bottom:100%;margin-bottom:2px}@media (min-width: 768px){.navbar-right .dropdown-menu{right:0;left:auto}.navbar-right .dropdown-menu-left{left:0;right:auto}}.dropdown-header{padding:11px 20px}.dropdown-menu{-webkit-box-shadow:0 3px 18px 0 rgba(48,40,40,0.25);box-shadow:0 3px 18px 0 rgba(48,40,40,0.25);border:0;margin:0;padding:0}.dropdown-menu>li{border:0;margin:0;padding:0}.dropdown-menu>li>a{padding:11px 20px} +#bootstrap-theme .chr_disabled{opacity:0.5;pointer-events:none}#bootstrap-theme .table-condensed>thead>tr>th{background:#fff !important;padding:8px 5px}#bootstrap-theme .table-condensed-mixed>thead>tr>th,#bootstrap-theme .table-condensed-mixed>thead>tr>td,#bootstrap-theme .table-condensed-mixed>tbody>tr>th,#bootstrap-theme .table-condensed-mixed>tbody>tr>td{padding-left:5px;padding-right:5px}#bootstrap-theme .table-condensed>tbody>tr>td:first-child,#bootstrap-theme .table-condensed>tbody>tr>th:first-child,#bootstrap-theme .table-condensed>thead>tr>td:first-child,#bootstrap-theme .table-condensed>thead>tr>th:first-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>td:first-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>th:first-child,#bootstrap-theme .table-condensed-mixed>thead>tr>td:first-child,#bootstrap-theme .table-condensed-mixed>thead>tr>th:first-child{padding-left:20px}#bootstrap-theme .table-condensed>tbody>tr>td:last-child,#bootstrap-theme .table-condensed>tbody>tr>th:last-child,#bootstrap-theme .table-condensed>thead>tr>td:last-child,#bootstrap-theme .table-condensed>thead>tr>th:last-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>td:last-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>th:last-child,#bootstrap-theme .table-condensed-mixed>thead>tr>td:last-child,#bootstrap-theme .table-condensed-mixed>thead>tr>th:last-child{padding-right:20px}#bootstrap-theme .table-nested{overflow-y:hidden;position:relative}#bootstrap-theme .table-nested:before{box-shadow:inset 0px 6px 9px -6px rgba(0,0,0,0.2);content:'';display:block;height:10px;left:0;position:absolute;top:0;width:100%;z-index:10}#bootstrap-theme .table-nested:after{box-shadow:inset 0px -4px 9px -6px rgba(0,0,0,0.2);content:'';display:block;height:10px;left:0;position:absolute;bottom:0;width:100%;z-index:10}#bootstrap-theme .table-nested>table,#bootstrap-theme .table-nested>.table{background-color:#fff}#bootstrap-theme .table-nested>table>tbody>tr>td:first-child,#bootstrap-theme .table-nested>table>tbody>tr>th:first-child,#bootstrap-theme .table-nested>table>thead>tr>td:first-child,#bootstrap-theme .table-nested>table>thead>tr>th:first-child,#bootstrap-theme .table-nested>.table>tbody>tr>td:first-child,#bootstrap-theme .table-nested>.table>tbody>tr>th:first-child,#bootstrap-theme .table-nested>.table>thead>tr>td:first-child,#bootstrap-theme .table-nested>.table>thead>tr>th:first-child{padding-left:30px;position:relative}#bootstrap-theme .table-nested>table>tbody>tr>td:first-child:before,#bootstrap-theme .table-nested>table>tbody>tr>th:first-child:before,#bootstrap-theme .table-nested>table>thead>tr>td:first-child:before,#bootstrap-theme .table-nested>table>thead>tr>th:first-child:before,#bootstrap-theme .table-nested>.table>tbody>tr>td:first-child:before,#bootstrap-theme .table-nested>.table>tbody>tr>th:first-child:before,#bootstrap-theme .table-nested>.table>thead>tr>td:first-child:before,#bootstrap-theme .table-nested>.table>thead>tr>th:first-child:before{background:#c2cfd8;content:'';display:block;height:110%;left:0;position:absolute;top:0;width:10px;z-index:2}#bootstrap-theme .table-nested>table>tbody>tr>td:last-child,#bootstrap-theme .table-nested>table>tbody>tr>th:last-child,#bootstrap-theme .table-nested>table>thead>tr>td:last-child,#bootstrap-theme .table-nested>table>thead>tr>th:last-child,#bootstrap-theme .table-nested>.table>tbody>tr>td:last-child,#bootstrap-theme .table-nested>.table>tbody>tr>th:last-child,#bootstrap-theme .table-nested>.table>thead>tr>td:last-child,#bootstrap-theme .table-nested>.table>thead>tr>th:last-child{padding-right:30px;position:relative}#bootstrap-theme .table-nested>table>tbody>tr>td:last-child:after,#bootstrap-theme .table-nested>table>tbody>tr>th:last-child:after,#bootstrap-theme .table-nested>table>thead>tr>td:last-child:after,#bootstrap-theme .table-nested>table>thead>tr>th:last-child:after,#bootstrap-theme .table-nested>.table>tbody>tr>td:last-child:after,#bootstrap-theme .table-nested>.table>tbody>tr>th:last-child:after,#bootstrap-theme .table-nested>.table>thead>tr>td:last-child:after,#bootstrap-theme .table-nested>.table>thead>tr>th:last-child:after{background:#c2cfd8;content:'';display:block;height:110%;right:0;position:absolute;top:0;width:10px;z-index:2}@media screen and (max-width: 767px){#bootstrap-theme .table-nested.table-responsive{border:0;margin-bottom:0}}#bootstrap-theme .table-nested-cell{padding:0 !important}#bootstrap-theme .chr_absence-work-pattern__add-custom{margin-bottom:20px}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(1){width:40%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(2){width:15%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(3){width:35%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(4){width:10%}#bootstrap-theme .chr_absence-work-pattern__work-pattern-listing{display:inline-block}#bootstrap-theme .chr_absence-work-pattern__alert{margin-bottom:0 !important}#bootstrap-theme .annual-entitlement-change-log-component thead td{min-width:100px}#bootstrap-theme .annual-entitlement-change-log-component thead .annual-entitlement-change-log-component__comments{min-width:300px}#bootstrap-theme .chr_annual-entitlements__period{width:130px}#bootstrap-theme .chr_annual-entitlements__edit-entitlements{width:150px}#bootstrap-theme .chr_contract-entitlements__position{width:140px}@media (max-width: 992px){#bootstrap-theme .chr_leave-balance-tab .chr_leave-balance-tab__filter:not(:last-child){padding-bottom:15px}}#bootstrap-theme .chr_leave-balance-tab__body{padding:0}@media (min-width: 1200px){#bootstrap-theme .chr_leave-calendar__dates-container .chr_leave-calendar{table-layout:fixed}}#bootstrap-theme .chr_leave-calendar__names-container .chr_leave-calendar{table-layout:fixed}#bootstrap-theme .chr_leave-calendar__day{font-size:10px !important;line-height:1.4em !important;padding:10px !important;text-align:center !important}@media (min-width: 1200px){#bootstrap-theme .chr_leave-calendar__day{padding:10px 0 !important}}#bootstrap-theme .chr_leave-calendar__day--disabled{opacity:0.5}#bootstrap-theme .chr_leave-calendar__day--current{color:#0071bd !important}#bootstrap-theme .chr_leave-calendar__item{color:#FFF;display:block;font-size:10px;height:100%;position:relative;text-align:center;text-transform:uppercase;width:100%}#bootstrap-theme .chr_leave-calendar__item>span{bottom:0;left:0;margin:auto;position:absolute;right:0;top:0;height:1.2em}#bootstrap-theme .chr_leave-calendar__item>.chr_leave-calendar__time-unit{font-size:7px;height:1em;margin-left:-1px}#bootstrap-theme .chr_leave-calendar__item>a{cursor:pointer;bottom:0;left:0;margin:auto;position:absolute;right:0;top:0}#bootstrap-theme .chr_leave-calendar__item--disabled{cursor:not-allowed;opacity:0.5}#bootstrap-theme .chr_leave-calendar__item--type--late{background-color:#eca67e;border-color:#eca67e}#bootstrap-theme .chr_leave-calendar__item--type--non-working{background-color:#41afcb !important;border-color:#41afcb}#bootstrap-theme .chr_leave-calendar__item--type--public-holiday{background-color:#8ec68a !important;border-color:#8ec68a}#bootstrap-theme .chr_leave-calendar__item--type--weekend{background-color:#c7cbd0 !important;border-color:#c7cbd0}#bootstrap-theme .chr_leave-calendar__item--alt{background:#FFF !important;border:1px solid transparent;color:#464354}#bootstrap-theme .chr_leave-calendar__item--requested:before{background:#c7cbd0;content:'';display:block;height:.5em;position:absolute;width:100%;top:0}#bootstrap-theme .chr_leave-calendar__item--toil-requested:before{background:red;content:'';display:block;height:.5em;left:-1px;position:absolute;width:calc(100% + 2px);top:-1px}#bootstrap-theme .chr_leave-calendar__items>td{overflow:hidden;height:35px;padding:0 !important}#bootstrap-theme .chr_leave-calendar__items leave-calendar-day{display:block;height:100%}#bootstrap-theme .chr_leave-calendar__legend__title{font-size:12px}#bootstrap-theme .chr_leave-calendar__legend>.row:not(:first-child){margin-top:20px}#bootstrap-theme .chr_leave-calendar__legend .chr_leave-calendar__legend__entry{margin-top:10px}@media (min-width: 768px){#bootstrap-theme .chr_leave-calendar__legend .chr_leave-calendar__legend__entry{margin-top:0}}#bootstrap-theme .chr_leave-calendar__legend__entry{overflow:auto}#bootstrap-theme .chr_leave-calendar__legend__entry+#bootstrap-theme .chr_leave-calendar__legend__entry{margin-top:10px}#bootstrap-theme .chr_leave-calendar__legend__entry>.chr_leave-calendar__item{font-size:8px;height:20px;margin-right:10px;position:absolute;width:20px}#bootstrap-theme .chr_leave-calendar__legend__label{display:inline-block;font-size:12px;margin-left:26px}#bootstrap-theme .chr_leave-calendar__month-header{background:#f3f6f7}#bootstrap-theme .chr_leave-calendar__month-header .panel-title{font-size:16px}#bootstrap-theme td.chr_leave-calendar__name,#bootstrap-theme th.chr_leave-calendar__name{font-size:12px !important;line-height:100%;padding:0 20px !important;text-align:left;text-overflow:ellipsis;width:100%}#bootstrap-theme th.chr_leave-calendar__name,#bootstrap-theme th.chr_leave-calendar__day{height:49px}#bootstrap-theme th.chr_leave-calendar__name{padding-bottom:10px !important}#bootstrap-theme td.chr_leave-calendar__name{vertical-align:middle !important}#bootstrap-theme .chr_leave-calendar__pagination{font-size:10px;text-align:center}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"]{outline:none;padding:0;line-height:1em}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"] .fa{color:#555}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"][disabled] .fa{opacity:0.5}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"]:hover:not([disabled]) .fa{color:#464354}#bootstrap-theme .chr_leave-calendar__pagination-next{border-top:none}#bootstrap-theme .chr_leave-calendar__pagination-next th{height:24px;padding:4px 0 6px !important}#bootstrap-theme .chr_leave-calendar__pagination-next .chr_leave-calendar__pagination{padding-right:3px !important}#bootstrap-theme .chr_leave-calendar__month-container{margin:0}#bootstrap-theme .chr_leave-calendar__month-container>div{padding:0}#bootstrap-theme .chr_leave-calendar__dates-container{overflow-x:auto}#bootstrap-theme .chr_leave-calendar__admin-filters-hint{display:inline-block;font-size:20px;vertical-align:middle}#bootstrap-theme .chr_leave-calendar__admin-filters-select{width:calc(100% - 50px);display:inline-block;margin-right:20px}#bootstrap-theme .chr_leave-report .dropdown-toggle{color:#464354;padding:0 10px}#bootstrap-theme .chr_leave-report .dropdown-toggle:hover{background:#e6e6e6}#bootstrap-theme .chr_leave-report table{table-layout:fixed}#bootstrap-theme .chr_leave-report table thead th,#bootstrap-theme .chr_leave-report table tbody td{padding:8px 5px}#bootstrap-theme .chr_leave-report__label{color:#464354;font-weight:700}#bootstrap-theme .chr_leave-report__label>.fa{margin-right:5px}#bootstrap-theme .chr_leave-report__label--toggle{cursor:pointer;user-select:none}#bootstrap-theme .chr_leave-report__heading{background-color:#f3f6f7;border-bottom:1px solid #dadcde}#bootstrap-theme .chr_leave-report__heading .chr_leave-report__export-button{line-height:2.4}#bootstrap-theme .chr_leave-report__table table,#bootstrap-theme .chr_leave-report__table .table{border-collapse:separate}#bootstrap-theme .chr_leave-report__table table>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>tbody>tr:first-child>td{border-top-width:0}#bootstrap-theme .chr_leave-report__table table>thead+tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>thead+tbody>tr:first-child>td{border-top-width:1px}#bootstrap-theme .chr_leave-report__table table:not(.table-bordered):not(.table-condensed)>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table:not(.table-bordered):not(.table-condensed)>tbody>tr:first-child>td{border-color:#f3f6f7}#bootstrap-theme .chr_leave-report__table table>thead>tr>th,#bootstrap-theme .chr_leave-report__table .table>thead>tr>th{background:#f3f6f7;border-bottom:0;color:#464354;text-transform:capitalize}#bootstrap-theme .chr_leave-report__table table>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>tbody>tr:first-child>td{border-color:#e8eef0 !important}#bootstrap-theme .chr_leave-report__table table>tfoot>tr,#bootstrap-theme .chr_leave-report__table .table>tfoot>tr{background:#f3f6f7}#bootstrap-theme .chr_leave-report__table>table>thead>tr>th,#bootstrap-theme .chr_leave-report__table>.table>thead>tr>th{padding-bottom:13px;padding-top:13px}#bootstrap-theme .chr_leave-report__table-container{overflow:auto}#bootstrap-theme .chr_leave-report__table-container .panel{display:inline-block;min-width:100%}#bootstrap-theme .chr_leave-report__table__heading--action{width:45px}#bootstrap-theme .chr_leave-report__table__heading--label{width:280px}#bootstrap-theme .chr_leave-report__table__heading--dates{width:170px}#bootstrap-theme .chr_leave-report__table__heading--status{width:180px}#bootstrap-theme .chr_leave-report__table__heading--type{width:65px;word-break:break-word}#bootstrap-theme .chr_leave-request-comment{margin-top:10px}#bootstrap-theme .chr_leave-request-comment__text{border-bottom:1px solid #e8eef0;color:#c2cfd8;margin-right:10px;padding-bottom:20px}#bootstrap-theme .chr_leave-request-files_list{height:150px;overflow-y:auto;margin-top:20px;margin-bottom:20px}#bootstrap-theme .chr_leave-request-files_meta{margin-bottom:10px}#bootstrap-theme .chr_leave-request-files_upload{border:dashed 1px #464354;padding:20px}#bootstrap-theme .chr_leave-request-files_upload_action{padding:5px}#bootstrap-theme .chr_leave-request-files_file-name{display:inline-block;max-width:240px;overflow:hidden;text-overflow:ellipsis;vertical-align:bottom}#bootstrap-theme .chr_leave-request-files_delete{margin-top:-7px}#bootstrap-theme .chr_leave-request-modal .modal-title{font-size:18px !important}#bootstrap-theme .chr_leave-request-modal .table-responsive{border:0}#bootstrap-theme .chr_leave-request-modal .chr_leave-request-date-picker-container .input-group{width:100%}@media screen and (max-width: 767px){#bootstrap-theme .chr_leave-request-modal .chr_leave-request-date-picker-container{margin-bottom:10px}}#bootstrap-theme .chr_leave-request-modal__chevron{font-size:0.6em;margin-right:5px;vertical-align:middle}#bootstrap-theme .chr_leave-request-modal__comments{height:230px;margin-bottom:20px;overflow:auto}#bootstrap-theme .chr_leave-request-modal__comments_empty{margin-bottom:20px}#bootstrap-theme .chr_leave-request-modal__footer{margin:0}#bootstrap-theme .chr_leave-request-modal__delete{margin-left:15px;margin-top:8px}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container{margin-bottom:20px}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container ul{opacity:1 !important}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container:not(.ui-select-multiple) input{width:100% !important}#bootstrap-theme .chr_leave-request-modal__form-group,#bootstrap-theme .chr_leave-request-modal__required-documents>div{margin-bottom:15px}#bootstrap-theme .chr_leave-request-modal__response{padding:20px 20px 0}#bootstrap-theme .chr_leave-request-modal__response label{font-size:17px;margin-top:-3px}#bootstrap-theme .chr_leave-request-modal__response .chr_wysiwyg{margin-top:15px}#bootstrap-theme .chr_leave-request-modal__required-documents input{margin-right:5px}#bootstrap-theme .chr_leave-request-modal__small_spinner>div.chr_spinner{margin-top:18px;min-height:initial}#bootstrap-theme .chr_leave-request-modal__tab input[uib-datepicker-popup]{font-size:13px}#bootstrap-theme .chr_leave-request-modal__table{border:1px solid #f3f6f7;margin-bottom:15px !important}#bootstrap-theme .chr_leave-request-modal__user-info{font-size:17px;padding:20px}#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(1){color:#464354}#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(2){color:#555}@media screen and (min-width: 480px){#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(2){border-left:1px solid #e8eef0}}#bootstrap-theme .chr_leave-request-modal__span-expiry{display:inline-block;margin-top:7px}#bootstrap-theme .chr_leave-request-modal__expiry-clear{position:absolute;right:3.5em;top:0.6em;z-index:2}#bootstrap-theme .chr_leave-request-modal__small-text{font-size:80%}#bootstrap-theme .chr_leave-request-modal__custom-deduction-toggling-row{margin-top:-5px}@media screen and (min-width: 768px){#bootstrap-theme .chr_leave-request-modal__custom-deduction-label{text-align:right}}@media screen and (max-width: 767px){#bootstrap-theme .chr_leave-request-modal__custom-deduction-label{margin-bottom:10px}}#bootstrap-theme .chr_leave-request-modal .form-group{overflow:inherit !important}#bootstrap-theme .chr_leave-request-modal .alert{margin-bottom:0 !important}#bootstrap-theme .chr_leave-request-modal input[uib-datepicker-popup]{box-shadow:none !important;background-color:inherit !important;color:inherit !important;cursor:pointer !important;border-right:none}#bootstrap-theme leave-request-record-actions{display:block}#bootstrap-theme leave-request-record-actions .leave-request-record-actions__button{display:block;float:left;margin-left:0}#bootstrap-theme leave-request-record-actions .leave-request-record-actions__button:first-child{margin-right:8px}@media screen and (max-width: 767px){#bootstrap-theme leave-request-record-actions .leave-request-record-actions__button{width:100%}#bootstrap-theme leave-request-record-actions .leave-request-record-actions__button>.btn{width:100%}#bootstrap-theme leave-request-record-actions .leave-request-record-actions__button:first-child{margin-bottom:8px;margin-right:0}}#bootstrap-theme .leave-widget h4{color:#4d4d69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px}#bootstrap-theme .leave-widget__types>table,#bootstrap-theme .leave-widget__sickness>table,#bootstrap-theme .leave-widget__next-leave>table{border:none}#bootstrap-theme .leave-widget__types>table thead tr th,#bootstrap-theme .leave-widget__sickness>table thead tr th,#bootstrap-theme .leave-widget__next-leave>table thead tr th{color:#4d4d69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px;background:none;width:35%}#bootstrap-theme .leave-widget__types>table thead tr th:first-child,#bootstrap-theme .leave-widget__sickness>table thead tr th:first-child,#bootstrap-theme .leave-widget__next-leave>table thead tr th:first-child{width:65%}#bootstrap-theme .leave-widget__types>table tbody tr td,#bootstrap-theme .leave-widget__sickness>table tbody tr td,#bootstrap-theme .leave-widget__next-leave>table tbody tr td{color:#0071bd;font-size:16px;font-weight:600;padding-bottom:9px}#bootstrap-theme .leave-widget__types>table tbody tr td:first-child,#bootstrap-theme .leave-widget__sickness>table tbody tr td:first-child,#bootstrap-theme .leave-widget__next-leave>table tbody tr td:first-child{color:#464354}#bootstrap-theme .leave-widget hr{border-color:#DEE4ED;margin-bottom:25px;margin-top:25px}#bootstrap-theme .leave-widget__sickness h4{margin-top:18px}#bootstrap-theme .leave-widget__next-leave h3{font-size:16px;margin-bottom:16px;margin-top:0}#bootstrap-theme .leave-widget__next-leave__deduction{font-size:16px;font-weight:600;color:#464354}#bootstrap-theme .chr_leave__page-selector-dropdown{margin-right:5px;position:relative;top:1px;width:100%}#bootstrap-theme .chr_leave__page-selector-dropdown select{height:40px}#bootstrap-theme .chr_leave__page-selector-dropdown .crm_custom-select__arrow{line-height:40px;width:40px}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;border-bottom:1px solid #dadcde;margin:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header .panel-title{margin-top:7px;display:inline-block}@media screen and (max-width: 992px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header>div:not(:last-child),#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header .panel-title{padding-bottom:20px}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter{display:inline-block;margin-top:7px;white-space:nowrap}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter .fa{font-size:0.6em;margin-right:5px;margin-top:-2px;vertical-align:middle}@media screen and (max-width: 991px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter{margin-top:15px}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;border-bottom:1px solid #dadcde;margin:0;padding-top:15px}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>*{padding-left:10px !important;padding-right:10px !important}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>div:not(:last-child){padding-bottom:20px}}@media screen and (min-width: 992px) and (max-width: 1199px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>.no_gutter{padding-bottom:0 !important}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body{margin:0;padding:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body [class^="col-"],#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body [class*=" col-"]{padding:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body a{cursor:pointer}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container{padding-left:10px;padding-right:10px;background-color:#f7f7f9}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container>div{padding-left:15px;padding-right:15px}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .form-group{overflow:inherit !important}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .panel{background-image:none !important}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .panel-body,#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .chr_vertical_tabs{background-color:#f7f7f9}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] input[type="search"]{width:100% !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header .checkbox{margin-top:5px}#bootstrap-theme .page-manager-leave .chr_manage_leave_requests .btn-sm{font-size:100% !important}#bootstrap-theme .chr_manager_calendar__header{padding-left:10px;padding-right:10px;padding-top:15px;margin:0;background-color:#f7f7f9;border-bottom:1px solid #dadcde}#bootstrap-theme .chr_manager_calendar__header>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manager_calendar__header .checkbox{margin:0}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manager_calendar__header>div:not(:last-child){padding-bottom:20px}}#bootstrap-theme .chr_manager_calendar__sub-header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;margin:0}#bootstrap-theme .chr_manager_calendar__sub-header>*{padding-left:10px !important;padding-right:10px !important}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manager_calendar__sub-header>div:not(:last-child){padding-bottom:20px}#bootstrap-theme .chr_manager_calendar__sub-header .ui-select-container{height:auto}}#bootstrap-theme .time-amount-picker .crm_custom-select{display:inline-block;margin-right:2px}#bootstrap-theme .time-amount-picker .crm_custom-select:nth-child(2){margin-left:10px}#bootstrap-theme .absence-tab-page .tab-pane{padding:0 !important}#bootstrap-theme .absence-tab-page .tab-content{background-color:transparent !important}#bootstrap-theme .absence-tab-page leave-request-record-actions{margin-bottom:20px}#bootstrap-theme .crm-absence_type-form-block .crm-section .label{width:35%}#bootstrap-theme .crm-absence_type-form-block .crm-section .content{margin-left:40%}#bootstrap-theme .crm-absence_type-form-block .toil-option,#bootstrap-theme .crm-absence_type-form-block .carry-forward-option,#bootstrap-theme .crm-absence_type-form-block .toil-expiration,#bootstrap-theme .crm-absence_type-form-block .carry-forward-expiration-duration,#bootstrap-theme .crm-absence_type-form-block .carry-forward-expiration-date{display:none}#bootstrap-theme .crm-absence_type-form-block .sp-replacer{padding:2px}#bootstrap-theme .crm-absence_type-form-block .sp-preview{height:15px;width:15px}#bootstrap-theme .crm-absence_type-form-block .sp-dd{height:0;line-height:15px;font-size:9px}.page-civicrm-leaveandabsences-dashboard .page-title,.page-civicrm-leaveandabsences-dashboard #branding{display:none !important}.page-civicrm-leaveandabsences-dashboard #page{margin:0;padding:0}.admin-dashboard-page{position:relative}.admin-dashboard-page .crm_page__topbar{height:65px}.admin-dashboard-page leave-request-record-actions{margin:12px 16px 0 0}.admin-dashboard-page .chr_admin-dashboard_side-nav{background-color:#fff;height:calc(100% - 12px);overflow:hidden;position:absolute;width:170px}.admin-dashboard-page .chr_admin-dashboard_side-nav .active{background:#e8eef0}.admin-dashboard-page .chr_admin-dashboard_content{float:right;margin:16px;margin-bottom:0;width:calc(100% - 170px - 16px * 2)}#bootstrap-theme #calculation-details{background:#fff}#bootstrap-theme #calculation-details .base-contractual-entitlement{color:#0071bd}#bootstrap-theme #calculation-details .working-days-to-work{color:#44cb7e}#bootstrap-theme #calculation-details .working-days-in-period{color:#e6ab5e}#bootstrap-theme #calculation-details .contract-1-pro-rata{color:#E6807F}#bootstrap-theme #calculation-details .contract-2-pro-rata{color:#797300}#bootstrap-theme #calculation-details .contract-3-pro-rata{color:#904E1E}#bootstrap-theme #calculation-details .contract-4-pro-rata{color:#0511B1}#bootstrap-theme #calculation-details .contract-5-pro-rata{color:#4B9609}#bootstrap-theme #calculation-details .calculation-pro-rata{color:#95c0ff}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body{padding-top:20px;padding-bottom:20px}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body .row:first-child h3{margin-top:0}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body h3{margin-bottom:20px}#bootstrap-theme .crm-leave-and-absences-form-block .panel-footer .crm-button:last-child{margin-right:0}#bootstrap-theme.crm-leave-and-balance-import .panel{background-color:#fff}#bootstrap-theme.crm-leave-and-balance-import .panel-header{position:relative}#bootstrap-theme.crm-leave-and-balance-import .panel-header h2{padding:10px 20px}#bootstrap-theme.crm-leave-and-balance-import .panel-body .row:not(:last-child){padding-bottom:2em}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats .label{display:none}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats label{font-weight:normal !important}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats td{border:0;padding:0}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block{box-shadow:none;padding:0}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table{margin-bottom:2em;width:100%}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table th{padding:10px 20px;border-right:none}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table th,#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table td{padding:5px}#bootstrap-theme.crm-leave-and-balance-import #preview-counts,#bootstrap-theme.crm-leave-and-balance-import #summary-counts{box-shadow:none;margin-bottom:2em;width:100%}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td{background-color:#f2dede !important;color:#cf3458}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td a,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td a{color:#bd2d4e;font-weight:bold}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td a:hover,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td a:hover{color:#0062a4}#bootstrap-theme.manage-entitlements-form .wider-hr{margin-left:-20px;margin-right:-20px;border-width:2px}#bootstrap-theme.manage-entitlements-form .wider-row{margin-left:-20px;margin-right:-20px}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters{padding:15px 0;text-align:center}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .override-filters label{display:inline-block}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .override-filters label:before{display:none}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .absence-type-filter{margin-right:10px}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .col-sm-4:last-child{text-align:right}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list{margin-bottom:0}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement-header .title{float:left;width:65%}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement-header .actions{float:right}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list tr.hidden{display:none}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .absence-type{color:#fff;display:inline-block;padding:5px}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement .overridden-proposed-entitlement,#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement .calculation-unit{display:none}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .borderless-button{background-color:transparent;border:0;cursor:pointer}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .add-comment{font-size:1.1em}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .comment-text{display:none}#bootstrap-theme.manage-entitlements-form .manage-entitlements-form__filters{padding-bottom:1em}#bootstrap-theme.manage-entitlements-form .table{background:#f9f9f9;border-top:1px solid #e8eef0;border-bottom:1px solid #e8eef0;margin-bottom:2em}#bootstrap-theme.manage-entitlements-form .table th{background:#f3f6f7 !important}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header{border-left:1px solid #e8eef0;border-right:1px solid #e8eef0;background:#e4ebed !important;min-width:200px}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .row>div{display:table-cell;float:none;vertical-align:bottom}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .fa{color:#4d4d69}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .action-button-container{padding:0}#bootstrap-theme.manage-entitlements-form .table td.proposed-entitlement{border-left:1px solid #e8eef0;border-right:1px solid #e8eef0;background:white}#bootstrap-theme.manage-entitlements-form .table span.absence-type{border-radius:3px;padding:0 5px}#bootstrap-theme.manage-entitlements-form .table tbody .fa{color:#0071bd}#bootstrap-theme.manage-entitlements-form .crm-container .CRM_HRLeaveAndAbsences_Form_ManageEntitlements .crm-button-type-next{float:right !important}#bootstrap-theme.manage-entitlements-form .panel-footer{border-top:none}#add-comment-dialog{display:none}#add-comment-dialog .calculation_comment{box-sizing:border-box;padding:10px;width:100%}#bootstrap-theme .crm-work-pattern-form-block .ui-tabs.ui-widget-content{background:none}#bootstrap-theme .work-pattern-calendar .number-of-weeks{padding:15px 0 15px 0}#bootstrap-theme .work-pattern-calendar .work-pattern-week{border-top:1px solid rgba(0,0,0,0.2);padding:15px 0 15px 0;margin-bottom:15px}#bootstrap-theme .work-pattern-calendar .work-pattern-week.hidden-week{display:none}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-number{float:left;font-weight:bold;padding:5px 0 15px 5px}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days{table-layout:fixed}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-hours{float:right;padding:5px 5px 15px 0}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-hours .number-of-hours{font-weight:bold}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days td{padding:5px 10px 5px 10px}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days input{min-width:0;text-align:center}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days select{min-width:0;width:100% !important}#bootstrap-theme .work-pattern-calendar .work-pattern-week .hours-row td{padding-top:15px;padding-bottom:15px;border-top:1px solid rgba(0,0,0,0.2);border-bottom:1px solid rgba(0,0,0,0.2)}.caret{display:inline-block;width:0;height:0;margin-left:2px;vertical-align:middle;border-top:4px dashed;border-top:4px solid \9;border-right:4px solid transparent;border-left:4px solid transparent}.dropup,.dropdown{position:relative}.dropdown-toggle:focus{outline:0}.dropdown-menu{position:absolute;top:100%;left:0;z-index:1000;display:none;float:left;min-width:160px;padding:5px 0;margin:2px 0 0;list-style:none;font-size:13px;text-align:left;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.15);border-radius:2px;-webkit-box-shadow:0 6px 12px rgba(0,0,0,0.175);box-shadow:0 6px 12px rgba(0,0,0,0.175);background-clip:padding-box}.dropdown-menu.pull-right{right:0;left:auto}.dropdown-menu .divider{height:1px;margin:9px 0;overflow:hidden;background-color:#e5e5e5}.dropdown-menu>li>a{display:block;padding:3px 20px;clear:both;font-weight:normal;line-height:1.5384615385;color:#4d4d69;white-space:nowrap}.dropdown-menu>li>a:hover,.dropdown-menu>li>a:focus{text-decoration:none;color:#42425a;background-color:#f3f6f7}.dropdown-menu>.active>a,.dropdown-menu>.active>a:hover,.dropdown-menu>.active>a:focus{color:#fff;text-decoration:none;outline:0;background-color:#0071bd}.dropdown-menu>.disabled>a,.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{color:#e8eef0}.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{text-decoration:none;background-color:transparent;background-image:none;filter:progid:DXImageTransform.Microsoft.gradient(enabled = false);cursor:not-allowed}.open>.dropdown-menu{display:block}.open>a{outline:0}.dropdown-menu-right{left:auto;right:0}.dropdown-menu-left{left:0;right:auto}.dropdown-header{display:block;padding:3px 20px;font-size:12px;line-height:1.5384615385;color:#464354;white-space:nowrap}.dropdown-backdrop{position:fixed;left:0;right:0;bottom:0;top:0;z-index:990}.pull-right>.dropdown-menu{right:0;left:auto}.dropup .caret,.navbar-fixed-bottom .dropdown .caret{border-top:0;border-bottom:4px dashed;border-bottom:4px solid \9;content:""}.dropup .dropdown-menu,.navbar-fixed-bottom .dropdown .dropdown-menu{top:auto;bottom:100%;margin-bottom:2px}@media (min-width: 768px){.navbar-right .dropdown-menu{right:0;left:auto}.navbar-right .dropdown-menu-left{left:0;right:auto}}.dropdown-header{padding:11px 20px}.dropdown-menu{-webkit-box-shadow:0 3px 18px 0 rgba(48,40,40,0.25);box-shadow:0 3px 18px 0 rgba(48,40,40,0.25);border:0;margin:0;padding:0}.dropdown-menu>li{border:0;margin:0;padding:0}.dropdown-menu>li>a{padding:11px 20px} diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js index d8af6d230a1..d718ba04f66 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js @@ -1,5 +1,5 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,o){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,r){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),r=e.assign({},r,{absence_type_id:a,date:t(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",r).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,o,s,r){return t.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return s.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,o,s,r){return this.sendPOST("ContactWorkPattern","create",e.assign({},r,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,o,s){return t.debug("WorkPatternAPI.getCalendar",n,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,o){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,o,s,r){function i(t,n){return u().then(function(a){var o=this.days[c(t).valueOf()];return!!o&&e.find(a,function(e){return e.name===n}).value===o.type}.bind(this))}function c(e){return t(e,s.serverDateFormat).clone()}function u(){return l=l||r.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[c(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,o){return t.debug("Calendar"),n.extend({get:function(n,s,r,i){return t.debug("Calendar.get"),a.getCalendar(n,s,r,i).then(function(t){var a=t.values.map(function(e){return o.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function o(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,o,s){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return o.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,o,s,r){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,o,s,"getFull",r)),i.promise},balanceChangeByAbsenceType:function(t,n,o,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var r=a.defer();t&&n||r.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:o?{IN:o}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){r.resolve(e.values)}),r.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?o.reject(t(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,o,s,r,i,c){function u(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),r=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(r.date)]).then(function(t){return s.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,o&&(r.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return r.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(s.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,o,s,r){return n.all(this.processFilters(e),t,o,s,r).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,o){return n.balanceChangeByAbsenceType(e,t,a,o)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/instances/work-pattern.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("WorkPatternInstance",["$log","ModelInstance",function(e,t){return e.debug("WorkPatternInstance"),t.extend({})}])}),define("leave-absences/shared/models/work-pattern.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/work-pattern.instance"],function(e,t){"use strict";t.factory("WorkPattern",["$log","Model","WorkPatternAPI","WorkPatternInstance",function(t,n,a,o){return t.debug("WorkPattern"),n.extend({assignWorkPattern:function(e,t,n,o,s,r){return a.assignWorkPattern(e,t,n,o,s,r)},default:function(){return a.get({is_default:!0}).then(function(t){return o.init(e.first(t),!0)})},unassignWorkPattern:function(e){return a.unassignWorkPattern(e)},workPatternsOf:function(e,t,n){return a.workPatternsOf(e,t,n).then(function(e){return e.map(function(e){return o.init(e,!0)})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,o,s,r,i){function c(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function u(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?c():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return o.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):r.all()}function m(e){return"me"===e?o.leaveManagees(v.contactId):"unassigned"===e?o.leaveManagees(void 0,{unassigned:!0}):o.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

","

People I approve filter displays only staff members who you approve leave for.

","

People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

"].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,u()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:r.contactId}).leaveManagees().then(function(e){r.lookupContacts=e}).then(o)}}}function o(){return t.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:r.filters.userSettings.department?r.filters.userSettings.department.value:null,level_type:r.filters.userSettings.level_type?r.filters.userSettings.level_type.value:null,location:r.filters.userSettings.location?r.filters.userSettings.location.value:null,region:r.filters.userSettings.region?r.filters.userSettings.region.value:null,id:{IN:r.filters.userSettings.contact?[r.filters.userSettings.contact.id]:r.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var r;return{init:function(e){return r=e,r.showContactName=!0,r.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function o(a,o,s,r,i,c,u,l,d,m){function f(){for(var e=[],t=n(O.selectedPeriod.start_date).clone().startOf("month"),a=n(O.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(A(t)),t.add(1,"month");O.months=e}function p(){r.$new().$watch(function(){return O.selectedMonths},function(t,n){null===n||e.equals(t,n)||w()})}function h(e){O.injectMonths=!0,L("injected").then(function(){w(e)}).then(function(){O.loading.calendar=!1})}function v(){S=a("LeaveCalendar"+t.capitalize(M)+"Controller").init(O)}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function g(){return c.all().then(function(e){O.absencePeriods=t.sortBy(e,"start_date"),O.selectedPeriod=t.find(O.absencePeriods,function(e){return!!e.current})}).then(f).then(I)}function _(){return u.all().then(u.loadCalculationUnits)}function y(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return S.loadContacts().then(function(e){O.contacts=e})}function C(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){O.filters.optionValues.regions=e.hrjc_region,O.filters.optionValues.locations=e.hrjc_location,O.filters.optionValues.levelTypes=e.hrjc_level_type,O.filters.optionValues.departments=e.hrjc_department})}function P(){return l.all()}function D(){return o.all([_(),P(),y()]).then(function(e){O.supportData.absenceTypes=e[0],O.supportData.publicHolidays=e[1],O.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,O.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,O.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,O.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function R(){var e=o.resolve();return O.injectMonths&&(e=L("destroyed"),O.injectMonths=!1),e}function A(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function T(e){e=t.includes(["contacts","period"],e)?e:"period",o.resolve().then(function(){O.loading.calendar=!0}).then(R).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function w(e){var n=O.selectedMonths.length?O.months.filter(function(e){return t.includes(O.selectedMonths,e.index)}):O.months;r.$emit("LeaveCalendar::showMonths",n,!!e)}function I(){O.selectedMonths=[n().month()]}function k(){return O.roleOverride?o.resolve().then(function(){M=O.roleOverride}):o.all([m(i.permissions.admin.administer),m(i.permissions.ssp.manage)]).then(function(e){M=e[0]?"admin":e[1]?"manager":"staff"})}function L(e){return o(function(n){var a=0,o=r.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===O.months.length&&(o(),n())})})}s.debug("Component: leave-calendar");var S,M,O=this;O.absencePeriods=[],O.contacts=[],O.contactIdsToReduceTo=null,O.injectMonths=!1,O.months=[],O.selectedMonths=null,O.selectedPeriod=null,O.showContactName=!1,O.showFilters=!1,O.supportData={},O.loading={calendar:!0,page:!0},O.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},O.labelPeriod=b,O.refresh=T,function(){k().then(p).then(v).then(R).then(g).then(function(){return o.all([q(),D()])}).then(function(){return O.showFilters?C():t.noop}).then(function(){h()}).then(function(){O.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",o]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,o){"use strict";function s(){y.calculationUnit=r(y.supportData.calculationUnits,"value",b.calculation_unit)}function r(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(y.contactData.leaveRequest.from_date).isSame(y.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+y.calculationUnit.name+"-on-"+e+"-tooltip"}function c(){b=r(y.supportData.absenceTypes,"id",y.contactData.leaveRequest.type_id),y.contactData.leaveRequest["type_id.title"]=b.title}function u(){"days"===y.calculationUnit.name&&(g=r(y.supportData.dayTypes,"value",y.contactData.leaveRequest.from_date_type),_=r(y.supportData.dayTypes,"value",y.contactData.leaveRequest.to_date_type),y.contactData.leaveRequest["from_date_type.label"]=g.label,y.contactData.leaveRequest["to_date_type.label"]=_.label)}function l(e,t,n,a,s){e.stopPropagation(),o.openModal(t,n,a,s)}function d(){y.dates.from=new Date(y.contactData.leaveRequest.from_date),y.dates.to=new Date(y.contactData.leaveRequest.to_date)}function m(){y.contactData.isAccruedTOIL?y.label="AT":"days"===y.calculationUnit.name?f():p()}function f(){y.label=y.contactData.isAM?"AM":y.contactData.isPM?"PM":""}function p(){var e=t(y.contactData.leaveRequest.from_date).isSame(y.date,"day"),n=t(y.contactData.leaveRequest.to_date).isSame(y.date,"day");y.label=e?t(y.contactData.leaveRequest.from_date).format("HH:mm"):n?t(y.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){y.tooltipTemplate=y.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){y.contactData&&y.contactData.leaveRequest&&(c(),s(),u(),m(),d(),h()) -})}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,r,i,c){function u(e){_([e]),N(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return U[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){S(e),N(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=R(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){F.push(o.$on("LeaveCalendar::showMonths",x)),F.push(i.subscribe("LeaveRequest::new",u)),F.push(i.subscribe("LeaveRequest::edit",B)),F.push(i.subscribe("LeaveRequest::updatedByManager",B)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function P(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function D(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function R(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function A(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function T(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function w(){return[T(c.statusNames.approved),T(c.statusNames.adminApproved),T(c.statusNames.awaitingApproval),T(c.statusNames.moreInformationRequired)]}function I(){return H.month.loading=!0,a.all([L(),k()]).then(b).then($).then(function(){j=!0}).then(function(){H.month.loading=!1})}function k(){return r.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:w()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function L(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function S(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function M(){o.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function O(t,n,o){var s,r;return t.contactsData[n]=t.contactsData[n]||{},r=m(n),s=!0===o?a.resolve():a.all([r.isWeekend(p(t.date)),r.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:P(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?D(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function $(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return O(e,t.id)}))}))}function x(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!j)&&I())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=A(e);t&&(h(t),-1!==w().indexOf(e.status_id)&&u(e))}function N(e){return a.all(R(e).map(function(t){return O(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var j=!1,F=[],U={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=M,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,r,i,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(r.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=P[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(P,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:P[e].label,isDirectAction:P[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,P={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,r,i,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,r.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l,d,m,f){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function h(e){return t(e,c.serverDateFormat).toDate()}function v(e){return t(e).format(c.serverDateFormat)}function b(e){var t;return r.resolve().then(function(){J(e),"from"===e&&Q(),N("hours")&&(y(e),"from"!==e||pe.uiOptions.multipleDays||y("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return P(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return r.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return G()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(N("hours"))return H(e).then(function(){ne(e,!0)})}).then(function(){if(se(),!t)return V();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(I)}function g(){return se(),V()}function _(){return pe.uiOptions.toDate=null,J("to"),r.resolve().then(function(){if(N("hours")&&pe.uiOptions.fromDate)return y("from"),!pe.uiOptions.multipleDays&&y("to"),H("from").then(function(){ne("from",!0)}).then(se)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&V)}function y(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&s&&o&&(s=A(s).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=A(o).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function C(t,n){return t?(t=v(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):D(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):r.reject([])}function P(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function D(e,n){return e=t(e),r.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function R(){return pe.request?pe.request.request_type:pe.leaveType||null}function A(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(K).catch(I)}function w(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function I(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function k(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?V():T()}function L(){var e=pe.request.attributes();return pe.uiOptions.fromDate=h(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=h(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function S(e){s.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){N("days")||+e==+t||(re(),pe.performBalanceChangeCalculation())})}function M(){fe.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){ue()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",V))}function O(){pe.isMode("edit")&&(pe.isLeaveStatus(c.statusNames.approved)||pe.isLeaveStatus(c.statusNames.adminApproved))&&(me={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function $(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(w(a.min,n)<=0||w(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function x(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return r.all(e.map(H)).then(function(){["from","to"].forEach(function(e){$(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(re)}function E(){["from","to"].forEach(function(e){S(e),B(e)})}function B(e){s.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){N("days")||t===n||(se(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function N(e){return pe.selectedAbsenceType.calculation_unit_name===e}function j(e){return pe.request.request_type===e}function F(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return C(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function W(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function H(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(v(t)).then(function(t){he[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return he[e]={},I(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):r.resolve()}function G(){return u.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function Y(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function V(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(K).catch(I).finally(function(){pe.loading.balanceChange=!1})):r.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function X(){return v(pe.request.from_date)===v(pe.request.to_date)}function Q(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,J("to"))}function J(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,se(),re(),ie()}function K(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=h(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=h(pe.period.end_date)}function ee(){return!pe.isMode("create")&&X()||pe.isMode("create")&&(j("sickness")||N("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,r.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,i=he[a].number_of_hours?w(s,r).toString():"0";o.maxAmount=i,t&&(o.amount=o.maxAmount)}function ae(){me&&me.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=me.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function oe(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function se(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?v(e.fromDate):null,pe.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),N("hours")&&!j("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function re(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ce(){e.forEach(fe,function(e){e()})}function ue(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return oe(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),r.resolve().then(e&&ee).then(function(){if(e&&N("hours"))return H("from").then(function(){ne("from",!0)})}).then(e&&se).then(V)}function le(e){return pe.absenceTypes=e,oe(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,J("to")),ae(),V()}function de(e){var t=A(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(A(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(A(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var me=null,fe=[],pe=this,he={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=c.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:Y},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=h,pe.convertDateToServerFormat=v,pe.dateChangeHandler=b,pe.dateTypeChangeHandler=g,pe.daysSelectionModeChangeHandler=_,pe.isLeaveType=j,pe.isNotWorkingDay=F,pe.performBalanceChangeCalculation=V,pe.$onDestroy=ce,function(){n("RequestModalDetails"+e.capitalize(R(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",pe),M(),pe.initChildController().then(function(){return r.all([G(),W()])}).then(!pe.isMode("create")&&L).then(ee).then(function(){if(!pe.isMode("create")&&N("hours"))return x().then(se)}).then(!pe.isMode("create")&&Z).then(O).then(ae).then(k).then(function(){pe.isMode("view")||j("toil")||E()}).catch(I).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l){function d(){return k.fileUploader&&k.fileUploader.queue.length>0}function m(){return k.getFilesAmount()0?T.map(function(e){return e.label}).join(", "):""}function q(){return k.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(T.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){I[e.label]=t})})).catch(function(){I=null})}function P(){return c.valuesOf("safe_file_extension").then(function(e){T=e})}function D(e){return!e.attachment_id||k.canManage}function R(){e.forEach(w,function(e){e()})}function A(e,t){k.fileUploader.queue&&k.fileUploader.queue.length>0?k.fileUploader.uploadAll({entityID:k.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var T=[],w=[],I={},k=Object.create(this);return k.filesLoaded=!1,k.fileUploader=null,k.today=Date.now(),k.userDateFormatWithTime=r.DATE_FORMAT+" HH:mm",k.userDateFormat=r.DATE_FORMAT,k.$onDestroy=R,k.canRemoveAttachment=D,k.canSubmit=d,k.canUploadMore=m,k.formatDateTime=f,k.getAuthorName=p,k.getFilesAmount=h,k.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",k),g(),a.all([P(),q()]).then(_).finally(function(){k.filesLoaded=!0})}(),k}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,o){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],s.openLeavePopup=a,function(){o=n.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",selectedContactId:"<",isSelfRecord:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,o,s,r,i,c,u,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):W.refresh()}function b(t){t.dataIndex=e.indexBy(t.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return r.all().then(r.loadCalculationUnits).then(function(t){W.absenceTypes=t,W.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return T("approved",{status_id:F(m.statusNames.approved)})}function C(){return n.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function P(){return i.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(t){var n=e.find(W.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function D(){return i.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return O(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function R(){return n.all([i.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),A({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:O(e[0]),expiredTOILS:$(e[1].list)})}).then(function(t){W.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function A(t){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function T(e,t){return A(t).then(function(t){W.sections[e].data=t.list})}function w(){return n.all(Object.values(W.sections).filter(function(e){return e.open}).map(S))}function I(){return T("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function k(){return T("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function L(){ +})}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,r,i,c){function u(e){_([e]),N(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return U[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){S(e),N(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=R(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){F.push(o.$on("LeaveCalendar::showMonths",x)),F.push(i.subscribe("LeaveRequest::new",u)),F.push(i.subscribe("LeaveRequest::edit",B)),F.push(i.subscribe("LeaveRequest::updatedByManager",B)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function P(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function D(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function R(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function A(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function T(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function w(){return[T(c.statusNames.approved),T(c.statusNames.adminApproved),T(c.statusNames.awaitingApproval),T(c.statusNames.moreInformationRequired)]}function I(){return H.month.loading=!0,a.all([L(),k()]).then(b).then($).then(function(){j=!0}).then(function(){H.month.loading=!1})}function k(){return r.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:w()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function L(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function S(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function M(){o.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function O(t,n,o){var s,r;return t.contactsData[n]=t.contactsData[n]||{},r=m(n),s=!0===o?a.resolve():a.all([r.isWeekend(p(t.date)),r.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:P(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?D(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function $(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return O(e,t.id)}))}))}function x(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!j)&&I())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=A(e);t&&(h(t),-1!==w().indexOf(e.status_id)&&u(e))}function N(e){return a.all(R(e).map(function(t){return O(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var j=!1,F=[],U={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=M,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,r,i,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(r.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=P[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(P,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:P[e].label,isDirectAction:P[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,P={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,r,i,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,r.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l,d,m,f){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function h(e){return t(e,c.serverDateFormat).toDate()}function v(e){return t(e).format(c.serverDateFormat)}function b(e){var t;return r.resolve().then(function(){J(e),"from"===e&&Q(),N("hours")&&(y(e),"from"!==e||pe.uiOptions.multipleDays||y("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return P(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return r.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return G()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(N("hours"))return H(e).then(function(){ne(e,!0)})}).then(function(){if(se(),!t)return V();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(I)}function g(){return se(),V()}function _(){return pe.uiOptions.toDate=null,J("to"),r.resolve().then(function(){if(N("hours")&&pe.uiOptions.fromDate)return y("from"),!pe.uiOptions.multipleDays&&y("to"),H("from").then(function(){ne("from",!0)}).then(se)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&V)}function y(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&s&&o&&(s=A(s).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=A(o).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function C(t,n){return t?(t=v(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):D(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):r.reject([])}function P(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function D(e,n){return e=t(e),r.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function R(){return pe.request?pe.request.request_type:pe.leaveType||null}function A(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(K).catch(I)}function w(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function I(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function k(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?V():T()}function L(){var e=pe.request.attributes();return pe.uiOptions.fromDate=h(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=h(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function S(e){s.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){N("days")||+e==+t||(re(),pe.performBalanceChangeCalculation())})}function M(){fe.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){ue()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",V))}function O(){pe.isMode("edit")&&(pe.isLeaveStatus(c.statusNames.approved)||pe.isLeaveStatus(c.statusNames.adminApproved))&&(me={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function $(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(w(a.min,n)<=0||w(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function x(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return r.all(e.map(H)).then(function(){["from","to"].forEach(function(e){$(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(re)}function E(){["from","to"].forEach(function(e){S(e),B(e)})}function B(e){s.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){N("days")||t===n||(se(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function N(e){return pe.selectedAbsenceType.calculation_unit_name===e}function j(e){return pe.request.request_type===e}function F(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return C(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function W(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function H(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(v(t)).then(function(t){he[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return he[e]={},I(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):r.resolve()}function G(){return u.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function Y(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function V(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(K).catch(I).finally(function(){pe.loading.balanceChange=!1})):r.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function X(){return v(pe.request.from_date)===v(pe.request.to_date)}function Q(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,J("to"))}function J(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,se(),re(),ie()}function K(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=h(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=h(pe.period.end_date)}function ee(){return!pe.isMode("create")&&X()||pe.isMode("create")&&(j("sickness")||N("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,r.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,i=he[a].number_of_hours?w(s,r).toString():"0";o.maxAmount=i,t&&(o.amount=o.maxAmount)}function ae(){me&&me.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=me.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function oe(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function se(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?v(e.fromDate):null,pe.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),N("hours")&&!j("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function re(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ce(){e.forEach(fe,function(e){e()})}function ue(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return oe(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),r.resolve().then(e&&ee).then(function(){if(e&&N("hours"))return H("from").then(function(){ne("from",!0)})}).then(e&&se).then(V)}function le(e){return pe.absenceTypes=e,oe(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,J("to")),ae(),V()}function de(e){var t=A(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(A(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(A(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var me=null,fe=[],pe=this,he={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=c.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:Y},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=h,pe.convertDateToServerFormat=v,pe.dateChangeHandler=b,pe.dateTypeChangeHandler=g,pe.daysSelectionModeChangeHandler=_,pe.isLeaveType=j,pe.isNotWorkingDay=F,pe.performBalanceChangeCalculation=V,pe.$onDestroy=ce,function(){n("RequestModalDetails"+e.capitalize(R(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",pe),M(),pe.initChildController().then(function(){return r.all([G(),W()])}).then(!pe.isMode("create")&&L).then(ee).then(function(){if(!pe.isMode("create")&&N("hours"))return x().then(se)}).then(!pe.isMode("create")&&Z).then(O).then(ae).then(k).then(function(){pe.isMode("view")||j("toil")||E()}).catch(I).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l){function d(){return k.fileUploader&&k.fileUploader.queue.length>0}function m(){return k.getFilesAmount()0?T.map(function(e){return e.label}).join(", "):""}function q(){return k.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(T.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){I[e.label]=t})})).catch(function(){I=null})}function P(){return c.valuesOf("safe_file_extension").then(function(e){T=e})}function D(e){return!e.attachment_id||k.canManage}function R(){e.forEach(w,function(e){e()})}function A(e,t){k.fileUploader.queue&&k.fileUploader.queue.length>0?k.fileUploader.uploadAll({entityID:k.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var T=[],w=[],I={},k=Object.create(this);return k.filesLoaded=!1,k.fileUploader=null,k.today=Date.now(),k.userDateFormatWithTime=r.DATE_FORMAT+" HH:mm",k.userDateFormat=r.DATE_FORMAT,k.$onDestroy=R,k.canRemoveAttachment=D,k.canSubmit=d,k.canUploadMore=m,k.formatDateTime=f,k.getAuthorName=p,k.getFilesAmount=h,k.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",k),g(),a.all([P(),q()]).then(_).finally(function(){k.filesLoaded=!0})}(),k}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,o){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],s.openLeavePopup=a,function(){o=n.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,o,s,r,i,c,u,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):W.refresh()}function b(t){t.dataIndex=e.indexBy(t.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return r.all().then(r.loadCalculationUnits).then(function(t){W.absenceTypes=t,W.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return T("approved",{status_id:F(m.statusNames.approved)})}function C(){return n.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function P(){return i.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(t){var n=e.find(W.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function D(){return i.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return O(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function R(){return n.all([i.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),A({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:O(e[0]),expiredTOILS:$(e[1].list)})}).then(function(t){W.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function A(t){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function T(e,t){return A(t).then(function(t){W.sections[e].data=t.list})}function w(){return n.all(Object.values(W.sections).filter(function(e){return e.open}).map(S))}function I(){return T("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function k(){return T("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function L(){ return T("holidays",{public_holiday:!0})}function S(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function M(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){W.leaveRequestStatuses=e.indexBy(t,"value")})}function O(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(W.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function $(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function x(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(W.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],B(t,a))})}function B(e,t){var n=W.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function N(){W.loading.content=!0,n.all([P(),C()]).then(function(){W.loading.content=!1}).then(function(){return n.all([w(),h()])})}function j(e){var t=W.sections[e];t.open=!t.open,t.open&&!t.data.length&&S(t)}function F(t){return e.find(W.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:D},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:L},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:k},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:I}},W.labelPeriod=g,W.refresh=N,W.toggleSection=j,function(){n.all([M(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return n.all([P(),C()])}).then(function(){W.loading.content=!1}),x()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["leave-absences/shared/modules/controllers"],function(e){function t(e,t,n,a){function o(){return a.request.calculateBalanceChange(a.selectedAbsenceType.calculation_unit_name)}function s(){var e=a.request,t=!!e.from_date&&!!e.to_date,n=a.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function r(){return a.canCalculateChange()}function i(){return n.resolve()}t.debug("RequestModalDetailsLeaveController"),a.calculateBalanceChange=o,a.canCalculateChange=s,a.canSubmit=r,a.initChildController=i}e.controller("RequestModalDetailsLeaveController",t),t.$inject=["$controller","$log","$q","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function r(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function i(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=r,s.initChildController=i,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s,r){function i(){return r.balance.change.amount=+r.request.toil_to_accrue,n.resolve(r.balance.change)}function c(){return f().catch(function(e){return e.length&&(r.errors=e),n.reject(e)}).then(function(e){return s.calculateToilExpiryDate(r.request.type_id,e)}).then(function(e){return r.request.toil_expiry_date=e,r.uiOptions.expiryDate=new Date(e),e})}function u(){return!!r.request.toil_to_accrue}function l(){var e=r.uiOptions.multipleDays&&!!r.request.to_date,t=!r.uiOptions.multipleDays&&!!r.request.from_date,n=t||e,a=D.from_date!==r.request.from_date||D.to_date!==r.request.to_date;return r.canDisplayToilExpirationField&&n&&R.hasExpirationFromAdminSettings&&a}function d(){return!!(r.request.from_date&&r.request.to_date&&r.request.toil_duration&&r.request.toil_to_accrue)}function m(){r.request.toil_expiry_date=!1,r.uiOptions.expiryDate=null}function f(){var e=r.uiOptions.multipleDays,t=r.request;return p({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function p(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return n.reject([t])}return e.value?n.resolve(e.value):n.reject([])}function h(){var e=r.isMode("create")&&R.hasExpirationFromAdminSettings,t=R.hasPreviousExpirationDate,n=r.isLeaveType("toil"),a=r.canManage;r.canDisplayToilExpirationField=n&&(a||e||t)}function v(){return R.hasPreviousExpirationDate=r.isMode("edit")&&!!r.request.toil_expiry_date,s.canExpire(r.request.type_id).then(function(e){R.hasExpirationFromAdminSettings=e})}function b(){return r.request.to_date_type=r.request.from_date_type="1",v().then(h).then(g).then(y)}function g(){r.canManage&&(r.uiOptions.expiryDate=r.convertDateFormatFromServer(r.request.toil_expiry_date))}function _(){r.isMode("view")||a.$watch(function(){return r.request.toil_to_accrue},function(e,t){+e!=+t&&r.performBalanceChangeCalculation()})}function y(){return o.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){r.toilAmounts=e.indexBy(t,"value")})}function q(){D=angular.copy(r.request.attributes())}function C(){return l()?c().catch(n.resolve):n.resolve()}function P(){r.uiOptions.expiryDate&&(r.request.toil_expiry_date=r.convertDateToServerFormat(r.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var D,R={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};r.canDisplayToilExpirationField=!1,r.calculateBalanceChange=i,r.canCalculateChange=u,r.canSubmit=d,r.clearExpiryDate=m,r.initChildController=b,r.onDateChangeExtended=C,r.setDaysSelectionModeExtended=C,r.updateExpiryDate=P,function(){_(),q()}()}t.controller("RequestModalDetailsToilController",n),n.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),r={date:o};return a.all(r).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={toilDurationHours:"0",toilDurationMinutes:"0",request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},transformAttributes:function(e){var t=Number(e.toil_duration);return t&&(e.toilDurationHours=Math.floor(t/60).toString(),e.toilDurationMinutes=(t%60).toString()),e},updateDuration:function(){this.toil_duration=60*Number(this.toilDurationHours)+Number(this.toilDurationMinutes)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files","toilDurationHours","toilDurationMinutes"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,r,i,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,P){function D(e){"days"===$e.selectedAbsenceType.calculation_unit_name?delete $e.request[e+"_date_amount"]:delete $e.request[e+"_date_type"]}function R(){["from","to"].forEach(D)}function A(){var e=$e.requestStatuses[y.statusNames.awaitingApproval].value;Ie.status_id===e&&e!==$e.request.status_id&&d.publish("ManagerBadge:: Update Count")}function T(){return Oe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return Oe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return!$e.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function k(){var e=T();return $e.isMode("edit")&&(e=e&&(G()||w())),$e.canManage&&$e.requestStatuses&&(e=e&&!!$e.getStatusFromValue($e.newStatusOnSave)),(e=e&&!!$e.period.id)&&!$e.isMode("view")}function L(){$e.isSelfRecord?$e.request.status_id=$e.requestStatuses[y.statusNames.awaitingApproval].value:$e.canManage&&($e.request.status_id=$e.newStatusOnSave||$e.request.status_id)}function S(){if($e.isMode("edit")&&!$e.isRole("staff")&&"toil"!==F())return $e.request.calculateBalanceChange($e.selectedAbsenceType.calculation_unit_name).then(function(e){if(+$e.balance.change.amount!=+e.amount)return P.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function M(){$e.errors=[]}function O(){return $e.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function $(){ee()&&!$e.isRole("staff")&&($e.request.change_balance=!0)}function x(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return $e.request.delete().then(function(){$e.dismissModal(),d.publish("LeaveRequest::delete",$e.request)})}})}function E(){i.dismiss({$value:"cancel"})}function B(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function N(){return j($e.getStatusFromValue($e.request.status_id).name)}function j(e){return n.map(Te[e],function(e){return $e.requestStatuses[e]})}function F(){return $e.request?$e.request.request_type:$e.leaveType||null}function U(){return!$e.request||e.equals({},$e.requestStatuses)?[]:$e.request.status_id?N():j("none")}function W(e){return n.find($e.requestStatuses,function(t){return t.value===e})}function H(e){$e.errors=n.isArray(e)?e:[e],$e.loading.absenceTypes=!1,$e.submitting=!1}function G(){return!e.equals(Ie,$e.request.attributes())||$e.canManage&&$e.newStatusOnSave}function Y(){return $e.postContactSelection=!0,$e.staffMemberSelectionComplete=!1,$e.request.contact_id?o.resolve().then(ie).then(ce).then(he).then(be).then(Z).then(z).then($e.isMode("edit")?ge:n.noop).then(function(){$e.postContactSelection=!1,$e.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Se)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Te.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Te.awaiting_approval=e,Te.more_information_required=e,Te.rejected=e,Te.approved=e,Te.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return $e.canManage?f.find($e.request.contact_id).then(function(e){$e.contactName=e.display_name}):o.resolve()}function X(){ke.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",$e.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){we++})),r.$on("$destroy",Pe),r.$on("LeaveRequestPopup::addTab",function(e,t){Oe.push(t)})}function Q(){var e,t;$e.request=$e.leaveRequest||null,e=F(),t=$e.initRequestAttributes(),"leave"===e?$e.request=_.init(t):"sickness"===e?$e.request=q.init(t):"toil"===e&&($e.request=C.init(t))}function J(){var e={};return $e.request?e=$e.request.attributes():$e.canManage||(e={contact_id:Le}),e}function K(){if(Me="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(Me="admin")}).then(function(){return"staff"===Me&&c(y.permissions.ssp.manage).then(function(e){e&&(Me="manager")})}).finally(function(){$e.canManage=$e.isRole("manager")||$e.isRole("admin")})}function Z(){($e.isRole("admin")||$e.isMode("create")&&$e.isRole("manager"))&&($e.newStatusOnSave=$e.requestStatuses[y.statusNames.approved].value)}function ee(){return!$e.request.status_id||!n.includes(["cancelled","rejected"],W($e.request.status_id).name)}function te(e){var t=$e.getStatusFromValue($e.request.status_id);return!!t&&t.name===e}function ne(e){return $e.request&&$e.request.request_type===e}function ae(e){return $e.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return Me===e}function re(){return h.all().then(function(e){$e.absencePeriods=e})}function ie(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Ae={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return $e.loading.entitlements=!0,b.all({contact_id:$e.request.contact_id,period_id:$e.period.id,type_id:{IN:Ae.ids}},!0).finally(function(){$e.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Le=e.contactId})}function le(){return $e.selectedContactId?f.find($e.selectedContactId).then(function(e){$e.managedContacts=[e]}):$e.isRole("admin")?f.all().then(function(e){$e.managedContacts=n.remove(e.list,function(e){return e.id!==Le})}):f.find(Le).then(function(e){return e.leaveManagees()}).then(function(e){$e.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){$e.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){A(),d.publish(e,$e.request),$e.errors=[],$e.dismissModal()}function pe(){["from","to"].forEach(function(e){$e.request[e+"_date"]=Ie[e+"_date"]})}function he(e){if($e.absenceTypes=me(Ae.types,e),!$e.absenceTypes.length)return o.reject(Se)}function ve(){$e.period=n.find($e.absencePeriods,function(e){return $e.isMode("create")?e.current:oe($e.request,e)})}function be(){$e.isMode("create")?($e.selectedAbsenceType=$e.absenceTypes[0],$e.request.type_id=$e.selectedAbsenceType.id):$e.selectedAbsenceType=n.find($e.absenceTypes,function(e){return e.id===$e.request.type_id})}function ge(){Ie=e.copy($e.request.attributes())}function _e(){var e;$e.request.id?(e=[$e.requestStatuses[y.statusNames.approved].value,$e.requestStatuses[y.statusNames.adminApproved].value,$e.requestStatuses[y.statusNames.rejected].value,$e.requestStatuses[y.statusNames.cancelled].value],$e.mode="edit",$e.isRole("staff")&&e.indexOf($e.request.status_id)>-1&&($e.mode="view")):$e.mode="create"}function ye(){var e=$e.request.status_id;if(!$e.isMode("view")&&!$e.submitting)return $e.submitting=!0,L(),R(),$e.request.isValid().then(ee()&&S).then($).then(!$e.request.change_balance&&pe).then(qe).then(function(){return $e.isMode("edit")?Re():O()}).catch(function(t){$e.request.status_id=e,t&&H(t)}).finally(function(){$e.submitting=!1})}function qe(){return o.all(Oe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===we&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return we>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Pe(){ke.forEach(function(e){e()})}function De(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Re(){return $e.request.update().then(Ce).then(function(){$e.isRole("manager")?fe("LeaveRequest::updatedByManager"):($e.isRole("staff")||$e.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Ae,Te={},we=0,Ie={},ke=[],Le="",Se="No entitlement",Me="",Oe=[],$e=n.assign(this,m);$e.absencePeriods=[],$e.absenceTypes=[],$e.canManage=!1,$e.contactName=null,$e.errors=[],$e.loading={absenceTypes:!0,entitlements:!0},$e.managedContacts=[],$e.mode="",$e.newStatusOnSave=null,$e.period={},$e.postContactSelection=!1,$e.requestStatuses={},$e.selectedAbsenceType={},$e.staffMemberSelectionComplete=!1,$e.submitting=!1,$e.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},$e.canChangeAbsenceType=I,$e.canSubmit=k,$e.closeAlert=M,$e.deleteLeaveRequest=x,$e.dismissModal=E,$e.getStatuses=U,$e.getStatusFromValue=W,$e.initAfterContactSelection=Y,$e.initRequestAttributes=J,$e.isLeaveStatus=te,$e.isLeaveType=ne,$e.isMode=ae,$e.isRole=se,$e.submit=ye,$e.updateAbsenceType=De,function(){$e.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),re(),de()]).then(Q).then(_e).then(ve).then(function(){return $e.canManage&&!$e.isMode("edit")&&le()}).then(function(){if($e.selectedContactId&&($e.request.contact_id=$e.selectedContactId),$e.request.contact_id)return $e.initAfterContactSelection()}).catch(H).finally(function(){$e.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,r,i,c){function u(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,r,i){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:r,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,r){function i(e){l.errorMessage=e}function c(){return r.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrjc_revision_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,r.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(i).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrjc_revision_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(),g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){i.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){r.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,r){function i(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,r){n=o.entitlements.slice(0,r),a=e.entitlements.slice(r+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,r;return s=e.indexBy(n,"entitlement_id.type_id"),r=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:r}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t] ;e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,r){o.comment&&(t=s.concat(o).concat(r),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(i).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,r,i,c,u,l,d){function m(){P.absencePeriods=t.chain(P.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){P.absenceTypes=t.filter(P.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:P.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:P.contactId,returnUrl:n})}function h(){return c.all().then(function(e){P.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:P.contactId}).then(function(e){q=e})}function g(e){r.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=P.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){P.absencePeriods=t.map(P.absencePeriods,function(e){var n=t.map(P.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

Last updated:
By: "+e.author_name+"
Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],P=this;P.absencePeriods=[],P.loading={absencePeriods:!0},P.getEditEntitlementsPageURL=p,P.openAnnualEntitlementChangeLog=g,P.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){P.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,r,i){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return r.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){i.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js index a8a385f1b4e..29a2bf30872 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js @@ -8,7 +8,7 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){A.$current.navigable==t&&c(e,n)||A.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=A.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=M[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(A.$current=t,A.current=t.self,A.params=n,V(A.params,m),A.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),A.current)}).then(null,function(a){return a===D?S:A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(A.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},A.is=function(e,t,a){a=W({relative:A.$current},a||{});var r=f(e,a.relative);return j(r)?A.$current===r&&(!t||c(r.params.$$values(t),m)):n},A.includes=function(e,t,a){if(a=W({relative:A.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=A.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(A.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function I(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function O(e,t){return{relative:S(e)||t.$current,inherit:!0}}function L(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=W(O(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=I(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function M(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=I(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function k(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function x(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function E(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;aWhen All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

","

People I approve filter displays only staff members who you approve leave for.

","

People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

"].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(M.selectedPeriod.start_date).clone().startOf("month"),a=n(M.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");M.months=e}function p(){s.$new().$watch(function(){return M.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){M.injectMonths=!0,I("injected").then(function(){R(e)}).then(function(){M.loading.calendar=!1})}function v(){O=a("LeaveCalendar"+t.capitalize(L)+"Controller").init(M)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){M.absencePeriods=t.sortBy(e,"start_date"),M.selectedPeriod=t.find(M.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return O.loadContacts().then(function(e){M.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){M.filters.optionValues.regions=e.hrjc_region,M.filters.optionValues.locations=e.hrjc_location,M.filters.optionValues.levelTypes=e.hrjc_level_type,M.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function w(){return r.all([y(),C(),_()]).then(function(e){M.supportData.absenceTypes=e[0],M.supportData.publicHolidays=e[1],M.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,M.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,M.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,M.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return M.injectMonths&&(e=I("destroyed"),M.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){M.loading.calendar=!0}).then(A).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=M.selectedMonths.length?M.months.filter(function(e){return t.includes(M.selectedMonths,e.index)}):M.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){M.selectedMonths=[n().month()]}function T(){return M.roleOverride?r.resolve().then(function(){L=M.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){L=e[0]?"admin":e[1]?"manager":"staff"})}function I(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===M.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var O,L,M=this;M.absencePeriods=[],M.contacts=[],M.contactIdsToReduceTo=null,M.injectMonths=!1,M.months=[],M.selectedMonths=null,M.selectedPeriod=null,M.showContactName=!1,M.showFilters=!1,M.supportData={},M.loading={calendar:!0,page:!0},M.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},M.labelPeriod=g,M.refresh=D,function(){T().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),w()])}).then(function(){return M.showFilters?$():t.noop}).then(function(){h()}).then(function(){M.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){O(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",x)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function w(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([I(),T()]).then(g).then(k).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function I(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function O(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function L(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function M(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?w(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function k(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return M(e,t.id)}))}))}function x(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function E(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(A(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=L,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}), -define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f,m){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function h(e){return t(e,u.serverDateFormat).toDate()}function v(e){return t(e).format(u.serverDateFormat)}function g(e){var t;return s.resolve().then(function(){X(e),"from"===e&&K(),B("hours")&&(_(e),"from"!==e||pe.uiOptions.multipleDays||_("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return C(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return s.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return V()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(B("hours"))return W(e).then(function(){ne(e,!0)})}).then(function(){if(oe(),!t)return Y();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(S)}function b(){return oe(),Y()}function y(){return pe.uiOptions.toDate=null,X("to"),s.resolve().then(function(){if(B("hours")&&pe.uiOptions.fromDate)return _("from"),!pe.uiOptions.multipleDays&&_("to"),W("from").then(function(){ne("from",!0)}).then(oe)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&Y)}function _(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&o&&r&&(o=P(o).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=P(r).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function $(t,n){return t?(t=v(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):w(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):s.reject([])}function C(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function w(e,n){return e=t(e),s.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function A(){return pe.request?pe.request.request_type:pe.leaveType||null}function P(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(Q).catch(S)}function R(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function S(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function T(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?Y():D()}function I(){var e=pe.request.attributes();return pe.uiOptions.fromDate=h(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=h(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function O(e){o.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){B("days")||+e==+t||(se(),pe.performBalanceChangeCalculation())})}function L(){me.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){ce()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",Y))}function M(){pe.isMode("edit")&&(pe.isLeaveStatus(u.statusNames.approved)||pe.isLeaveStatus(u.statusNames.adminApproved))&&(fe={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function k(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(R(a.min,n)<=0||R(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function x(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return s.all(e.map(W)).then(function(){["from","to"].forEach(function(e){k(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(se)}function E(){["from","to"].forEach(function(e){O(e),j(e)})}function j(e){o.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){B("days")||t===n||(oe(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function B(e){return pe.selectedAbsenceType.calculation_unit_name===e}function N(e){return pe.request.request_type===e}function F(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return $(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function H(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function W(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(v(t)).then(function(t){he[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return he[e]={},S(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):s.resolve()}function V(){return c.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function G(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function Y(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(Q).catch(S).finally(function(){pe.loading.balanceChange=!1})):s.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function J(){return v(pe.request.from_date)===v(pe.request.to_date)}function K(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,X("to"))}function X(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,oe(),se(),ie()}function Q(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=h(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=h(pe.period.end_date)}function ee(){return!pe.isMode("create")&&J()||pe.isMode("create")&&(N("sickness")||B("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,s.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,s=n.multipleDays&&"from"===a?r.max:n.times.to.time,i=he[a].number_of_hours?R(o,s).toString():"0";r.maxAmount=i,t&&(r.amount=r.maxAmount)}function ae(){fe&&fe.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=fe.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function re(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function oe(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?v(e.fromDate):null,pe.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),B("hours")&&!N("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function se(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ue(){e.forEach(me,function(e){e()})}function ce(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return re(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),s.resolve().then(e&&ee).then(function(){if(e&&B("hours"))return W("from").then(function(){ne("from",!0)})}).then(e&&oe).then(Y)}function le(e){return pe.absenceTypes=e,re(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,X("to")),ae(),Y()}function de(e){var t=P(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(P(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(P(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var fe=null,me=[],pe=this,he={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=u.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:G},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=h,pe.convertDateToServerFormat=v,pe.dateChangeHandler=g,pe.dateTypeChangeHandler=b,pe.daysSelectionModeChangeHandler=y,pe.isLeaveType=N,pe.isNotWorkingDay=F,pe.performBalanceChangeCalculation=Y,pe.$onDestroy=ue,function(){n("RequestModalDetails"+e.capitalize(A(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",pe),L(),pe.initChildController().then(function(){return s.all([V(),H()])}).then(!pe.isMode("create")&&I).then(ee).then(function(){if(!pe.isMode("create")&&B("hours"))return x().then(oe)}).then(!pe.isMode("create")&&Z).then(M).then(ae).then(T).then(function(){pe.isMode("view")||N("toil")||E()}).catch(S).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function w(e){return!e.attachment_id||T.canManage}function A(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=A,T.canRemoveAttachment=w,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=h,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",selectedContactId:"<",isSelfRecord:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function w(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function A(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:M(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:x(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function I(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function O(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function L(e,t,n,a){d.openModal.apply(d,arguments)}function M(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function k(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function x(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=k(n)),n.length)return{IN:n}}function E(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,A(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=h,U.getAbsenceTypeByID=v,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=L,U.refresh=E,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),w(),I(),P(),S(),R(),O()]).then(function(){U.loading.page=!1,A()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["leave-absences/shared/modules/controllers"],function(e){function t(e,t,n,a){function r(){return a.request.calculateBalanceChange(a.selectedAbsenceType.calculation_unit_name)}function o(){var e=a.request,t=!!e.from_date&&!!e.to_date,n=a.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function s(){return a.canCalculateChange()}function i(){return n.resolve()}t.debug("RequestModalDetailsLeaveController"),a.calculateBalanceChange=r,a.canCalculateChange=o,a.canSubmit=s,a.initChildController=i}e.controller("RequestModalDetailsLeaveController",t),t.$inject=["$controller","$log","$q","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s){function i(){return s.balance.change.amount=+s.request.toil_to_accrue,n.resolve(s.balance.change)}function u(){return m().catch(function(e){return e.length&&(s.errors=e),n.reject(e)}).then(function(e){return o.calculateToilExpiryDate(s.request.type_id,e)}).then(function(e){return s.request.toil_expiry_date=e,s.uiOptions.expiryDate=new Date(e),e})}function c(){return!!s.request.toil_to_accrue}function l(){var e=s.uiOptions.multipleDays&&!!s.request.to_date,t=!s.uiOptions.multipleDays&&!!s.request.from_date,n=t||e,a=w.from_date!==s.request.from_date||w.to_date!==s.request.to_date;return s.canDisplayToilExpirationField&&n&&A.hasExpirationFromAdminSettings&&a}function d(){return!!(s.request.from_date&&s.request.to_date&&s.request.toil_duration&&s.request.toil_to_accrue)}function f(){s.request.toil_expiry_date=!1,s.uiOptions.expiryDate=null}function m(){var e=s.uiOptions.multipleDays,t=s.request;return p({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function p(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return n.reject([t])}return e.value?n.resolve(e.value):n.reject([])}function h(){var e=s.isMode("create")&&A.hasExpirationFromAdminSettings,t=A.hasPreviousExpirationDate,n=s.isLeaveType("toil"),a=s.canManage;s.canDisplayToilExpirationField=n&&(a||e||t)}function v(){return A.hasPreviousExpirationDate=s.isMode("edit")&&!!s.request.toil_expiry_date,o.canExpire(s.request.type_id).then(function(e){A.hasExpirationFromAdminSettings=e})}function g(){return s.request.to_date_type=s.request.from_date_type="1",v().then(h).then(b).then(_)}function b(){s.canManage&&(s.uiOptions.expiryDate=s.convertDateFormatFromServer(s.request.toil_expiry_date))}function y(){s.isMode("view")||a.$watch(function(){return s.request.toil_to_accrue},function(e,t){+e!=+t&&s.performBalanceChangeCalculation()})}function _(){return r.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){s.toilAmounts=e.indexBy(t,"value")})}function q(){w=angular.copy(s.request.attributes())}function $(){return l()?u().catch(n.resolve):n.resolve()}function C(){s.uiOptions.expiryDate&&(s.request.toil_expiry_date=s.convertDateToServerFormat(s.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var w,A={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};s.canDisplayToilExpirationField=!1,s.calculateBalanceChange=i,s.canCalculateChange=c,s.canSubmit=d,s.clearExpiryDate=f,s.initChildController=g,s.onDateChangeExtended=$,s.setDaysSelectionModeExtended=$,s.updateExpiryDate=C,function(){y(),q()}()}t.controller("RequestModalDetailsToilController",n),n.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}), +define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f,m){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function h(e){return t(e,u.serverDateFormat).toDate()}function v(e){return t(e).format(u.serverDateFormat)}function g(e){var t;return s.resolve().then(function(){X(e),"from"===e&&K(),B("hours")&&(_(e),"from"!==e||pe.uiOptions.multipleDays||_("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return C(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return s.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return V()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(B("hours"))return W(e).then(function(){ne(e,!0)})}).then(function(){if(oe(),!t)return Y();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(S)}function b(){return oe(),Y()}function y(){return pe.uiOptions.toDate=null,X("to"),s.resolve().then(function(){if(B("hours")&&pe.uiOptions.fromDate)return _("from"),!pe.uiOptions.multipleDays&&_("to"),W("from").then(function(){ne("from",!0)}).then(oe)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&Y)}function _(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&o&&r&&(o=P(o).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=P(r).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function $(t,n){return t?(t=v(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):w(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):s.reject([])}function C(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function w(e,n){return e=t(e),s.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function A(){return pe.request?pe.request.request_type:pe.leaveType||null}function P(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(Q).catch(S)}function R(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function S(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function T(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?Y():D()}function I(){var e=pe.request.attributes();return pe.uiOptions.fromDate=h(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=h(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function O(e){o.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){B("days")||+e==+t||(se(),pe.performBalanceChangeCalculation())})}function L(){me.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){ce()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",Y))}function M(){pe.isMode("edit")&&(pe.isLeaveStatus(u.statusNames.approved)||pe.isLeaveStatus(u.statusNames.adminApproved))&&(fe={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function k(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(R(a.min,n)<=0||R(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function x(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return s.all(e.map(W)).then(function(){["from","to"].forEach(function(e){k(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(se)}function E(){["from","to"].forEach(function(e){O(e),j(e)})}function j(e){o.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){B("days")||t===n||(oe(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function B(e){return pe.selectedAbsenceType.calculation_unit_name===e}function N(e){return pe.request.request_type===e}function F(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return $(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function H(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function W(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(v(t)).then(function(t){he[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return he[e]={},S(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):s.resolve()}function V(){return c.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function G(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function Y(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(Q).catch(S).finally(function(){pe.loading.balanceChange=!1})):s.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function J(){return v(pe.request.from_date)===v(pe.request.to_date)}function K(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,X("to"))}function X(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,oe(),se(),ie()}function Q(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=h(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=h(pe.period.end_date)}function ee(){return!pe.isMode("create")&&J()||pe.isMode("create")&&(N("sickness")||B("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,s.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,s=n.multipleDays&&"from"===a?r.max:n.times.to.time,i=he[a].number_of_hours?R(o,s).toString():"0";r.maxAmount=i,t&&(r.amount=r.maxAmount)}function ae(){fe&&fe.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=fe.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function re(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function oe(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?v(e.fromDate):null,pe.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),B("hours")&&!N("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function se(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ue(){e.forEach(me,function(e){e()})}function ce(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return re(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),s.resolve().then(e&&ee).then(function(){if(e&&B("hours"))return W("from").then(function(){ne("from",!0)})}).then(e&&oe).then(Y)}function le(e){return pe.absenceTypes=e,re(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,X("to")),ae(),Y()}function de(e){var t=P(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(P(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(P(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var fe=null,me=[],pe=this,he={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=u.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:G},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=h,pe.convertDateToServerFormat=v,pe.dateChangeHandler=g,pe.dateTypeChangeHandler=b,pe.daysSelectionModeChangeHandler=y,pe.isLeaveType=N,pe.isNotWorkingDay=F,pe.performBalanceChangeCalculation=Y,pe.$onDestroy=ue,function(){n("RequestModalDetails"+e.capitalize(A(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",pe),L(),pe.initChildController().then(function(){return s.all([V(),H()])}).then(!pe.isMode("create")&&I).then(ee).then(function(){if(!pe.isMode("create")&&B("hours"))return x().then(oe)}).then(!pe.isMode("create")&&Z).then(M).then(ae).then(T).then(function(){pe.isMode("view")||N("toil")||E()}).catch(S).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function w(e){return!e.attachment_id||T.canManage}function A(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=A,T.canRemoveAttachment=w,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=h,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function w(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function A(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:M(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:x(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function I(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function O(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function L(e,t,n,a){d.openModal.apply(d,arguments)}function M(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function k(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function x(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=k(n)),n.length)return{IN:n}}function E(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,A(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=h,U.getAbsenceTypeByID=v,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=L,U.refresh=E,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),w(),I(),P(),S(),R(),O()]).then(function(){U.loading.page=!1,A()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["leave-absences/shared/modules/controllers"],function(e){function t(e,t,n,a){function r(){return a.request.calculateBalanceChange(a.selectedAbsenceType.calculation_unit_name)}function o(){var e=a.request,t=!!e.from_date&&!!e.to_date,n=a.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function s(){return a.canCalculateChange()}function i(){return n.resolve()}t.debug("RequestModalDetailsLeaveController"),a.calculateBalanceChange=r,a.canCalculateChange=o,a.canSubmit=s,a.initChildController=i}e.controller("RequestModalDetailsLeaveController",t),t.$inject=["$controller","$log","$q","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s){function i(){return s.balance.change.amount=+s.request.toil_to_accrue,n.resolve(s.balance.change)}function u(){return m().catch(function(e){return e.length&&(s.errors=e),n.reject(e)}).then(function(e){return o.calculateToilExpiryDate(s.request.type_id,e)}).then(function(e){return s.request.toil_expiry_date=e,s.uiOptions.expiryDate=new Date(e),e})}function c(){return!!s.request.toil_to_accrue}function l(){var e=s.uiOptions.multipleDays&&!!s.request.to_date,t=!s.uiOptions.multipleDays&&!!s.request.from_date,n=t||e,a=w.from_date!==s.request.from_date||w.to_date!==s.request.to_date;return s.canDisplayToilExpirationField&&n&&A.hasExpirationFromAdminSettings&&a}function d(){return!!(s.request.from_date&&s.request.to_date&&s.request.toil_duration&&s.request.toil_to_accrue)}function f(){s.request.toil_expiry_date=!1,s.uiOptions.expiryDate=null}function m(){var e=s.uiOptions.multipleDays,t=s.request;return p({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function p(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return n.reject([t])}return e.value?n.resolve(e.value):n.reject([])}function h(){var e=s.isMode("create")&&A.hasExpirationFromAdminSettings,t=A.hasPreviousExpirationDate,n=s.isLeaveType("toil"),a=s.canManage;s.canDisplayToilExpirationField=n&&(a||e||t)}function v(){return A.hasPreviousExpirationDate=s.isMode("edit")&&!!s.request.toil_expiry_date,o.canExpire(s.request.type_id).then(function(e){A.hasExpirationFromAdminSettings=e})}function g(){return s.request.to_date_type=s.request.from_date_type="1",v().then(h).then(b).then(_)}function b(){s.canManage&&(s.uiOptions.expiryDate=s.convertDateFormatFromServer(s.request.toil_expiry_date))}function y(){s.isMode("view")||a.$watch(function(){return s.request.toil_to_accrue},function(e,t){+e!=+t&&s.performBalanceChangeCalculation()})}function _(){return r.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){s.toilAmounts=e.indexBy(t,"value")})}function q(){w=angular.copy(s.request.attributes())}function $(){return l()?u().catch(n.resolve):n.resolve()}function C(){s.uiOptions.expiryDate&&(s.request.toil_expiry_date=s.convertDateToServerFormat(s.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var w,A={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};s.canDisplayToilExpirationField=!1,s.calculateBalanceChange=i,s.canCalculateChange=c,s.canSubmit=d,s.clearExpiryDate=f,s.initChildController=g,s.onDateChangeExtended=$,s.setDaysSelectionModeExtended=$,s.updateExpiryDate=C,function(){y(),q()}()}t.controller("RequestModalDetailsToilController",n),n.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}), define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,r,o){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(o.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={toilDurationHours:"0",toilDurationMinutes:"0",request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},transformAttributes:function(e){var t=Number(e.toil_duration);return t&&(e.toilDurationHours=Math.floor(t/60).toString(),e.toilDurationMinutes=(t%60).toString()),e},updateDuration:function(){this.toil_duration=60*Number(this.toilDurationHours)+Number(this.toilDurationMinutes)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files","toilDurationHours","toilDurationMinutes"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function w(e){"days"===ke.selectedAbsenceType.calculation_unit_name?delete ke.request[e+"_date_amount"]:delete ke.request[e+"_date_type"]}function A(){["from","to"].forEach(w)}function P(){var e=ke.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==ke.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!ke.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return ke.isMode("edit")&&(e=e&&(V()||R())),ke.canManage&&ke.requestStatuses&&(e=e&&!!ke.getStatusFromValue(ke.newStatusOnSave)),(e=e&&!!ke.period.id)&&!ke.isMode("view")}function I(){ke.isSelfRecord?ke.request.status_id=ke.requestStatuses[_.statusNames.awaitingApproval].value:ke.canManage&&(ke.request.status_id=ke.newStatusOnSave||ke.request.status_id)}function O(){if(ke.isMode("edit")&&!ke.isRole("staff")&&"toil"!==F())return ke.request.calculateBalanceChange(ke.selectedAbsenceType.calculation_unit_name).then(function(e){if(+ke.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function L(){ke.errors=[]}function M(){return ke.request.create().then($e).then(function(){me("LeaveRequest::new")})}function k(){ee()&&!ke.isRole("staff")&&(ke.request.change_balance=!0)}function x(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return ke.request.delete().then(function(){ke.dismissModal(),d.publish("LeaveRequest::delete",ke.request)})}})}function E(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(ke.getStatusFromValue(ke.request.status_id).name)}function N(e){return n.map(De[e],function(e){return ke.requestStatuses[e]})}function F(){return ke.request?ke.request.request_type:ke.leaveType||null}function U(){return!ke.request||e.equals({},ke.requestStatuses)?[]:ke.request.status_id?B():N("none")}function H(e){return n.find(ke.requestStatuses,function(t){return t.value===e})}function W(e){ke.errors=n.isArray(e)?e:[e],ke.loading.absenceTypes=!1,ke.submitting=!1}function V(){return!e.equals(Se,ke.request.attributes())||ke.canManage&&ke.newStatusOnSave}function G(){return ke.postContactSelection=!0,ke.staffMemberSelectionComplete=!1,ke.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(ke.isMode("edit")?be:n.noop).then(function(){ke.postContactSelection=!1,ke.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Oe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return ke.canManage?m.find(ke.request.contact_id).then(function(e){ke.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",ke.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function K(){var e,t;ke.request=ke.leaveRequest||null,e=F(),t=ke.initRequestAttributes(),"leave"===e?ke.request=y.init(t):"sickness"===e?ke.request=q.init(t):"toil"===e&&(ke.request=$.init(t))}function X(){var e={};return ke.request?e=ke.request.attributes():ke.canManage||(e={contact_id:Ie}),e}function Q(){if(Le="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Le="admin")}).then(function(){return"staff"===Le&&u(_.permissions.ssp.manage).then(function(e){e&&(Le="manager")})}).finally(function(){ke.canManage=ke.isRole("manager")||ke.isRole("admin")})}function Z(){(ke.isRole("admin")||ke.isMode("create")&&ke.isRole("manager"))&&(ke.newStatusOnSave=ke.requestStatuses[_.statusNames.approved].value)}function ee(){return!ke.request.status_id||!n.includes(["cancelled","rejected"],H(ke.request.status_id).name)}function te(e){var t=ke.getStatusFromValue(ke.request.status_id);return!!t&&t.name===e}function ne(e){return ke.request&&ke.request.request_type===e}function ae(e){return ke.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Le===e}function se(){return h.all().then(function(e){ke.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return ke.loading.entitlements=!0,g.all({contact_id:ke.request.contact_id,period_id:ke.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){ke.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Ie=e.contactId})}function le(){return ke.selectedContactId?m.find(ke.selectedContactId).then(function(e){ke.managedContacts=[e]}):ke.isRole("admin")?m.all().then(function(e){ke.managedContacts=n.remove(e.list,function(e){return e.id!==Ie})}):m.find(Ie).then(function(e){return e.leaveManagees()}).then(function(e){ke.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){ke.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,ke.request),ke.errors=[],ke.dismissModal()}function pe(){["from","to"].forEach(function(e){ke.request[e+"_date"]=Se[e+"_date"]})}function he(e){if(ke.absenceTypes=fe(Pe.types,e),!ke.absenceTypes.length)return r.reject(Oe)}function ve(){ke.period=n.find(ke.absencePeriods,function(e){return ke.isMode("create")?e.current:re(ke.request,e)})}function ge(){ke.isMode("create")?(ke.selectedAbsenceType=ke.absenceTypes[0],ke.request.type_id=ke.selectedAbsenceType.id):ke.selectedAbsenceType=n.find(ke.absenceTypes,function(e){return e.id===ke.request.type_id})}function be(){Se=e.copy(ke.request.attributes())}function ye(){var e;ke.request.id?(e=[ke.requestStatuses[_.statusNames.approved].value,ke.requestStatuses[_.statusNames.adminApproved].value,ke.requestStatuses[_.statusNames.rejected].value,ke.requestStatuses[_.statusNames.cancelled].value],ke.mode="edit",ke.isRole("staff")&&e.indexOf(ke.request.status_id)>-1&&(ke.mode="view")):ke.mode="create"}function _e(){var e=ke.request.status_id;if(!ke.isMode("view")&&!ke.submitting)return ke.submitting=!0,I(),A(),ke.request.isValid().then(ee()&&O).then(k).then(!ke.request.change_balance&&pe).then(qe).then(function(){return ke.isMode("edit")?Ae():M()}).catch(function(t){ke.request.status_id=e,t&&W(t)}).finally(function(){ke.submitting=!1})}function qe(){return r.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function we(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return ke.request.update().then($e).then(function(){ke.isRole("manager")?me("LeaveRequest::updatedByManager"):(ke.isRole("staff")||ke.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Ie="",Oe="No entitlement",Le="",Me=[],ke=n.assign(this,f);ke.absencePeriods=[],ke.absenceTypes=[],ke.canManage=!1,ke.contactName=null,ke.errors=[],ke.loading={absenceTypes:!0,entitlements:!0},ke.managedContacts=[],ke.mode="",ke.newStatusOnSave=null,ke.period={},ke.postContactSelection=!1,ke.requestStatuses={},ke.selectedAbsenceType={},ke.staffMemberSelectionComplete=!1,ke.submitting=!1,ke.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},ke.canChangeAbsenceType=S,ke.canSubmit=T,ke.closeAlert=L,ke.deleteLeaveRequest=x,ke.dismissModal=E,ke.getStatuses=U,ke.getStatusFromValue=H,ke.initAfterContactSelection=G,ke.initRequestAttributes=X,ke.isLeaveStatus=te,ke.isLeaveType=ne,ke.isMode=ae,ke.isRole=oe,ke.submit=_e,ke.updateAbsenceType=we,function(){ke.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return ke.canManage&&!ke.isMode("edit")&&le()}).then(function(){if(ke.selectedContactId&&(ke.request.contact_id=ke.selectedContactId),ke.request.contact_id)return ke.initAfterContactSelection()}).catch(W).finally(function(){ke.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(t){return t.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM),define("leave-absences/admin-dashboard/modules/config",["common/angular","leave-absences/admin-dashboard/modules/settings"],function(e){return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(e,t,n,a,r,o){var s={format:["DateFormat",function(e){return e.getDateFormat()}]};r.debugEnabled(o.debug),t.defaults.stripTrailingSlashes=!1,a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:s}).state("calendar",{url:"/calendar",template:'',resolve:s}).state("leave-balances",{url:"/leave-balances",template:"",resolve:s})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function t(e,t){e.debug("Component: admin-dashboard-container"),t.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",t]})}), define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/admin-dashboard":n+"/admin-dashboard"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js index cffb5875b44..dfee0b5854d 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js @@ -8,7 +8,7 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))h.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),h.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var v=s(u||{}),h=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+h.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,v)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,v)),m.$$inheritedValues=f(o.$$values,v),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,v)),o.then(i,u));for(var q=0,$=h.length;q<$;q+=3)a.hasOwnProperty(h[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(h[q],h[q+1],h[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(h.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(v[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return v[t]=new Y.Param(t,n,a,r),v[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},v=this.params=r?r.params.$$new():new Y.ParamSet,h=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=h}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:v,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,v=!0,h=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(v=e),v},this.defaultSquashPolicy=function(e){if(!j(e))return h;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return h=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!v.type.is(e))throw new Error("Default value ("+e+") for parameter '"+v.id+"' is not an instance of Type ("+v.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(v.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?v.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var v=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return h;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[D]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),h(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=M[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&h.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),h.update(!0),w.current)}).then(null,function(a){return a===R?S:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||h.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=R(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==v){d=n.$new(),v=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(h)}}var f,m,p,v,h=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=R(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function R(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function D(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function I(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function O(e,t){return{relative:S(e)||t.$current,inherit:!0}}function L(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=D(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=W(O(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=I(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function M(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=I(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function k(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return v.push(u),h[s]=r,function(){var e=v.indexOf(u);-1!==e&&v.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function x(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function E(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),h.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",h),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n){function a(e){e.absencePeriods&&c.absencePeriods.length&&(c.filters.period_id=o().id),e.absenceTypes&&c.absenceTypes.length&&(c.filters.type_id=s().id),(e.loggedInContactId||e.userRole)&&(c.filters.managed_by="manager"===c.userRole?c.loggedInContactId:void 0),r()&&c.submitFilters()}function r(){return e.every(c.filters,function(e){return null!==e})}function o(){return e.find(c.absencePeriods,function(e){return e.current})||c.absencePeriods.reduce(function(e,n){return t(e.end_date).isAfter(n.end_date)?e:n})}function s(){return c.absenceTypes.reduce(function(e,t){return e.title.localeCompare(t.title)?e:t})}function i(e){return e.current?"Current Period ("+e.title+")":e.title}function u(){n.$emit("LeaveBalanceFilters::update",c.filters)}var c=this;c.filters={period_id:null,type_id:null,managed_by:null},c.$onChanges=a,c.labelPeriod=i,c.submitFilters=u}n.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,t){return e.extend({all:function(e,n,a,r,o){return t.getLeaveBalances(this.processFilters(e),n,a,r,o)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){return r.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function p(){return o.all().then(o.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function v(){return s.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function h(){return n.all([m(),p(),v(),g(),q()]).catch(function(e){u.error("Error",e)})}function g(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function b(){return P.loading.report=!0,i.all(w,P.pagination,void 0,void 0,!1).then(function(e){P.report=y(e.list),P.reportCount=e.total}).catch(function(e){u.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function y(n){return n.map(function(n){return n=e.copy(n),n.absence_types=t.indexBy(n.absence_types,function(e){return e.id}),n})}function _(){a.$on("LeaveBalanceFilters::update",C),c.subscribe("LeaveRequest::new",$)}function q(){return f(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function $(e){C(e,w)}function C(e,t){w=t,P.pagination.page=1,A(),P.loadReportCurrentPage()}function A(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+w.type_id})}var w={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.loadReportCurrentPage=b,function(){_(),h().then(function(){P.loading.component=!1})}()}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(h.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(h.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=h.filters.userSettings.assignedTo.type;return f(e).then(function(e){h.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return h.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(m(),null,"display_name").then(function(e){return e.list})}function d(){return v?a.resolve(v):s.all()}function f(e){return"me"===e?r.leaveManagees(h.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function m(){return{department:h.filters.userSettings.department?h.filters.userSettings.department.value:null,level_type:h.filters.userSettings.level_type?h.filters.userSettings.level_type.value:null,location:h.filters.userSettings.location?h.filters.userSettings.location.value:null,region:h.filters.userSettings.region?h.filters.userSettings.region.value:null,id:{IN:h.filters.userSettings.contact?[h.filters.userSettings.contact.id]:h.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

","

People I approve filter displays only staff members who you approve leave for.

","

People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

"].join(""))}n.debug("LeaveCalendarAdminController");var v,h;return{init:function(e){return h=e,h.showContactDetailsLink=!0,h.showContactName=!0,h.showFilters=!0,h.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],h.filters.userSettings.assignedTo=h.filtersByAssignee[0],h.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(M.selectedPeriod.start_date).clone().startOf("month"),a=n(M.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");M.months=e}function p(){s.$new().$watch(function(){return M.selectedMonths},function(t,n){null===n||e.equals(t,n)||D()})}function v(e){M.injectMonths=!0,I("injected").then(function(){D(e)}).then(function(){M.loading.calendar=!1})}function h(){O=a("LeaveCalendar"+t.capitalize(L)+"Controller").init(M)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){M.absencePeriods=t.sortBy(e,"start_date"),M.selectedPeriod=t.find(M.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return O.loadContacts().then(function(e){M.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){M.filters.optionValues.regions=e.hrjc_region,M.filters.optionValues.locations=e.hrjc_location,M.filters.optionValues.levelTypes=e.hrjc_level_type,M.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){M.supportData.absenceTypes=e[0],M.supportData.publicHolidays=e[1],M.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,M.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,M.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,M.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return M.injectMonths&&(e=I("destroyed"),M.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function R(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){M.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){v("contacts"===e)})}function D(e){var n=M.selectedMonths.length?M.months.filter(function(e){return t.includes(M.selectedMonths,e.index)}):M.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){M.selectedMonths=[n().month()]}function T(){return M.roleOverride?r.resolve().then(function(){L=M.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){L=e[0]?"admin":e[1]?"manager":"staff"})}function I(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===M.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var O,L,M=this;M.absencePeriods=[],M.contacts=[],M.contactIdsToReduceTo=null,M.injectMonths=!1,M.months=[],M.selectedMonths=null,M.selectedPeriod=null,M.showContactName=!1,M.showFilters=!1,M.supportData={},M.loading={calendar:!0,page:!0},M.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},M.labelPeriod=g,M.refresh=R,function(){T().then(p).then(h).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return M.showFilters?$():t.noop}).then(function(){v()}).then(function(){M.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function v(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function h(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),v())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){h()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function v(e){O(e),B(e)}function h(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",x)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",v)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?v(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function R(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function D(){return[R(u.statusNames.approved),R(u.statusNames.adminApproved),R(u.statusNames.awaitingApproval),R(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([I(),T()]).then(g).then(k).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:D()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function I(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function O(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function L(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function M(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function k(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return M(e,t.id)}))}))}function x(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function E(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(v(t),-1!==D().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=L,W.contactsList=m,W.getContactUrl=h,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}), -define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(v(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):v(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function v(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function h(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=h,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function v(e){return q.mode===e}function h(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=v,q.onBeforeSubmit=h,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f,m){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function v(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function g(e){var t;return s.resolve().then(function(){X(e),"from"===e&&K(),B("hours")&&(_(e),"from"!==e||pe.uiOptions.multipleDays||_("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return C(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return s.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return V()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(B("hours"))return W(e).then(function(){ne(e,!0)})}).then(function(){if(oe(),!t)return Y();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(S)}function b(){return oe(),Y()}function y(){return pe.uiOptions.toDate=null,X("to"),s.resolve().then(function(){if(B("hours")&&pe.uiOptions.fromDate)return _("from"),!pe.uiOptions.multipleDays&&_("to"),W("from").then(function(){ne("from",!0)}).then(oe)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&Y)}function _(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&o&&r&&(o=P(o).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=P(r).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function $(t,n){return t?(t=h(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):A(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):s.reject([])}function C(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function A(e,n){return e=t(e),s.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function w(){return pe.request?pe.request.request_type:pe.leaveType||null}function P(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function R(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(Q).catch(S)}function D(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function S(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function T(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?Y():R()}function I(){var e=pe.request.attributes();return pe.uiOptions.fromDate=v(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=v(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function O(e){o.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){B("days")||+e==+t||(se(),pe.performBalanceChangeCalculation())})}function L(){me.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){ce()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",Y))}function M(){pe.isMode("edit")&&(pe.isLeaveStatus(u.statusNames.approved)||pe.isLeaveStatus(u.statusNames.adminApproved))&&(fe={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function k(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(D(a.min,n)<=0||D(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function x(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return s.all(e.map(W)).then(function(){["from","to"].forEach(function(e){k(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(se)}function E(){["from","to"].forEach(function(e){O(e),j(e)})}function j(e){o.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){B("days")||t===n||(oe(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function B(e){return pe.selectedAbsenceType.calculation_unit_name===e}function N(e){return pe.request.request_type===e}function F(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return $(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function H(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function W(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(h(t)).then(function(t){ve[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return ve[e]={},S(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):s.resolve()}function V(){return c.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function G(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function Y(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(Q).catch(S).finally(function(){pe.loading.balanceChange=!1})):s.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function J(){return h(pe.request.from_date)===h(pe.request.to_date)}function K(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,X("to"))}function X(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,oe(),se(),ie()}function Q(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=v(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=v(pe.period.end_date)}function ee(){return!pe.isMode("create")&&J()||pe.isMode("create")&&(N("sickness")||B("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,s.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,s=n.multipleDays&&"from"===a?r.max:n.times.to.time,i=ve[a].number_of_hours?D(o,s).toString():"0";r.maxAmount=i,t&&(r.amount=r.maxAmount)}function ae(){fe&&fe.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=fe.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function re(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function oe(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?h(e.fromDate):null,pe.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),B("hours")&&!N("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function se(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ue(){e.forEach(me,function(e){e()})}function ce(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return re(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),s.resolve().then(e&&ee).then(function(){if(e&&B("hours"))return W("from").then(function(){ne("from",!0)})}).then(e&&oe).then(Y)}function le(e){return pe.absenceTypes=e,re(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,X("to")),ae(),Y()}function de(e){var t=P(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(P(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(P(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var fe=null,me=[],pe=this,ve={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=u.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:G},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=v,pe.convertDateToServerFormat=h,pe.dateChangeHandler=g,pe.dateTypeChangeHandler=b,pe.daysSelectionModeChangeHandler=y,pe.isLeaveType=N,pe.isNotWorkingDay=F,pe.performBalanceChangeCalculation=Y,pe.$onDestroy=ue,function(){n("RequestModalDetails"+e.capitalize(w(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",pe),L(),pe.initChildController().then(function(){return s.all([V(),H()])}).then(!pe.isMode("create")&&I).then(ee).then(function(){if(!pe.isMode("create")&&B("hours"))return x().then(oe)}).then(!pe.isMode("create")&&Z).then(M).then(ae).then(T).then(function(){pe.isMode("view")||N("toil")||E()}).catch(S).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?R.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(R.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){R=e})}function A(e){return!e.attachment_id||T.canManage}function w(){e.forEach(D,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var R=[],D=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=w,T.canRemoveAttachment=A,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=v,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",selectedContactId:"<",isSelfRecord:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function v(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function h(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?R(e):n.all([R("table"),R("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function R(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function D(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:M(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:x(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function I(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function O(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function L(e,t,n,a){d.openModal.apply(d,arguments)}function M(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function k(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function x(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=k(n)),n.length)return{IN:n}}function E(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=v,U.getAbsenceTypeByID=h,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=L,U.refresh=E,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),I(),P(),S(),D(),O()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["leave-absences/shared/modules/controllers"],function(e){function t(e,t,n,a){function r(){return a.request.calculateBalanceChange(a.selectedAbsenceType.calculation_unit_name)}function o(){var e=a.request,t=!!e.from_date&&!!e.to_date,n=a.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function s(){return a.canCalculateChange()}function i(){return n.resolve()}t.debug("RequestModalDetailsLeaveController"),a.calculateBalanceChange=r,a.canCalculateChange=o,a.canSubmit=s,a.initChildController=i}e.controller("RequestModalDetailsLeaveController",t),t.$inject=["$controller","$log","$q","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s){function i(){return s.balance.change.amount=+s.request.toil_to_accrue,n.resolve(s.balance.change)}function u(){ +define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(v(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):v(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function v(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function h(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=h,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function v(e){return q.mode===e}function h(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=v,q.onBeforeSubmit=h,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f,m){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function v(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function g(e){var t;return s.resolve().then(function(){X(e),"from"===e&&K(),B("hours")&&(_(e),"from"!==e||pe.uiOptions.multipleDays||_("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return C(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return s.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return V()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(B("hours"))return W(e).then(function(){ne(e,!0)})}).then(function(){if(oe(),!t)return Y();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(S)}function b(){return oe(),Y()}function y(){return pe.uiOptions.toDate=null,X("to"),s.resolve().then(function(){if(B("hours")&&pe.uiOptions.fromDate)return _("from"),!pe.uiOptions.multipleDays&&_("to"),W("from").then(function(){ne("from",!0)}).then(oe)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&Y)}function _(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&o&&r&&(o=P(o).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=P(r).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function $(t,n){return t?(t=h(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):A(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):s.reject([])}function C(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function A(e,n){return e=t(e),s.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function w(){return pe.request?pe.request.request_type:pe.leaveType||null}function P(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function R(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(Q).catch(S)}function D(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function S(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function T(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?Y():R()}function I(){var e=pe.request.attributes();return pe.uiOptions.fromDate=v(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=v(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function O(e){o.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){B("days")||+e==+t||(se(),pe.performBalanceChangeCalculation())})}function L(){me.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){ce()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",Y))}function M(){pe.isMode("edit")&&(pe.isLeaveStatus(u.statusNames.approved)||pe.isLeaveStatus(u.statusNames.adminApproved))&&(fe={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function k(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(D(a.min,n)<=0||D(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function x(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return s.all(e.map(W)).then(function(){["from","to"].forEach(function(e){k(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(se)}function E(){["from","to"].forEach(function(e){O(e),j(e)})}function j(e){o.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){B("days")||t===n||(oe(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function B(e){return pe.selectedAbsenceType.calculation_unit_name===e}function N(e){return pe.request.request_type===e}function F(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return $(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function H(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function W(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(h(t)).then(function(t){ve[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return ve[e]={},S(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):s.resolve()}function V(){return c.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function G(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function Y(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(Q).catch(S).finally(function(){pe.loading.balanceChange=!1})):s.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function J(){return h(pe.request.from_date)===h(pe.request.to_date)}function K(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,X("to"))}function X(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,oe(),se(),ie()}function Q(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=v(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=v(pe.period.end_date)}function ee(){return!pe.isMode("create")&&J()||pe.isMode("create")&&(N("sickness")||B("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,s.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,s=n.multipleDays&&"from"===a?r.max:n.times.to.time,i=ve[a].number_of_hours?D(o,s).toString():"0";r.maxAmount=i,t&&(r.amount=r.maxAmount)}function ae(){fe&&fe.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=fe.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function re(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function oe(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?h(e.fromDate):null,pe.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),B("hours")&&!N("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function se(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ue(){e.forEach(me,function(e){e()})}function ce(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return re(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),s.resolve().then(e&&ee).then(function(){if(e&&B("hours"))return W("from").then(function(){ne("from",!0)})}).then(e&&oe).then(Y)}function le(e){return pe.absenceTypes=e,re(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,X("to")),ae(),Y()}function de(e){var t=P(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(P(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(P(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var fe=null,me=[],pe=this,ve={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=u.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:G},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=v,pe.convertDateToServerFormat=h,pe.dateChangeHandler=g,pe.dateTypeChangeHandler=b,pe.daysSelectionModeChangeHandler=y,pe.isLeaveType=N,pe.isNotWorkingDay=F,pe.performBalanceChangeCalculation=Y,pe.$onDestroy=ue,function(){n("RequestModalDetails"+e.capitalize(w(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",pe),L(),pe.initChildController().then(function(){return s.all([V(),H()])}).then(!pe.isMode("create")&&I).then(ee).then(function(){if(!pe.isMode("create")&&B("hours"))return x().then(oe)}).then(!pe.isMode("create")&&Z).then(M).then(ae).then(T).then(function(){pe.isMode("view")||N("toil")||E()}).catch(S).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?R.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(R.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){R=e})}function A(e){return!e.attachment_id||T.canManage}function w(){e.forEach(D,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var R=[],D=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=w,T.canRemoveAttachment=A,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=v,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function v(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function h(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?R(e):n.all([R("table"),R("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function R(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function D(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:M(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:x(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function I(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function O(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function L(e,t,n,a){d.openModal.apply(d,arguments)}function M(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function k(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function x(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=k(n)),n.length)return{IN:n}}function E(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=v,U.getAbsenceTypeByID=h,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=L,U.refresh=E,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),I(),P(),S(),D(),O()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["leave-absences/shared/modules/controllers"],function(e){function t(e,t,n,a){function r(){return a.request.calculateBalanceChange(a.selectedAbsenceType.calculation_unit_name)}function o(){var e=a.request,t=!!e.from_date&&!!e.to_date,n=a.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function s(){return a.canCalculateChange()}function i(){return n.resolve()}t.debug("RequestModalDetailsLeaveController"),a.calculateBalanceChange=r,a.canCalculateChange=o,a.canSubmit=s,a.initChildController=i}e.controller("RequestModalDetailsLeaveController",t),t.$inject=["$controller","$log","$q","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s){function i(){return s.balance.change.amount=+s.request.toil_to_accrue,n.resolve(s.balance.change)}function u(){ return m().catch(function(e){return e.length&&(s.errors=e),n.reject(e)}).then(function(e){return o.calculateToilExpiryDate(s.request.type_id,e)}).then(function(e){return s.request.toil_expiry_date=e,s.uiOptions.expiryDate=new Date(e),e})}function c(){return!!s.request.toil_to_accrue}function l(){var e=s.uiOptions.multipleDays&&!!s.request.to_date,t=!s.uiOptions.multipleDays&&!!s.request.from_date,n=t||e,a=A.from_date!==s.request.from_date||A.to_date!==s.request.to_date;return s.canDisplayToilExpirationField&&n&&w.hasExpirationFromAdminSettings&&a}function d(){return!!(s.request.from_date&&s.request.to_date&&s.request.toil_duration&&s.request.toil_to_accrue)}function f(){s.request.toil_expiry_date=!1,s.uiOptions.expiryDate=null}function m(){var e=s.uiOptions.multipleDays,t=s.request;return p({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function p(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return n.reject([t])}return e.value?n.resolve(e.value):n.reject([])}function v(){var e=s.isMode("create")&&w.hasExpirationFromAdminSettings,t=w.hasPreviousExpirationDate,n=s.isLeaveType("toil"),a=s.canManage;s.canDisplayToilExpirationField=n&&(a||e||t)}function h(){return w.hasPreviousExpirationDate=s.isMode("edit")&&!!s.request.toil_expiry_date,o.canExpire(s.request.type_id).then(function(e){w.hasExpirationFromAdminSettings=e})}function g(){return s.request.to_date_type=s.request.from_date_type="1",h().then(v).then(b).then(_)}function b(){s.canManage&&(s.uiOptions.expiryDate=s.convertDateFormatFromServer(s.request.toil_expiry_date))}function y(){s.isMode("view")||a.$watch(function(){return s.request.toil_to_accrue},function(e,t){+e!=+t&&s.performBalanceChangeCalculation()})}function _(){return r.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){s.toilAmounts=e.indexBy(t,"value")})}function q(){A=angular.copy(s.request.attributes())}function $(){return l()?u().catch(n.resolve):n.resolve()}function C(){s.uiOptions.expiryDate&&(s.request.toil_expiry_date=s.convertDateToServerFormat(s.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var A,w={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};s.canDisplayToilExpirationField=!1,s.calculateBalanceChange=i,s.canCalculateChange=c,s.canSubmit=d,s.clearExpiryDate=f,s.initChildController=g,s.onDateChangeExtended=$,s.setDaysSelectionModeExtended=$,s.updateExpiryDate=C,function(){y(),q()}()}t.controller("RequestModalDetailsToilController",n),n.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function v(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function h(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?v.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([h.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([h.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={toilDurationHours:"0",toilDurationMinutes:"0",request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},transformAttributes:function(e){var t=Number(e.toil_duration);return t&&(e.toilDurationHours=Math.floor(t/60).toString(),e.toilDurationMinutes=(t%60).toString()),e},updateDuration:function(){this.toil_duration=60*Number(this.toilDurationHours)+Number(this.toilDurationMinutes)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files","toilDurationHours","toilDurationMinutes"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,v,h,g,b,y,_,q,$,C){function A(e){"days"===ke.selectedAbsenceType.calculation_unit_name?delete ke.request[e+"_date_amount"]:delete ke.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=ke.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==ke.request.status_id&&d.publish("ManagerBadge:: Update Count")}function R(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function D(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!ke.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=R();return ke.isMode("edit")&&(e=e&&(V()||D())),ke.canManage&&ke.requestStatuses&&(e=e&&!!ke.getStatusFromValue(ke.newStatusOnSave)),(e=e&&!!ke.period.id)&&!ke.isMode("view")}function I(){ke.isSelfRecord?ke.request.status_id=ke.requestStatuses[_.statusNames.awaitingApproval].value:ke.canManage&&(ke.request.status_id=ke.newStatusOnSave||ke.request.status_id)}function O(){if(ke.isMode("edit")&&!ke.isRole("staff")&&"toil"!==F())return ke.request.calculateBalanceChange(ke.selectedAbsenceType.calculation_unit_name).then(function(e){if(+ke.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function L(){ke.errors=[]}function M(){return ke.request.create().then($e).then(function(){me("LeaveRequest::new")})}function k(){ee()&&!ke.isRole("staff")&&(ke.request.change_balance=!0)}function x(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return ke.request.delete().then(function(){ke.dismissModal(),d.publish("LeaveRequest::delete",ke.request)})}})}function E(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(ke.getStatusFromValue(ke.request.status_id).name)}function N(e){return n.map(Re[e],function(e){return ke.requestStatuses[e]})}function F(){return ke.request?ke.request.request_type:ke.leaveType||null}function U(){return!ke.request||e.equals({},ke.requestStatuses)?[]:ke.request.status_id?B():N("none")}function H(e){return n.find(ke.requestStatuses,function(t){return t.value===e})}function W(e){ke.errors=n.isArray(e)?e:[e],ke.loading.absenceTypes=!1,ke.submitting=!1}function V(){return!e.equals(Se,ke.request.attributes())||ke.canManage&&ke.newStatusOnSave}function G(){return ke.postContactSelection=!0,ke.staffMemberSelectionComplete=!1,ke.request.contact_id?r.resolve().then(ie).then(ue).then(ve).then(ge).then(Z).then(z).then(ke.isMode("edit")?be:n.noop).then(function(){ke.postContactSelection=!1,ke.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Oe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Re.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Re.awaiting_approval=e,Re.more_information_required=e,Re.rejected=e,Re.approved=e,Re.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return ke.canManage?m.find(ke.request.contact_id).then(function(e){ke.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(ve).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",ke.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){De++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function K(){var e,t;ke.request=ke.leaveRequest||null,e=F(),t=ke.initRequestAttributes(),"leave"===e?ke.request=y.init(t):"sickness"===e?ke.request=q.init(t):"toil"===e&&(ke.request=$.init(t))}function X(){var e={};return ke.request?e=ke.request.attributes():ke.canManage||(e={contact_id:Ie}),e}function Q(){if(Le="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Le="admin")}).then(function(){return"staff"===Le&&u(_.permissions.ssp.manage).then(function(e){e&&(Le="manager")})}).finally(function(){ke.canManage=ke.isRole("manager")||ke.isRole("admin")})}function Z(){(ke.isRole("admin")||ke.isMode("create")&&ke.isRole("manager"))&&(ke.newStatusOnSave=ke.requestStatuses[_.statusNames.approved].value)}function ee(){return!ke.request.status_id||!n.includes(["cancelled","rejected"],H(ke.request.status_id).name)}function te(e){var t=ke.getStatusFromValue(ke.request.status_id);return!!t&&t.name===e}function ne(e){return ke.request&&ke.request.request_type===e}function ae(e){return ke.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Le===e}function se(){return v.all().then(function(e){ke.absencePeriods=e})}function ie(){return h.all(j()).then(h.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return ke.loading.entitlements=!0,g.all({contact_id:ke.request.contact_id,period_id:ke.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){ke.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Ie=e.contactId})}function le(){return ke.selectedContactId?m.find(ke.selectedContactId).then(function(e){ke.managedContacts=[e]}):ke.isRole("admin")?m.all().then(function(e){ke.managedContacts=n.remove(e.list,function(e){return e.id!==Ie})}):m.find(Ie).then(function(e){return e.leaveManagees()}).then(function(e){ke.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){ke.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,ke.request),ke.errors=[],ke.dismissModal()}function pe(){["from","to"].forEach(function(e){ke.request[e+"_date"]=Se[e+"_date"]})}function ve(e){if(ke.absenceTypes=fe(Pe.types,e),!ke.absenceTypes.length)return r.reject(Oe)}function he(){ke.period=n.find(ke.absencePeriods,function(e){return ke.isMode("create")?e.current:re(ke.request,e)})}function ge(){ke.isMode("create")?(ke.selectedAbsenceType=ke.absenceTypes[0],ke.request.type_id=ke.selectedAbsenceType.id):ke.selectedAbsenceType=n.find(ke.absenceTypes,function(e){return e.id===ke.request.type_id})}function be(){Se=e.copy(ke.request.attributes())}function ye(){var e;ke.request.id?(e=[ke.requestStatuses[_.statusNames.approved].value,ke.requestStatuses[_.statusNames.adminApproved].value,ke.requestStatuses[_.statusNames.rejected].value,ke.requestStatuses[_.statusNames.cancelled].value],ke.mode="edit",ke.isRole("staff")&&e.indexOf(ke.request.status_id)>-1&&(ke.mode="view")):ke.mode="create"}function _e(){var e=ke.request.status_id;if(!ke.isMode("view")&&!ke.submitting)return ke.submitting=!0,I(),w(),ke.request.isValid().then(ee()&&O).then(k).then(!ke.request.change_balance&&pe).then(qe).then(function(){return ke.isMode("edit")?we():M()}).catch(function(t){ke.request.status_id=e,t&&W(t)}).finally(function(){ke.submitting=!1})}function qe(){return r.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===De&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return De>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return ke.request.update().then($e).then(function(){ke.isRole("manager")?me("LeaveRequest::updatedByManager"):(ke.isRole("staff")||ke.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,Re={},De=0,Se={},Te=[],Ie="",Oe="No entitlement",Le="",Me=[],ke=n.assign(this,f);ke.absencePeriods=[],ke.absenceTypes=[],ke.canManage=!1,ke.contactName=null,ke.errors=[],ke.loading={absenceTypes:!0,entitlements:!0},ke.managedContacts=[],ke.mode="",ke.newStatusOnSave=null,ke.period={},ke.postContactSelection=!1,ke.requestStatuses={},ke.selectedAbsenceType={},ke.staffMemberSelectionComplete=!1,ke.submitting=!1,ke.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},ke.canChangeAbsenceType=S,ke.canSubmit=T,ke.closeAlert=L,ke.deleteLeaveRequest=x,ke.dismissModal=E,ke.getStatuses=U,ke.getStatusFromValue=H,ke.initAfterContactSelection=G,ke.initRequestAttributes=X,ke.isLeaveStatus=te,ke.isLeaveType=ne,ke.isMode=ae,ke.isRole=oe,ke.submit=_e,ke.updateAbsenceType=Ae,function(){ke.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(he).then(function(){return ke.canManage&&!ke.isMode("edit")&&le()}).then(function(){if(ke.selectedContactId&&(ke.request.contact_id=ke.selectedContactId),ke.request.contact_id)return ke.initAfterContactSelection()}).catch(W).finally(function(){ke.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e){define("leave-absences/manager-leave/modules/config",["common/angular","leave-absences/manager-leave/modules/settings"],function(t){return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/manager-leave/requests"),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM), define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","leave-absences/shared/ui-router","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js index 3758089832d..73f9f672fb5 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js @@ -9,5 +9,5 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return V(new(V(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return V({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=V({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),V(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=V({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){V(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){V(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],w={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,V(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(V({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(w,function(e,t){g[t]=new y(V({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(w,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return V(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);V(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,V(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){A.$current.navigable==t&&c(e,n)||A.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=A.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=L[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(A.$current=t,A.current=t.self,A.params=n,W(A.params,m),A.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),A.current)}).then(null,function(a){return a===D?S:A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(A.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},A.is=function(e,t,a){a=V({relative:A.$current},a||{});var r=f(e,a.relative);return j(r)?A.$current===r&&(!t||c(r.params.$$values(t),m)):n},A.includes=function(e,t,a){if(a=V({relative:A.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=A.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(A.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function I(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function x(e,t){return{relative:S(e)||t.$current,inherit:!0}}function O(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=V(x(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=I(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function L(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=I(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function k(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function E(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,V=t.extend,W=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,V(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return f(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(m(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function f(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function m(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

","

People I approve filter displays only staff members who you approve leave for.

","

People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

"].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(L.selectedPeriod.start_date).clone().startOf("month"),a=n(L.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");L.months=e}function p(){s.$new().$watch(function(){return L.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){L.injectMonths=!0,I("injected").then(function(){R(e)}).then(function(){L.loading.calendar=!1})}function v(){x=a("LeaveCalendar"+t.capitalize(O)+"Controller").init(L)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){L.absencePeriods=t.sortBy(e,"start_date"),L.selectedPeriod=t.find(L.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return x.loadContacts().then(function(e){L.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){L.filters.optionValues.regions=e.hrjc_region,L.filters.optionValues.locations=e.hrjc_location,L.filters.optionValues.levelTypes=e.hrjc_level_type,L.filters.optionValues.departments=e.hrjc_department})}function w(){return l.all()}function C(){return r.all([y(),w(),_()]).then(function(e){L.supportData.absenceTypes=e[0],L.supportData.publicHolidays=e[1],L.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,L.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,L.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,L.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return L.injectMonths&&(e=I("destroyed"),L.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){ e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){L.loading.calendar=!0}).then(A).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=L.selectedMonths.length?L.months.filter(function(e){return t.includes(L.selectedMonths,e.index)}):L.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){L.selectedMonths=[n().month()]}function T(){return L.roleOverride?r.resolve().then(function(){O=L.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){O=e[0]?"admin":e[1]?"manager":"staff"})}function I(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===L.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var x,O,L=this;L.absencePeriods=[],L.contacts=[],L.contactIdsToReduceTo=null,L.injectMonths=!1,L.months=[],L.selectedMonths=null,L.selectedPeriod=null,L.showContactName=!1,L.showFilters=!1,L.supportData={},L.loading={calendar:!0,page:!0},L.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},L.labelPeriod=g,L.refresh=D,function(){T().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),C()])}).then(function(){return L.showFilters?$():t.noop}).then(function(){h()}).then(function(){L.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(V.period.start_date)&&r.isSameOrBefore(V.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return V.showOnlyWithLeaveRequests?V.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):V.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){x(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return V.contactIdsToReduceTo&&(V.contacts=V.contacts.filter(function(t){return e.includes(V.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){V.supportData.dayTypes=e.indexBy(V.supportData.dayTypes,"name"),V.supportData.leaveRequestStatuses=e.indexBy(V.supportData.leaveRequestStatuses,"value"),V.supportData.publicHolidays=e.transform(V.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",M)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=V.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function w(e){return!!V.supportData.publicHolidays[p(e).valueOf()]}function C(t){var n=V.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===V.month.index&&r.year()===V.month.year&&a.push(e.find(V.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(V.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function S(){return V.month.loading=!0,a.all([I(),T()]).then(g).then(k).then(function(){N=!0}).then(function(){V.month.loading=!1})}function T(){return s.all({from_date:{to:V.month.days[V.month.days.length-1].date},to_date:{from:V.month.days[0].date},status_id:{IN:R()},contact_id:{IN:V.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(V.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function I(){var t=V.month.days[0].date,n=V.month.days[V.month.days.length-1].date;return o.get(V.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function x(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function O(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function L(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:w(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?C(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function k(){return a.all(V.month.days.map(function(e){return a.all(V.contacts.map(function(t){return L(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===V.month.index})?V.visible=!1:(V.currentPage=0,V.visible=!0,(a||!N)&&S())}function E(t){var n=e.find(V.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(A(e).map(function(t){return L(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},V=this;V.currentPage=0,V.pageSize=20,V.visible=!1,V.showContactName=!!V.showContactName,V.showOnlyWithLeaveRequests=!!V.showOnlyWithLeaveRequests,V.$onDestroy=O,V.contactsList=m,V.getContactUrl=v,function(){var e=t().month(V.month.index).year(V.month.year);b(),_(),V.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=w[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(w,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:w[e].label,isDirectAction:w[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,w={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f,m){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function h(e){return t(e,u.serverDateFormat).toDate()}function v(e){return t(e).format(u.serverDateFormat)}function g(e){var t;return s.resolve().then(function(){X(e),"from"===e&&K(),B("hours")&&(_(e),"from"!==e||pe.uiOptions.multipleDays||_("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return w(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return s.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return W()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(B("hours"))return V(e).then(function(){ne(e,!0)})}).then(function(){if(oe(),!t)return Y();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(S)}function b(){return oe(),Y()}function y(){return pe.uiOptions.toDate=null,X("to"),s.resolve().then(function(){if(B("hours")&&pe.uiOptions.fromDate)return _("from"),!pe.uiOptions.multipleDays&&_("to"),V("from").then(function(){ne("from",!0)}).then(oe)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&Y)}function _(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&o&&r&&(o=P(o).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=P(r).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function $(t,n){return t?(t=v(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):C(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):s.reject([])}function w(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function C(e,n){return e=t(e),s.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function A(){return pe.request?pe.request.request_type:pe.leaveType||null}function P(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(Q).catch(S)}function R(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function S(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function T(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?Y():D()}function I(){var e=pe.request.attributes();return pe.uiOptions.fromDate=h(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=h(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function x(e){o.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){B("days")||+e==+t||(se(),pe.performBalanceChangeCalculation())})}function O(){me.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){ce()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",Y))}function L(){pe.isMode("edit")&&(pe.isLeaveStatus(u.statusNames.approved)||pe.isLeaveStatus(u.statusNames.adminApproved))&&(fe={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function k(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(R(a.min,n)<=0||R(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function M(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return s.all(e.map(V)).then(function(){["from","to"].forEach(function(e){k(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(se)}function E(){["from","to"].forEach(function(e){x(e),j(e)})}function j(e){o.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){B("days")||t===n||(oe(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function B(e){return pe.selectedAbsenceType.calculation_unit_name===e}function N(e){return pe.request.request_type===e}function F(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return $(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function H(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function V(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(v(t)).then(function(t){he[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return he[e]={},S(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):s.resolve()}function W(){return c.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function G(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function Y(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(Q).catch(S).finally(function(){pe.loading.balanceChange=!1})):s.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function J(){return v(pe.request.from_date)===v(pe.request.to_date)}function K(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,X("to"))}function X(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,oe(),se(),ie()}function Q(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=h(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=h(pe.period.end_date)}function ee(){return!pe.isMode("create")&&J()||pe.isMode("create")&&(N("sickness")||B("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,s.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,s=n.multipleDays&&"from"===a?r.max:n.times.to.time,i=he[a].number_of_hours?R(o,s).toString():"0";r.maxAmount=i,t&&(r.amount=r.maxAmount)}function ae(){fe&&fe.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=fe.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function re(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function oe(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?v(e.fromDate):null,pe.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),B("hours")&&!N("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function se(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ue(){e.forEach(me,function(e){e()})}function ce(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return re(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),s.resolve().then(e&&ee).then(function(){if(e&&B("hours"))return V("from").then(function(){ne("from",!0)})}).then(e&&oe).then(Y)}function le(e){return pe.absenceTypes=e,re(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,X("to")),ae(),Y()}function de(e){var t=P(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(P(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(P(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var fe=null,me=[],pe=this,he={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=u.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:G},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=h,pe.convertDateToServerFormat=v,pe.dateChangeHandler=g,pe.dateTypeChangeHandler=b,pe.daysSelectionModeChangeHandler=y,pe.isLeaveType=N,pe.isNotWorkingDay=F,pe.performBalanceChangeCalculation=Y,pe.$onDestroy=ue,function(){n("RequestModalDetails"+e.capitalize(A(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",pe),O(),pe.initChildController().then(function(){return s.all([W(),H()])}).then(!pe.isMode("create")&&I).then(ee).then(function(){if(!pe.isMode("create")&&B("hours"))return M().then(oe)}).then(!pe.isMode("create")&&Z).then(L).then(ae).then(T).then(function(){pe.isMode("view")||N("toil")||E()}).catch(S).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function w(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function C(e){return!e.attachment_id||T.canManage}function A(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=A,T.canRemoveAttachment=C,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=h,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([w(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{ -type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",selectedContactId:"<",isSelfRecord:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,r,o,s,i,u,c,l,d,f){function m(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),H.sections.other.open&&m(e,H.sections.other)}function h(){Object.values(H.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):H.refresh()}function g(t){t.dataIndex=e.indexBy(t.data,"id")}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function y(){return o.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.selectedPeriod=e.find(H.absencePeriods,function(e){return!0===e.current})})}function _(){return s.all().then(s.loadCalculationUnits).then(function(t){H.absenceTypes=t,H.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return D("approved",{status_id:F(f.statusNames.approved)})}function $(){return n.all([u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,null,!0),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(f.statusNames.approved)]),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(f.statusNames.awaitingApproval),F(f.statusNames.moreInformationRequired)])]).then(function(e){H.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function w(){return i.all({contact_id:H.contactId,period_id:H.selectedPeriod.id},!0).then(function(e){H.entitlements=e}).then(function(){H.absenceTypesFiltered=H.absenceTypes.filter(function(t){var n=e.find(H.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function C(){return i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id},H.entitlements).then(function(){return L(H.entitlements)}).then(function(e){H.sections.entitlements.data=e})}function A(){return n.all([i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id,expired:!0}),P({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:L(e[0]),expiredTOILS:k(e[1].list)})}).then(function(t){H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function P(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function D(e,t){return P(t).then(function(t){H.sections[e].data=t.list})}function R(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(x))}function S(){return D("other",{status_id:{in:[F(f.statusNames.rejected),F(f.statusNames.cancelled)]}})}function T(){return D("pending",{status_id:{in:[F(f.statusNames.awaitingApproval),F(f.statusNames.moreInformationRequired)]}})}function I(){return D("holidays",{public_holiday:!0})}function x(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function O(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function L(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function k(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([w(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([R(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&x(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:E,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:C},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:I},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:T},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([O(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([w(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["leave-absences/shared/modules/controllers"],function(e){function t(e,t,n,a){function r(){return a.request.calculateBalanceChange(a.selectedAbsenceType.calculation_unit_name)}function o(){var e=a.request,t=!!e.from_date&&!!e.to_date,n=a.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function s(){return a.canCalculateChange()}function i(){return n.resolve()}t.debug("RequestModalDetailsLeaveController"),a.calculateBalanceChange=r,a.canCalculateChange=o,a.canSubmit=s,a.initChildController=i}e.controller("RequestModalDetailsLeaveController",t),t.$inject=["$controller","$log","$q","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s){function i(){return s.balance.change.amount=+s.request.toil_to_accrue,n.resolve(s.balance.change)}function u(){return m().catch(function(e){return e.length&&(s.errors=e),n.reject(e)}).then(function(e){return o.calculateToilExpiryDate(s.request.type_id,e)}).then(function(e){return s.request.toil_expiry_date=e,s.uiOptions.expiryDate=new Date(e),e})}function c(){return!!s.request.toil_to_accrue}function l(){var e=s.uiOptions.multipleDays&&!!s.request.to_date,t=!s.uiOptions.multipleDays&&!!s.request.from_date,n=t||e,a=C.from_date!==s.request.from_date||C.to_date!==s.request.to_date;return s.canDisplayToilExpirationField&&n&&A.hasExpirationFromAdminSettings&&a}function d(){return!!(s.request.from_date&&s.request.to_date&&s.request.toil_duration&&s.request.toil_to_accrue)}function f(){s.request.toil_expiry_date=!1,s.uiOptions.expiryDate=null}function m(){var e=s.uiOptions.multipleDays,t=s.request;return p({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function p(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return n.reject([t])}return e.value?n.resolve(e.value):n.reject([])}function h(){var e=s.isMode("create")&&A.hasExpirationFromAdminSettings,t=A.hasPreviousExpirationDate,n=s.isLeaveType("toil"),a=s.canManage;s.canDisplayToilExpirationField=n&&(a||e||t)}function v(){return A.hasPreviousExpirationDate=s.isMode("edit")&&!!s.request.toil_expiry_date,o.canExpire(s.request.type_id).then(function(e){A.hasExpirationFromAdminSettings=e})}function g(){return s.request.to_date_type=s.request.from_date_type="1",v().then(h).then(b).then(_)}function b(){s.canManage&&(s.uiOptions.expiryDate=s.convertDateFormatFromServer(s.request.toil_expiry_date))}function y(){s.isMode("view")||a.$watch(function(){return s.request.toil_to_accrue},function(e,t){+e!=+t&&s.performBalanceChangeCalculation()})}function _(){return r.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){s.toilAmounts=e.indexBy(t,"value")})}function q(){C=angular.copy(s.request.attributes())}function $(){return l()?u().catch(n.resolve):n.resolve()}function w(){s.uiOptions.expiryDate&&(s.request.toil_expiry_date=s.convertDateToServerFormat(s.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var C,A={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};s.canDisplayToilExpirationField=!1,s.calculateBalanceChange=i,s.canCalculateChange=c,s.canSubmit=d,s.clearExpiryDate=f,s.initChildController=g,s.onDateChangeExtended=$,s.setDaysSelectionModeExtended=$,s.updateExpiryDate=w,function(){y(),q()}()}t.controller("RequestModalDetailsToilController",n),n.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={toilDurationHours:"0",toilDurationMinutes:"0",request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},transformAttributes:function(e){var t=Number(e.toil_duration);return t&&(e.toilDurationHours=Math.floor(t/60).toString(),e.toilDurationMinutes=(t%60).toString()),e},updateDuration:function(){this.toil_duration=60*Number(this.toilDurationHours)+Number(this.toilDurationMinutes)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files","toilDurationHours","toilDurationMinutes"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,w){function C(e){"days"===ke.selectedAbsenceType.calculation_unit_name?delete ke.request[e+"_date_amount"]:delete ke.request[e+"_date_type"]}function A(){["from","to"].forEach(C)}function P(){var e=ke.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==ke.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Le.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Le.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!ke.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return ke.isMode("edit")&&(e=e&&(W()||R())),ke.canManage&&ke.requestStatuses&&(e=e&&!!ke.getStatusFromValue(ke.newStatusOnSave)),(e=e&&!!ke.period.id)&&!ke.isMode("view")}function I(){ke.isSelfRecord?ke.request.status_id=ke.requestStatuses[_.statusNames.awaitingApproval].value:ke.canManage&&(ke.request.status_id=ke.newStatusOnSave||ke.request.status_id)}function x(){if(ke.isMode("edit")&&!ke.isRole("staff")&&"toil"!==F())return ke.request.calculateBalanceChange(ke.selectedAbsenceType.calculation_unit_name).then(function(e){if(+ke.balance.change.amount!=+e.amount)return w.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function O(){ke.errors=[]}function L(){return ke.request.create().then($e).then(function(){me("LeaveRequest::new")})}function k(){ee()&&!ke.isRole("staff")&&(ke.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return ke.request.delete().then(function(){ke.dismissModal(),d.publish("LeaveRequest::delete",ke.request)})}})}function E(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(ke.getStatusFromValue(ke.request.status_id).name)}function N(e){return n.map(De[e],function(e){return ke.requestStatuses[e]})}function F(){return ke.request?ke.request.request_type:ke.leaveType||null}function U(){return!ke.request||e.equals({},ke.requestStatuses)?[]:ke.request.status_id?B():N("none")}function H(e){return n.find(ke.requestStatuses,function(t){return t.value===e})}function V(e){ke.errors=n.isArray(e)?e:[e],ke.loading.absenceTypes=!1,ke.submitting=!1}function W(){return!e.equals(Se,ke.request.attributes())||ke.canManage&&ke.newStatusOnSave}function G(){return ke.postContactSelection=!0,ke.staffMemberSelectionComplete=!1,ke.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(ke.isMode("edit")?be:n.noop).then(function(){ke.postContactSelection=!1,ke.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==xe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return ke.canManage?m.find(ke.request.contact_id).then(function(e){ke.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",ke.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){V(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",we),s.$on("LeaveRequestPopup::addTab",function(e,t){Le.push(t)})}function K(){var e,t;ke.request=ke.leaveRequest||null,e=F(),t=ke.initRequestAttributes(),"leave"===e?ke.request=y.init(t):"sickness"===e?ke.request=q.init(t):"toil"===e&&(ke.request=$.init(t))}function X(){var e={};return ke.request?e=ke.request.attributes():ke.canManage||(e={contact_id:Ie}),e}function Q(){if(Oe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Oe="admin")}).then(function(){return"staff"===Oe&&u(_.permissions.ssp.manage).then(function(e){e&&(Oe="manager")})}).finally(function(){ke.canManage=ke.isRole("manager")||ke.isRole("admin")})}function Z(){(ke.isRole("admin")||ke.isMode("create")&&ke.isRole("manager"))&&(ke.newStatusOnSave=ke.requestStatuses[_.statusNames.approved].value)}function ee(){return!ke.request.status_id||!n.includes(["cancelled","rejected"],H(ke.request.status_id).name)}function te(e){var t=ke.getStatusFromValue(ke.request.status_id);return!!t&&t.name===e}function ne(e){return ke.request&&ke.request.request_type===e}function ae(e){return ke.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Oe===e}function se(){return h.all().then(function(e){ke.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return ke.loading.entitlements=!0,g.all({contact_id:ke.request.contact_id,period_id:ke.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){ke.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Ie=e.contactId})}function le(){return ke.selectedContactId?m.find(ke.selectedContactId).then(function(e){ke.managedContacts=[e]}):ke.isRole("admin")?m.all().then(function(e){ke.managedContacts=n.remove(e.list,function(e){return e.id!==Ie})}):m.find(Ie).then(function(e){return e.leaveManagees()}).then(function(e){ke.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){ke.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,ke.request),ke.errors=[],ke.dismissModal()}function pe(){["from","to"].forEach(function(e){ke.request[e+"_date"]=Se[e+"_date"]})}function he(e){if(ke.absenceTypes=fe(Pe.types,e),!ke.absenceTypes.length)return r.reject(xe)}function ve(){ke.period=n.find(ke.absencePeriods,function(e){return ke.isMode("create")?e.current:re(ke.request,e)})}function ge(){ke.isMode("create")?(ke.selectedAbsenceType=ke.absenceTypes[0],ke.request.type_id=ke.selectedAbsenceType.id):ke.selectedAbsenceType=n.find(ke.absenceTypes,function(e){return e.id===ke.request.type_id})}function be(){Se=e.copy(ke.request.attributes())}function ye(){var e;ke.request.id?(e=[ke.requestStatuses[_.statusNames.approved].value,ke.requestStatuses[_.statusNames.adminApproved].value,ke.requestStatuses[_.statusNames.rejected].value,ke.requestStatuses[_.statusNames.cancelled].value],ke.mode="edit",ke.isRole("staff")&&e.indexOf(ke.request.status_id)>-1&&(ke.mode="view")):ke.mode="create"}function _e(){var e=ke.request.status_id;if(!ke.isMode("view")&&!ke.submitting)return ke.submitting=!0,I(),A(),ke.request.isValid().then(ee()&&x).then(k).then(!ke.request.change_balance&&pe).then(qe).then(function(){return ke.isMode("edit")?Ae():L()}).catch(function(t){ke.request.status_id=e,t&&V(t)}).finally(function(){ke.submitting=!1})}function qe(){return r.all(Le.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function we(){Te.forEach(function(e){e()})}function Ce(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return ke.request.update().then($e).then(function(){ke.isRole("manager")?me("LeaveRequest::updatedByManager"):(ke.isRole("staff")||ke.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Ie="",xe="No entitlement",Oe="",Le=[],ke=n.assign(this,f);ke.absencePeriods=[],ke.absenceTypes=[],ke.canManage=!1,ke.contactName=null,ke.errors=[],ke.loading={absenceTypes:!0,entitlements:!0},ke.managedContacts=[],ke.mode="",ke.newStatusOnSave=null,ke.period={},ke.postContactSelection=!1,ke.requestStatuses={},ke.selectedAbsenceType={},ke.staffMemberSelectionComplete=!1,ke.submitting=!1,ke.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},ke.canChangeAbsenceType=S,ke.canSubmit=T,ke.closeAlert=O,ke.deleteLeaveRequest=M,ke.dismissModal=E,ke.getStatuses=U,ke.getStatusFromValue=H,ke.initAfterContactSelection=G,ke.initRequestAttributes=X,ke.isLeaveStatus=te,ke.isLeaveType=ne,ke.isMode=ae,ke.isRole=oe,ke.submit=_e,ke.updateAbsenceType=Ce,function(){ke.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return ke.canManage&&!ke.isMode("edit")&&le()}).then(function(){if(ke.selectedContactId&&(ke.request.contact_id=ke.selectedContactId),ke.request.contact_id)return ke.initAfterContactSelection()}).catch(V).finally(function(){ke.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM),define("leave-absences/my-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/models/option-group","common/modules/dialog","common/services/check-permissions","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/my-leave/components/my-leave-container.component","leave-absences/my-leave/modules/config"],function(e){return e.module("my-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.mocks","common.models","common.services","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","my-leave.components","my-leave.config"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/my-leave":n+"/my-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/my-leave/app"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-my-leave]"),["my-leave"])})})}(CRM,require),define("my-leave",function(){}); +type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,r,o,s,i,u,c,l,d,f){function m(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),H.sections.other.open&&m(e,H.sections.other)}function h(){Object.values(H.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):H.refresh()}function g(t){t.dataIndex=e.indexBy(t.data,"id")}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function y(){return o.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.selectedPeriod=e.find(H.absencePeriods,function(e){return!0===e.current})})}function _(){return s.all().then(s.loadCalculationUnits).then(function(t){H.absenceTypes=t,H.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return D("approved",{status_id:F(f.statusNames.approved)})}function $(){return n.all([u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,null,!0),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(f.statusNames.approved)]),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(f.statusNames.awaitingApproval),F(f.statusNames.moreInformationRequired)])]).then(function(e){H.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function w(){return i.all({contact_id:H.contactId,period_id:H.selectedPeriod.id},!0).then(function(e){H.entitlements=e}).then(function(){H.absenceTypesFiltered=H.absenceTypes.filter(function(t){var n=e.find(H.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function C(){return i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id},H.entitlements).then(function(){return L(H.entitlements)}).then(function(e){H.sections.entitlements.data=e})}function A(){return n.all([i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id,expired:!0}),P({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:L(e[0]),expiredTOILS:k(e[1].list)})}).then(function(t){H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function P(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function D(e,t){return P(t).then(function(t){H.sections[e].data=t.list})}function R(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(x))}function S(){return D("other",{status_id:{in:[F(f.statusNames.rejected),F(f.statusNames.cancelled)]}})}function T(){return D("pending",{status_id:{in:[F(f.statusNames.awaitingApproval),F(f.statusNames.moreInformationRequired)]}})}function I(){return D("holidays",{public_holiday:!0})}function x(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function O(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function L(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function k(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([w(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([R(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&x(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:E,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:C},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:I},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:T},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([O(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([w(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["leave-absences/shared/modules/controllers"],function(e){function t(e,t,n,a){function r(){return a.request.calculateBalanceChange(a.selectedAbsenceType.calculation_unit_name)}function o(){var e=a.request,t=!!e.from_date&&!!e.to_date,n=a.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function s(){return a.canCalculateChange()}function i(){return n.resolve()}t.debug("RequestModalDetailsLeaveController"),a.calculateBalanceChange=r,a.canCalculateChange=o,a.canSubmit=s,a.initChildController=i}e.controller("RequestModalDetailsLeaveController",t),t.$inject=["$controller","$log","$q","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s){function i(){return s.balance.change.amount=+s.request.toil_to_accrue,n.resolve(s.balance.change)}function u(){return m().catch(function(e){return e.length&&(s.errors=e),n.reject(e)}).then(function(e){return o.calculateToilExpiryDate(s.request.type_id,e)}).then(function(e){return s.request.toil_expiry_date=e,s.uiOptions.expiryDate=new Date(e),e})}function c(){return!!s.request.toil_to_accrue}function l(){var e=s.uiOptions.multipleDays&&!!s.request.to_date,t=!s.uiOptions.multipleDays&&!!s.request.from_date,n=t||e,a=C.from_date!==s.request.from_date||C.to_date!==s.request.to_date;return s.canDisplayToilExpirationField&&n&&A.hasExpirationFromAdminSettings&&a}function d(){return!!(s.request.from_date&&s.request.to_date&&s.request.toil_duration&&s.request.toil_to_accrue)}function f(){s.request.toil_expiry_date=!1,s.uiOptions.expiryDate=null}function m(){var e=s.uiOptions.multipleDays,t=s.request;return p({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function p(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return n.reject([t])}return e.value?n.resolve(e.value):n.reject([])}function h(){var e=s.isMode("create")&&A.hasExpirationFromAdminSettings,t=A.hasPreviousExpirationDate,n=s.isLeaveType("toil"),a=s.canManage;s.canDisplayToilExpirationField=n&&(a||e||t)}function v(){return A.hasPreviousExpirationDate=s.isMode("edit")&&!!s.request.toil_expiry_date,o.canExpire(s.request.type_id).then(function(e){A.hasExpirationFromAdminSettings=e})}function g(){return s.request.to_date_type=s.request.from_date_type="1",v().then(h).then(b).then(_)}function b(){s.canManage&&(s.uiOptions.expiryDate=s.convertDateFormatFromServer(s.request.toil_expiry_date))}function y(){s.isMode("view")||a.$watch(function(){return s.request.toil_to_accrue},function(e,t){+e!=+t&&s.performBalanceChangeCalculation()})}function _(){return r.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){s.toilAmounts=e.indexBy(t,"value")})}function q(){C=angular.copy(s.request.attributes())}function $(){return l()?u().catch(n.resolve):n.resolve()}function w(){s.uiOptions.expiryDate&&(s.request.toil_expiry_date=s.convertDateToServerFormat(s.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var C,A={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};s.canDisplayToilExpirationField=!1,s.calculateBalanceChange=i,s.canCalculateChange=c,s.canSubmit=d,s.clearExpiryDate=f,s.initChildController=g,s.onDateChangeExtended=$,s.setDaysSelectionModeExtended=$,s.updateExpiryDate=w,function(){y(),q()}()}t.controller("RequestModalDetailsToilController",n),n.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={toilDurationHours:"0",toilDurationMinutes:"0",request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},transformAttributes:function(e){var t=Number(e.toil_duration);return t&&(e.toilDurationHours=Math.floor(t/60).toString(),e.toilDurationMinutes=(t%60).toString()),e},updateDuration:function(){this.toil_duration=60*Number(this.toilDurationHours)+Number(this.toilDurationMinutes)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files","toilDurationHours","toilDurationMinutes"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,w){function C(e){"days"===ke.selectedAbsenceType.calculation_unit_name?delete ke.request[e+"_date_amount"]:delete ke.request[e+"_date_type"]}function A(){["from","to"].forEach(C)}function P(){var e=ke.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==ke.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Le.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Le.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!ke.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return ke.isMode("edit")&&(e=e&&(W()||R())),ke.canManage&&ke.requestStatuses&&(e=e&&!!ke.getStatusFromValue(ke.newStatusOnSave)),(e=e&&!!ke.period.id)&&!ke.isMode("view")}function I(){ke.isSelfRecord?ke.request.status_id=ke.requestStatuses[_.statusNames.awaitingApproval].value:ke.canManage&&(ke.request.status_id=ke.newStatusOnSave||ke.request.status_id)}function x(){if(ke.isMode("edit")&&!ke.isRole("staff")&&"toil"!==F())return ke.request.calculateBalanceChange(ke.selectedAbsenceType.calculation_unit_name).then(function(e){if(+ke.balance.change.amount!=+e.amount)return w.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function O(){ke.errors=[]}function L(){return ke.request.create().then($e).then(function(){me("LeaveRequest::new")})}function k(){ee()&&!ke.isRole("staff")&&(ke.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return ke.request.delete().then(function(){ke.dismissModal(),d.publish("LeaveRequest::delete",ke.request)})}})}function E(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(ke.getStatusFromValue(ke.request.status_id).name)}function N(e){return n.map(De[e],function(e){return ke.requestStatuses[e]})}function F(){return ke.request?ke.request.request_type:ke.leaveType||null}function U(){return!ke.request||e.equals({},ke.requestStatuses)?[]:ke.request.status_id?B():N("none")}function H(e){return n.find(ke.requestStatuses,function(t){return t.value===e})}function V(e){ke.errors=n.isArray(e)?e:[e],ke.loading.absenceTypes=!1,ke.submitting=!1}function W(){return!e.equals(Se,ke.request.attributes())||ke.canManage&&ke.newStatusOnSave}function G(){return ke.postContactSelection=!0,ke.staffMemberSelectionComplete=!1,ke.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(ke.isMode("edit")?be:n.noop).then(function(){ke.postContactSelection=!1,ke.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==xe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return ke.canManage?m.find(ke.request.contact_id).then(function(e){ke.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",ke.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){V(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",we),s.$on("LeaveRequestPopup::addTab",function(e,t){Le.push(t)})}function K(){var e,t;ke.request=ke.leaveRequest||null,e=F(),t=ke.initRequestAttributes(),"leave"===e?ke.request=y.init(t):"sickness"===e?ke.request=q.init(t):"toil"===e&&(ke.request=$.init(t))}function X(){var e={};return ke.request?e=ke.request.attributes():ke.canManage||(e={contact_id:Ie}),e}function Q(){if(Oe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Oe="admin")}).then(function(){return"staff"===Oe&&u(_.permissions.ssp.manage).then(function(e){e&&(Oe="manager")})}).finally(function(){ke.canManage=ke.isRole("manager")||ke.isRole("admin")})}function Z(){(ke.isRole("admin")||ke.isMode("create")&&ke.isRole("manager"))&&(ke.newStatusOnSave=ke.requestStatuses[_.statusNames.approved].value)}function ee(){return!ke.request.status_id||!n.includes(["cancelled","rejected"],H(ke.request.status_id).name)}function te(e){var t=ke.getStatusFromValue(ke.request.status_id);return!!t&&t.name===e}function ne(e){return ke.request&&ke.request.request_type===e}function ae(e){return ke.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Oe===e}function se(){return h.all().then(function(e){ke.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return ke.loading.entitlements=!0,g.all({contact_id:ke.request.contact_id,period_id:ke.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){ke.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Ie=e.contactId})}function le(){return ke.selectedContactId?m.find(ke.selectedContactId).then(function(e){ke.managedContacts=[e]}):ke.isRole("admin")?m.all().then(function(e){ke.managedContacts=n.remove(e.list,function(e){return e.id!==Ie})}):m.find(Ie).then(function(e){return e.leaveManagees()}).then(function(e){ke.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){ke.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,ke.request),ke.errors=[],ke.dismissModal()}function pe(){["from","to"].forEach(function(e){ke.request[e+"_date"]=Se[e+"_date"]})}function he(e){if(ke.absenceTypes=fe(Pe.types,e),!ke.absenceTypes.length)return r.reject(xe)}function ve(){ke.period=n.find(ke.absencePeriods,function(e){return ke.isMode("create")?e.current:re(ke.request,e)})}function ge(){ke.isMode("create")?(ke.selectedAbsenceType=ke.absenceTypes[0],ke.request.type_id=ke.selectedAbsenceType.id):ke.selectedAbsenceType=n.find(ke.absenceTypes,function(e){return e.id===ke.request.type_id})}function be(){Se=e.copy(ke.request.attributes())}function ye(){var e;ke.request.id?(e=[ke.requestStatuses[_.statusNames.approved].value,ke.requestStatuses[_.statusNames.adminApproved].value,ke.requestStatuses[_.statusNames.rejected].value,ke.requestStatuses[_.statusNames.cancelled].value],ke.mode="edit",ke.isRole("staff")&&e.indexOf(ke.request.status_id)>-1&&(ke.mode="view")):ke.mode="create"}function _e(){var e=ke.request.status_id;if(!ke.isMode("view")&&!ke.submitting)return ke.submitting=!0,I(),A(),ke.request.isValid().then(ee()&&x).then(k).then(!ke.request.change_balance&&pe).then(qe).then(function(){return ke.isMode("edit")?Ae():L()}).catch(function(t){ke.request.status_id=e,t&&V(t)}).finally(function(){ke.submitting=!1})}function qe(){return r.all(Le.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function we(){Te.forEach(function(e){e()})}function Ce(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return ke.request.update().then($e).then(function(){ke.isRole("manager")?me("LeaveRequest::updatedByManager"):(ke.isRole("staff")||ke.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Ie="",xe="No entitlement",Oe="",Le=[],ke=n.assign(this,f);ke.absencePeriods=[],ke.absenceTypes=[],ke.canManage=!1,ke.contactName=null,ke.errors=[],ke.loading={absenceTypes:!0,entitlements:!0},ke.managedContacts=[],ke.mode="",ke.newStatusOnSave=null,ke.period={},ke.postContactSelection=!1,ke.requestStatuses={},ke.selectedAbsenceType={},ke.staffMemberSelectionComplete=!1,ke.submitting=!1,ke.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},ke.canChangeAbsenceType=S,ke.canSubmit=T,ke.closeAlert=O,ke.deleteLeaveRequest=M,ke.dismissModal=E,ke.getStatuses=U,ke.getStatusFromValue=H,ke.initAfterContactSelection=G,ke.initRequestAttributes=X,ke.isLeaveStatus=te,ke.isLeaveType=ne,ke.isMode=ae,ke.isRole=oe,ke.submit=_e,ke.updateAbsenceType=Ce,function(){ke.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return ke.canManage&&!ke.isMode("edit")&&le()}).then(function(){if(ke.selectedContactId&&(ke.request.contact_id=ke.selectedContactId),ke.request.contact_id)return ke.initAfterContactSelection()}).catch(V).finally(function(){ke.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM),define("leave-absences/my-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/models/option-group","common/modules/dialog","common/services/check-permissions","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/my-leave/components/my-leave-container.component","leave-absences/my-leave/modules/config"],function(e){return e.module("my-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.mocks","common.models","common.services","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","my-leave.components","my-leave.config"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/my-leave":n+"/my-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/my-leave/app"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-my-leave]"),["my-leave"])})})}(CRM,require),define("my-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-record-actions.component.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-record-actions.component.js index 638441ccb48..8f7cf0ec81e 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-record-actions.component.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-record-actions.component.js @@ -8,8 +8,8 @@ define([ components.component('leaveRequestRecordActions', { bindings: { contactId: '<', - selectedContactId: '<', - isSelfRecord: '<' + isSelfRecord: '<', + selectedContactId: '<' }, templateUrl: ['shared-settings', function (sharedSettings) { return sharedSettings.sharedPathTpl + 'components/leave-request-record-actions.html'; diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_absence-work-patterns.scss b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_absence-work-patterns.scss index 962a3cb53b1..b9d628d75ce 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_absence-work-patterns.scss +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_absence-work-patterns.scss @@ -1,3 +1,7 @@ +.chr_absence-work-pattern__add-custom { + margin-bottom: 20px; +} + .chr_absence-work-pattern__custom-work-pattern { td:nth-child(1) { width: 40%; diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave-request-record-actions.scss b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave-request-record-actions.scss index 2690e40bddf..626b12d8c79 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave-request-record-actions.scss +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave-request-record-actions.scss @@ -1,33 +1,30 @@ leave-request-record-actions { display: block; - .fa, - .btn-group { - margin-right: $crm-gap-medium; - } -} - -leave-request-record-actions .btn-toolbar { - margin-left: 0; - overflow: inherit; - - .btn-group, - .btn { + .leave-request-record-actions__button { + display: block; + float: left; margin-left: 0; + + &:first-child { + margin-right: $crm-gap-medium; + } } } @media screen and (max-width: $screen-xs-max) { leave-request-record-actions { - .btn-group, - .btn { - display: block; + .leave-request-record-actions__button { width: 100%; - } - .btn-group { - margin-bottom: $crm-gap-medium; - margin-right: 0; + > .btn { + width: 100%; + } + + &:first-child { + margin-bottom: $crm-gap-medium; + margin-right: 0; + } } } } diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_absence-tab-page.scss b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_absence-tab-page.scss index 3c9e65ae305..656300104a6 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_absence-tab-page.scss +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/pages/_absence-tab-page.scss @@ -8,6 +8,6 @@ } leave-request-record-actions { - margin-bottom: $crm-panel-nested-indent; + margin-bottom: 20px; } } diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/absence-tab/components/absence-tab-container.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/absence-tab/components/absence-tab-container.html index ebb325809dc..49f2d79ae32 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/absence-tab/components/absence-tab-container.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/absence-tab/components/absence-tab-container.html @@ -1,7 +1,6 @@
diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/absence-tab/components/absence-tab-work-patterns.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/absence-tab/components/absence-tab-work-patterns.html index 77106b7ed35..07c8fafdddf 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/absence-tab/components/absence-tab-work-patterns.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/absence-tab/components/absence-tab-work-patterns.html @@ -1,8 +1,6 @@ -

- -

+
diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/admin-dashboard/components/admin-dashboard-container.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/admin-dashboard/components/admin-dashboard-container.html index 9170855c942..17366f6455e 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/admin-dashboard/components/admin-dashboard-container.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/admin-dashboard/components/admin-dashboard-container.html @@ -2,7 +2,6 @@
diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/manager-leave/components/manager-leave-container.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/manager-leave/components/manager-leave-container.html index 7ee85885f06..ae09d81edfa 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/manager-leave/components/manager-leave-container.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/manager-leave/components/manager-leave-container.html @@ -1,7 +1,6 @@
-
@@ -151,10 +150,10 @@
- + target="_blank" title="Edit Departments" + data-option-edit-path="civicrm/admin/options/hrjc_department">
@@ -176,10 +175,10 @@ - + target="_blank" title="Edit Levels" + data-option-edit-path="civicrm/admin/options/hrjc_level_type"> diff --git a/com.civicrm.hrjobroles/views/include/job_role_panel.html b/com.civicrm.hrjobroles/views/include/job_role_panel.html index f2b61df5eb3..ad992fdc223 100755 --- a/com.civicrm.hrjobroles/views/include/job_role_panel.html +++ b/com.civicrm.hrjobroles/views/include/job_role_panel.html @@ -205,10 +205,10 @@ - + target="_blank" title="Edit Regions" + data-option-edit-path="civicrm/admin/options/hrjc_region"> @@ -238,10 +238,10 @@ - + target="_blank" title="Edit Departments" + data-option-edit-path="civicrm/admin/options/hrjc_department"> @@ -271,10 +271,10 @@ - + target="_blank" title="Edit Levels" + data-option-edit-path="civicrm/admin/options/hrjc_level_type"> From 49e363844aa45792d8e0f2fd28799d17ece822b4 Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Mon, 26 Mar 2018 10:49:29 +0100 Subject: [PATCH 068/203] PCHR-3451: Upgrade existing work pattern to the new default value --- .../CRM/HRLeaveAndAbsences/Upgrader.php | 1 + .../HRLeaveAndAbsences/Upgrader/Step/1022.php | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php index 9b9fd3058a4..bc583e58322 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php @@ -27,6 +27,7 @@ class CRM_HRLeaveAndAbsences_Upgrader extends CRM_HRLeaveAndAbsences_Upgrader_Ba use CRM_HRLeaveAndAbsences_Upgrader_Step_1019; use CRM_HRLeaveAndAbsences_Upgrader_Step_1020; use CRM_HRLeaveAndAbsences_Upgrader_Step_1021; + use CRM_HRLeaveAndAbsences_Upgrader_Step_1022; /** * A list of directories to be scanned for XML installation files diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php new file mode 100644 index 00000000000..5e19ae1ecf1 --- /dev/null +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php @@ -0,0 +1,22 @@ + ['id'], + 'api.ContactWorkPattern.update' => [ + 'change_reason' => 1, + 'id' => "\$value.id" + ], + ]); + + return TRUE; + } +} From 95e94778654f80f4dce29b378f300df0a9fe3f19 Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Mon, 26 Mar 2018 14:44:23 +0100 Subject: [PATCH 069/203] PCHR-3451: PR Feedback --- .../HRLeaveAndAbsences/Upgrader/Step/1022.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php index 5e19ae1ecf1..d48ecf45232 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php @@ -9,13 +9,15 @@ trait CRM_HRLeaveAndAbsences_Upgrader_Step_1022 { */ public function upgrade_1022() { - civicrm_api3('ContactWorkPattern', 'get', [ - 'return' => ['id'], - 'api.ContactWorkPattern.update' => [ - 'change_reason' => 1, - 'id' => "\$value.id" - ], - ]); + $query = 'UPDATE civicrm_hrleaveandabsences_contact_work_pattern SET change_reason = + ( + SELECT cov.value FROM civicrm_option_value cov LEFT JOIN civicrm_option_group cog + ON (cog.id = cov.option_group_id) + WHERE cog.name = "hrleaveandabsences_work_pattern_change_reason" + AND cov.is_default = 1 + )'; + + CRM_Core_DAO::executeQuery($query); return TRUE; } From 877fe044b6ac0bb4d5d998a876e5d99b19f388c2 Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Tue, 27 Mar 2018 09:59:20 +0100 Subject: [PATCH 070/203] PCHR-3162: Merged in updates from staging --- bin/git-release.sh | 3 +- com.civicrm.hrjobroles/info.xml | 11 ++- contactaccessrights/info.xml | 11 ++- contactsummary/css/contactsummary.css | 2 +- contactsummary/info.xml | 11 ++- contactsummary/scss/contactsummary.scss | 11 +-- hrbank/info.xml | 7 +- hrcareer/info.xml | 7 +- hrcase/info.xml | 7 +- hrdemog/info.xml | 7 +- hrident/info.xml | 3 +- hrim/info.xml | 7 +- hrjobcontract/info.xml | 11 ++- hrjobcontract/js/dist/job-contract.min.js | 4 +- .../controllers/form/form-pay.controller.js | 4 +- hrmed/info.xml | 7 +- hrprofile/info.xml | 7 +- hrqual/info.xml | 7 +- hrrecruitment/info.xml | 7 +- hrreport/info.xml | 7 +- hrstaffdir/info.xml | 7 +- hrui/info.xml | 7 +- hrvisa/info.xml | 3 +- org.civicrm.bootstrapcivihr/info.xml | 10 +-- org.civicrm.hremergency/info.xml | 14 +-- org.civicrm.reqangular/info.xml | 11 ++- uk.co.compucorp.civicrm.hrcomments/info.xml | 6 +- .../info.xml | 6 +- uk.co.compucorp.civicrm.hrcore/info.xml | 6 +- .../templates/CRM/HRCore/UserMenuMarkup.tpl | 2 +- uk.co.compucorp.civicrm.hremails/info.xml | 6 +- .../HRLeaveAndAbsences/BAO/LeaveRequest.php | 84 +++++++++++++---- .../CRM/HRLeaveAndAbsences/Upgrader.php | 3 +- .../HRLeaveAndAbsences/Upgrader/Step/1023.php | 27 ++++++ .../info.xml | 6 +- .../Form/ManageEntitlements.tpl | 14 +-- .../HRLeaveAndAbsences/Page/AbsencePeriod.tpl | 2 +- .../HRLeaveAndAbsences/Page/AbsenceType.tpl | 2 +- .../HRLeaveAndAbsences/Page/PublicHoliday.tpl | 2 +- .../HRLeaveAndAbsences/Page/WorkPattern.tpl | 4 +- .../BAO/LeaveRequestTest.php | 89 ++++++++++++++++++- .../tests/phpunit/api/v3/LeaveRequestTest.php | 9 +- .../option_groups/toil_amounts_install.xml | 12 --- uk.co.compucorp.civicrm.hrsampledata/info.xml | 6 +- 44 files changed, 311 insertions(+), 168 deletions(-) create mode 100644 uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1023.php diff --git a/bin/git-release.sh b/bin/git-release.sh index 9b008bf0ea5..8e774a84937 100755 --- a/bin/git-release.sh +++ b/bin/git-release.sh @@ -26,7 +26,8 @@ org.civicrm.reqangular \ uk.co.compucorp.civicrm.hrcore \ uk.co.compucorp.civicrm.hremails \ uk.co.compucorp.civicrm.hrleaveandabsences \ -uk.co.compucorp.civicrm.hrcomments +uk.co.compucorp.civicrm.hrcomments \ +uk.co.compucorp.civicrm.hrcontactactionsmenu ) set -e diff --git a/com.civicrm.hrjobroles/info.xml b/com.civicrm.hrjobroles/info.xml index fb09ae3447f..3f08b059f5a 100644 --- a/com.civicrm.hrjobroles/info.xml +++ b/com.civicrm.hrjobroles/info.xml @@ -5,16 +5,15 @@ Job Roles implementation for CiviHR AGPL-3.0 - gregmeszaros - meszaros275@gmail.com + Compucorp Ltd + info@compucorp.co.uk - 2018-02-26 - 1.7.4 - alpha + 2018-03-26 + 1.7.5 + stable 4.7 - This is a new, undeveloped module CRM/Hrjobroles diff --git a/contactaccessrights/info.xml b/contactaccessrights/info.xml index 1b615f87fbd..bcf188ba4ee 100644 --- a/contactaccessrights/info.xml +++ b/contactaccessrights/info.xml @@ -5,16 +5,15 @@ This extension allows setting up access rights for contacts. AGPL-3.0 - Robin Mitra - robinmitra1@gmail.com + Compucorp Ltd + info@compucorp.co.uk - 2018-02-26 - 1.7.4 - alpha + 2018-03-26 + 1.7.5 + stable 4.7 - This is a new, undeveloped module CRM/Contactaccessrights diff --git a/contactsummary/css/contactsummary.css b/contactsummary/css/contactsummary.css index 7955d5ba3db..8ff08c076f6 100644 --- a/contactsummary/css/contactsummary.css +++ b/contactsummary/css/contactsummary.css @@ -1 +1 @@ -#bootstrap-theme .leave-widget h4{color:#4D4D69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px}#bootstrap-theme .leave-widget__types>table,#bootstrap-theme .leave-widget__sickness>table,#bootstrap-theme .leave-widget__next-leave>table{border:none}#bootstrap-theme .leave-widget__types>table thead tr th,#bootstrap-theme .leave-widget__sickness>table thead tr th,#bootstrap-theme .leave-widget__next-leave>table thead tr th{color:#4D4D69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px;background:none;width:35%}#bootstrap-theme .leave-widget__types>table thead tr th:first-child,#bootstrap-theme .leave-widget__sickness>table thead tr th:first-child,#bootstrap-theme .leave-widget__next-leave>table thead tr th:first-child{width:65%}#bootstrap-theme .leave-widget__types>table tbody tr td,#bootstrap-theme .leave-widget__sickness>table tbody tr td,#bootstrap-theme .leave-widget__next-leave>table tbody tr td{color:#0071BD;font-size:16px;font-weight:600;padding-bottom:9px}#bootstrap-theme .leave-widget__types>table tbody tr td:first-child,#bootstrap-theme .leave-widget__sickness>table tbody tr td:first-child,#bootstrap-theme .leave-widget__next-leave>table tbody tr td:first-child{color:#464354}#bootstrap-theme .leave-widget hr{border-color:#DEE4ED;margin-bottom:25px;margin-top:25px}#bootstrap-theme .leave-widget__sickness h4{margin-top:18px}#bootstrap-theme .leave-widget__next-leave h3{font-size:16px;margin-bottom:16px;margin-top:0}#bootstrap-theme .leave-widget__next-leave__deduction{font-size:16px;font-weight:600;color:#464354}#bootstrap-theme .date-range-calendar{font-size:13px;font-weight:normal}#bootstrap-theme .date-range-calendar__from,#bootstrap-theme .date-range-calendar__to{float:left;margin-bottom:10px}#bootstrap-theme .date-range-calendar__to::before{content:'\f178';float:left;font-size:16px;font-family:'FontAwesome';line-height:21px;margin:10px;margin-left:16px}#bootstrap-theme .date-range-calendar__day{background:#E8EEF0;border:1px solid #DEE4ED;border-radius:2px;border-top:none;display:inline-block;float:left;font-size:18px;height:40px;line-height:32px;margin-right:10px;text-align:center;width:40px}#bootstrap-theme .date-range-calendar__day::before{border-top:8px solid #0071BD;border-top-left-radius:2px;border-top-right-radius:2px;content:'';display:block;margin:-1px;width:calc(100% + 2px)}#bootstrap-theme .date-range-calendar__time{display:block}#bootstrap-theme button.info-button{background:none;border:none}#bootstrap-theme button.info-button .fa{color:#0071BD}#bootstrap-theme ul.week-heatmap{font-size:0;list-style:none;padding:0}#bootstrap-theme ul.week-heatmap li{background-color:#44CB7E;border-radius:2px;display:inline-block;font-size:16px;font-weight:600;height:40px;line-height:40px;margin-bottom:10px;margin-right:10px;text-align:center;width:40px}#bootstrap-theme ul.week-heatmap li.week-heatmap__medium{background-color:#E6AB5E}#bootstrap-theme ul.week-heatmap li.week-heatmap__high{color:#fff;background-color:#CF3458}#bootstrap-theme ul.week-heatmap li.week-heatmap__disabled{background-color:#E8EEF0;color:#464354}#contactsummary{padding:20px}#contactsummary .panel--key-dates>.panel-body{padding-bottom:0;padding-top:0}#contactsummary .panel--key-details{margin-bottom:0 !important} +#bootstrap-theme .leave-widget h4{color:#4D4D69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px}#bootstrap-theme .leave-widget__types>table,#bootstrap-theme .leave-widget__sickness>table,#bootstrap-theme .leave-widget__next-leave>table{border:none}#bootstrap-theme .leave-widget__types>table thead tr th,#bootstrap-theme .leave-widget__sickness>table thead tr th,#bootstrap-theme .leave-widget__next-leave>table thead tr th{color:#4D4D69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px;background:none;width:35%}#bootstrap-theme .leave-widget__types>table thead tr th:first-child,#bootstrap-theme .leave-widget__sickness>table thead tr th:first-child,#bootstrap-theme .leave-widget__next-leave>table thead tr th:first-child{width:65%}#bootstrap-theme .leave-widget__types>table tbody tr td,#bootstrap-theme .leave-widget__sickness>table tbody tr td,#bootstrap-theme .leave-widget__next-leave>table tbody tr td{color:#0071BD;font-size:16px;font-weight:600;padding-bottom:9px}#bootstrap-theme .leave-widget__types>table tbody tr td:first-child,#bootstrap-theme .leave-widget__sickness>table tbody tr td:first-child,#bootstrap-theme .leave-widget__next-leave>table tbody tr td:first-child{color:#464354}#bootstrap-theme .leave-widget hr{border-color:#DEE4ED;margin-bottom:25px;margin-top:25px}#bootstrap-theme .leave-widget__sickness h4{margin-top:18px}#bootstrap-theme .leave-widget__next-leave h3{font-size:16px;margin-bottom:16px;margin-top:0}#bootstrap-theme .leave-widget__next-leave__deduction{font-size:16px;font-weight:600;color:#464354}#bootstrap-theme .date-range-calendar{font-size:13px;font-weight:normal}#bootstrap-theme .date-range-calendar__from,#bootstrap-theme .date-range-calendar__to{float:left;margin-bottom:10px}#bootstrap-theme .date-range-calendar__to::before{content:'\f178';float:left;font-size:16px;font-family:'FontAwesome';line-height:21px;margin:10px;margin-left:16px}#bootstrap-theme .date-range-calendar__day{background:#E8EEF0;border:1px solid #DEE4ED;border-radius:2px;border-top:none;display:inline-block;float:left;font-size:18px;height:40px;line-height:32px;margin-right:10px;text-align:center;width:40px}#bootstrap-theme .date-range-calendar__day::before{border-top:8px solid #0071BD;border-top-left-radius:2px;border-top-right-radius:2px;content:'';display:block;margin:-1px;width:calc(100% + 2px)}#bootstrap-theme .date-range-calendar__time{display:block}#bootstrap-theme button.info-button{background:none;border:none}#bootstrap-theme button.info-button .fa{color:#0071BD}#bootstrap-theme ul.week-heatmap{font-size:0;list-style:none;padding:0}#bootstrap-theme ul.week-heatmap li{background-color:#44CB7E;border-radius:2px;display:inline-block;font-size:16px;font-weight:600;height:40px;line-height:40px;margin-bottom:10px;margin-right:10px;text-align:center;width:40px}#bootstrap-theme ul.week-heatmap li.week-heatmap__medium{background-color:#E6AB5E}#bootstrap-theme ul.week-heatmap li.week-heatmap__high{color:#fff;background-color:#CF3458}#bootstrap-theme ul.week-heatmap li.week-heatmap__disabled{background-color:#E8EEF0;color:#464354}#contactsummary .panel--key-dates>.panel-body{padding-bottom:0;padding-top:0}#contactsummary .panel--key-details{margin-bottom:0 !important} diff --git a/contactsummary/info.xml b/contactsummary/info.xml index 4e435d6526c..c520647e0ad 100644 --- a/contactsummary/info.xml +++ b/contactsummary/info.xml @@ -5,16 +5,15 @@ Custom contact summary page AGPL-3.0 - Robin Mitra - robinmitra1@gmail.com + Compucorp Ltd + info@compucorp.co.uk - 2018-02-26 - 1.7.4 - alpha + 2018-03-26 + 1.7.5 + stable 4.7 - This is a new, undeveloped module CRM/Contactsummary diff --git a/contactsummary/scss/contactsummary.scss b/contactsummary/scss/contactsummary.scss index b575ed53ace..8d86b2d9a25 100644 --- a/contactsummary/scss/contactsummary.scss +++ b/contactsummary/scss/contactsummary.scss @@ -1,16 +1,13 @@ -@import "SCSSROOT/org.civicrm.shoreditch/scss/bootstrap/overrides/variables"; -@import "SCSSROOT/org.civicrm.shoreditch/base/scss/vendor/bootstrap/variables"; +@import 'SCSSROOT/org.civicrm.shoreditch/scss/bootstrap/overrides/variables'; +@import 'SCSSROOT/org.civicrm.shoreditch/base/scss/vendor/bootstrap/variables'; #bootstrap-theme { - @import "SCSSROOT/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/leave-widget"; - @import "./components/*"; + @import 'SCSSROOT/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/leave-widget'; + @import './components/*'; } #contactsummary { - padding: 20px; - .panel--key-dates { - > .panel-body { padding-bottom: 0; padding-top: 0; diff --git a/hrbank/info.xml b/hrbank/info.xml index 0b49862ac05..728ab44bba7 100644 --- a/hrbank/info.xml +++ b/hrbank/info.xml @@ -8,13 +8,12 @@ CiviCRM LLC info@civicrm.org - 2018-02-26 - 1.7.4 - beta + 2018-03-26 + 1.7.5 + stable 4.7 - This is a new, undeveloped module CRM/HRBank diff --git a/hrcareer/info.xml b/hrcareer/info.xml index 73778891328..6e41e7ba2ff 100644 --- a/hrcareer/info.xml +++ b/hrcareer/info.xml @@ -8,13 +8,12 @@ CiviCRM LLC info@civicrm.org - 2018-02-26 - 1.7.4 - beta + 2018-03-26 + 1.7.5 + stable 4.7 - This is a new, undeveloped module CRM/HRCareer diff --git a/hrcase/info.xml b/hrcase/info.xml index 376ff4bed48..ab47c570dc6 100644 --- a/hrcase/info.xml +++ b/hrcase/info.xml @@ -8,13 +8,12 @@ CiviCRM LLC info@civicrm.org - 2018-02-26 - 1.7.4 - beta + 2018-03-26 + 1.7.5 + stable 4.7 - This is a new, undeveloped module CRM/HRCase diff --git a/hrdemog/info.xml b/hrdemog/info.xml index 5970ce2c19d..2bb05c6e9b0 100644 --- a/hrdemog/info.xml +++ b/hrdemog/info.xml @@ -8,13 +8,12 @@ CiviCRM LLC info@civicrm.org - 2018-02-26 - 1.7.4 - beta + 2018-03-26 + 1.7.5 + stable 4.7 - This is a new, undeveloped module CRM/HRDemog diff --git a/hrident/info.xml b/hrident/info.xml index 892f1a1276e..1c248c21026 100644 --- a/hrident/info.xml +++ b/hrident/info.xml @@ -10,11 +10,10 @@ 2017-08-22 1.7.0-RC - beta + stable 4.7 - This is a new, undeveloped module CRM/HRIdent diff --git a/hrim/info.xml b/hrim/info.xml index 7f1d5e1023e..8909e6cccaf 100644 --- a/hrim/info.xml +++ b/hrim/info.xml @@ -8,11 +8,10 @@ CiviCRM LLC info@civicrm.org - 2018-02-26 - 1.7.4 - beta + 2018-03-26 + 1.7.5 + stable 4.7 - This is a new, undeveloped module diff --git a/hrjobcontract/info.xml b/hrjobcontract/info.xml index 60dd01245ec..6fa1283915b 100644 --- a/hrjobcontract/info.xml +++ b/hrjobcontract/info.xml @@ -5,16 +5,15 @@ Track job positions, job roles, etc (Human Resources) AGPL-3.0 - Mateusz Cieplinski - mateusz@coldrun.pl + Compucorp Ltd + info@compucorp.co.uk - 2018-02-26 - 1.7.4 - beta + 2018-03-26 + 1.7.5 + stable 4.7 - This is a new version for Job (CiviHR) extension CRM/Hrjobcontract diff --git a/hrjobcontract/js/dist/job-contract.min.js b/hrjobcontract/js/dist/job-contract.min.js index bb7dae57586..df6dd1ccad4 100644 --- a/hrjobcontract/js/dist/job-contract.min.js +++ b/hrjobcontract/js/dist/job-contract.min.js @@ -27,7 +27,7 @@ THE SOFTWARE. // Copyright CiviCRM LLC 2013. See http://civicrm.org/licensing -define("job-contract/modules/job-contract.config",["common/angular"],function(e){"use strict";function t(e,t,n,o,r,i,a){t.debugEnabled(a.debug),o.resolveForAll({format:["DateFormat",function(e){return e.getDateFormat()}]}).when("/",{controller:"ContractListController",templateUrl:a.pathApp+"views/contractList.html",resolve:{contractList:["contractService",function(e){return e.get()}]}}).otherwise({redirectTo:"/"}),n.defaults.stripTrailingSlashes=!1,e.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",i.theme="bootstrap",r.showWeeks=!1}e.module("job-contract.config",["job-contract.constants"]).config(t),t.$inject=["$httpProvider","$logProvider","$resourceProvider","$routeProvider","uibDatepickerConfig","uiSelectConfig","settings"]}),define("job-contract/modules/job-contract.constants",["common/angular"],function(e){"use strict";e.module("job-contract.constants",[]).constant("settings",{classNamePrefix:"hrjc-",contactId:CRM.jobContractTabApp.contactId,debug:+CRM.debug,pathApp:CRM.jobContractTabApp.path,pathFile:CRM.url("civicrm/hrjobcontract/file/"),pathReport:CRM.url("civicrm/report/hrjobcontract/summary"),pathRest:CRM.url("civicrm/ajax/rest"),pathTpl:CRM.jobContractTabApp.path+"views/",CRM:{options:CRM.FieldOptions||{},defaultCurrency:CRM.jobContractTabApp.defaultCurrency,apiTsFmt:"YYYY-MM-DD HH:mm:ss",fields:CRM.jobContractTabApp.fields,maxFileSize:CRM.jobContractTabApp.maxFileSize}})}),define("job-contract/controllers/contract.controller",["common/lodash","common/moment"],function(e,t){"use strict";function n(n,o,r,i,a,c,s,l,u,d,f,v,m,p,_,h,b,y,g,j,C,$){function w(t){var n,o;return r.all([v.getOne({jobcontract_revision_id:t.details_revision_id}),m.getOne({jobcontract_revision_id:t.hour_revision_id}),h.getOne({jobcontract_revision_id:t.health_revision_id}),p.getOne({jobcontract_revision_id:t.pay_revision_id}),b.getOne({jobcontract_revision_id:t.pension_revision_id}),_.getOne({jobcontract_revision_id:t.leave_revision_id})]).then(function(t){return o={details:t[0],hour:t[1],health:t[2],pay:t[3],pension:t[4],leave:t[5]},n={contract:c.contract},e.extend(n,e.cloneDeep(c.model)),e.extend(n.details,o.details),e.extend(n.hour,o.hour),e.extend(n.health,o.health),e.extend(n.pay,o.pay),e.extend(n.pension,o.pension),D(n.leave,o.leave),n})}function S(){c.$on("updateContractView",function(){c.$broadcast("hrjc-loader-show"),f.fullDetails(c.revisionCurrent.jobcontract_id).then(function(e){A(e),c.$broadcast("hrjc-loader-hide")}).then(E)})}function D(t,n,o){o=o||"",e.each(t,function(t){e.extend(t,n?e.find(n,{leave_type:t.leave_type})||o:o)})}function R(n,o){var a,s,d,v,m,p,_,h,b=["details","hour","pay"],g={controller:"ModalContractController",appendTo:i.find("div").eq(0),templateUrl:u.pathApp+"views/modalForm.html?v=4448",windowClass:"modal-contract",size:"lg",resolve:{action:function(){return n||"view"},content:function(){return{}},entity:function(){return o?I.fetchRevisionDetails(o):{contract:c.contract,details:c.details,hour:c.hour,pay:c.pay,leave:c.leave,health:c.health,pension:c.pension}},files:function(){return o?r.all({details:y.get(o.details_revision_id,"civicrm_hrjobcontract_details"),pension:y.get(o.pension_revision_id,"civicrm_hrjobcontract_pension")}):T},utils:function(){return c.utils}}};switch(c.$broadcast("hrjc-loader-show"),n){case"edit":g.resolve.content=function(){return{allowSave:!0,isDisabled:!1,copy:{close:"Cancel",save:"Save without making a new revision",title:"Edit contract"}}};break;case"change":g.resolve.content=function(){return{allowSave:!0,isDisabled:!1,copy:{close:"Cancel",save:"Save and make a new revision",title:"Change contract terms"}}}}a=l.open(g),a.result.then(function(n){n&&(f.updateHeaderInfo(),A(n),L(n.details.period_end_date),n.revisionCreated?(s=t(new Date(n.revisionCreated.effective_date)),d=t(new Date(c.revisionCurrent.effective_date)),v=t(),m={revisionEntityIdObj:n.revisionCreated,details:n.details,hour:n.hour,pay:n.pay},p=d.diff(v,"day")<=0||d.diff(s,"day")<=0,n.files&&(p?E().then(function(e){m.files=e}):r.all({details:y.get(n.revisionCreated.details_revision_id,"civicrm_hrjobcontract_details")}).then(function(e){m.files=e})),c.revisionList.unshift(n.revisionCreated),c.revisionDataList.unshift(m)):(c.contract.is_primary!==n.contract.is_primary&&c.$parent.$parent.toggleIsPrimary(c.contract.id),e.each(c.revisionDataList,function(t){for(_=0,h={};b[_];)t.revisionEntityIdObj[b[_]+"_revision_id"]===c.revisionCurrent[b[_]+"_revision_id"]&&(h[b[_]]=n[b[_]],"details"===b[_]&&n.files&&E().then(function(n){h.files=n,e.extend(t,h)}),e.extend(t,h)),_++})),CRM.refreshParent("#hrjobroles"),n.haveEntitlementFieldsChanged?$.updateEntitlements(c.contract.contact_id):C.success("Success","Contract successfully updated"))})}function P(e){var t,o=[],a="leave"!==e?"getOne":"get",s=0,f=c.revisionList.length;if(c.$broadcast("hrjc-loader-show"),!e)return null;for(s;s

Change Contract Terms:
When an employeees job or role changes, i.e. promotion, secondment or move,you can use this wizard to update the details of the contract and record a newrevision of the contract. A contract history is kept so you can always see theprevious version of the contract.

Correct an error on the contract record:
If you notice an issue or error with the job terms you can correct these withoutcreating a new job history record. These changes are not stored as a new revisionof the contract.

')},c.utils={contractListLen:u.length},c.delete=j,c.modalContract=C,c.toggleIsPrimary=$,function(){for(w in R)S[w]=R[w].getFields();o.all(S).then(function(e){c.fields=e,n.debug("FIELDS:"),n.debug(e);for(w in R)D[w]=R[w].model(e[w]);return o.all(D)}).then(function(o){c.model=o,n.debug("MODEL:"),n.debug(o),u=t("orderBy")(u,"-is_primary"),e.forEach(u,function(e){+e.is_current?c.contractCurrent.push(e):c.contractPast.push(e)}),c.$watchCollection("contractCurrent",function(){c.utils.contractListLen=c.contractCurrent.length+c.contractPast.length}),c.$watchCollection("contractPast",function(){c.utils.contractListLen=c.contractCurrent.length+c.contractPast.length}),i.$broadcast("hrjc-loader-hide"),c.contractListLoaded=!0}),o.all(P).then(function(t){e.extend(c.utils,t)})}()}return n.__name="ContractListController",n.$inject=["$filter","$log","$q","$rootElement","$rootScope","$sce","$scope","$window","$uibModal","contractList","contractService","contractDetailsService","contractHourService","contractPayService","contractLeaveService","contractHealthService","contractPensionService","utilsService","settings","pubSub"],n}),define("job-contract/controllers/revision-list.controller",["common/angular","common/lodash"],function(e,t){"use strict";function n(t,n,o,r,i,a,c,s,l,u,d,f,v,m,p){function _(){var e=(a.currentPage-1)*a.itemsPerPage,t=e+a.itemsPerPage;a.revisionDataListPage=$.slice(e,t)}function h(e,t){if(1===a.revisionList.length)return void t.stopPropagation();if(e&&"number"==typeof+e){c.open({appendTo:r.find("div").eq(0),templateUrl:s.pathApp+"views/modalDialog.html",size:"sm",controller:"ModalDialogController",resolve:{content:function(){return{msg:"Are you sure you want to delete this job contract revision?"}}}}).result.then(function(t){t&&(a.$broadcast("hrjc-loader-show"),l.deleteRevision(e).then(function(t){var n=0,o=a.revisionList.length;if(!t.is_error){for(n;nt&&g(),a.sortBy(),a.createPage()})}function y(e){var t=e.effective_date,n=e.change_reason;c.open({appendTo:r.find("div").eq(0),templateUrl:s.pathApp+"views/modalChangeReason.html?v="+(new Date).getTime(),controller:"ModalChangeReasonController",resolve:{content:function(){return{copy:{title:"Edit revision data"}}},date:function(){return t},reasonId:function(){return n}}}).result.then(function(o){o.date===t&&o.reasonId===n||l.saveRevision({id:e.id,change_reason:o.reasonId,effective_date:o.date}).then(function(){e.effective_date=o.date,e.change_reason=o.reasonId,a.sortBy(),a.createPage(),a.revisionCurrent.id!==g()&&a.$emit("updateContractView")})})}function g(){var n,o=0;if(a.revisionList.length){var r=t("orderBy")(a.revisionList,["effective_date","id"]);if(e.forEach(r,function(e){new Date(e.effective_date).setHours(0,0,0,0)<=(new Date).setHours(0,0,0,0)&&(n=e)}),!n)do{n=r[o],o++}while(r[o]&&r[o-1].effective_date===r[o].effective_date);return e.extend(a.revisionCurrent,n),n.id}return null}function j(e,n){void 0!==e&&(a.sortCol===e?a.sortReverse=!a.sortReverse:a.sortCol=e),void 0!==n&&(a.sortReverse=n),$=t("orderBy")(a.revisionDataList,a.sortCol,a.sortReverse)}n.debug("Controller: RevisionListController");var C=a.contract.id,$=a.revisionDataList;a.changeReasons=i.options.contract.change_reason,a.currentPage=1,a.itemsPerPage=5,a.maxSize=5,a.sortCol="revisionEntityIdObj.effective_date",a.sortReverse=!0,a.urlCSV=function(){var t=s.pathReport+(s.pathReport.indexOf("?")>-1?"&":"?"),n=a.fields;return e.forEach(n,function(n,o){t+="fields["+o+"_revision_id]=1&",e.forEach(n,function(e){t+="fields["+o+"_"+e.name+"]=1&"})}),t+="fields[sort_name]=1&fields[first_name]=1&fields[last_name]=1&fields[external_identifier]=1&fields[email]=1&fields[street_address]=1&fields[city]=1&fields[name]=1&fields[contract_contact_id]=1&fields[contract_contract_id]=1&fields[jobcontract_revision_id]=1&fields[change_reason]=1&fields[created_date]=1&fields[effective_date]=1&fields[modified_date]=1&order_bys[1][column]=id&order_bys[1][order]=ASC&order_bys[2][column]=civicrm_hrjobcontract_revision_revision_id&order_bys[2][order]=ASC&order_bys[3][column]=-&order_bys[3][order]=ASC&order_bys[4][column]=-&order_bys[4][order]=ASC&order_bys[5][column]=-&order_bys[5][order]=ASC&contract_id_op=eq&permission=access+CiviReport&row_count=&_qf_Summary_submit_csv=Preview+CSV&groups=&contract_id_value="+C+"&group_bys[civicrm_hrjobcontract_revision_revision_id]=1"}(),a.display={effectiveDate:!0,position:!0,payScale:!0,totalSalary:!0,hours:!0,placeOfWork:!0,recordedBy:!0,changeReason:!0},a.createPage=_,a.deleteRevision=h,a.modalRevisionEdit=y,a.sortBy=j,function(){b(),a.revisionDataList||(a.$broadcast("hrjc-loader-show"),p.fetchRevisions(C).then(function(e){a.revisionList=e.revisionList,a.revisionDataList=e.revisionDataList,a.$broadcast("hrjc-loader-hide")}))}()}return n.__name="RevisionListController",n.$inject=["$filter","$log","$q","$rootElement","$rootScope","$scope","$uibModal","settings","contractService","contractDetailsService","contractHourService","contractPayService","contractFilesService","contractRevisionService","contractRevisionListService"],n}),define("job-contract/controllers/form/form-general.controller",["common/moment"],function(e){"use strict";function t(t,n,o){function r(e,t){e.preventDefault(),e.stopPropagation(),n[t]=!0}function i(t,n){if(!t||!n)return null;var o,r,i,a;return i=e(n),i.add(1,"days"),a=i.diff(t,"years"),i.add(-a,"years"),r=i.diff(t,"months"),i.add(-r,"months"),o=i.diff(t,"days"),a=a>0?a>1?a+" years ":a+" year ":"",r=r>0?r>1?r+" months ":r+" month ":"",o=o>0?o>1?o+" days":o+" day":"",a+r+o||"0 days"}function a(t,n){return n=n||"min",e(t)["max"===n?"subtract":"add"](1,"day").toDate()}function c(){n.$watch("entity.details.period_start_date",function(){n.datepickerOptions.end.minDate=a(s.period_start_date,"min"),n.duration=i(s.period_start_date,s.period_end_date)}),n.$watch("entity.details.period_end_date",function(){s.period_end_date?n.datepickerOptions.start.maxDate=a(s.period_end_date,"max"):(n.datepickerOptions.start.maxDate=null,s.end_reason=null),n.duration=i(s.period_start_date,s.period_end_date)}),n.$watch("entity.details.position",function(e,t){e!==t&&s.title===t&&(n.contractForm.detailsTitle.$setViewValue(e),n.contractForm.detailsTitle.$render())}),n.$watch("entity.details.notice_amount",function(e,t){+e&&!s.notice_unit&&(n.contractForm.detailsNoticeUnit.$setValidity("required",!1),n.contractForm.detailsNoticeUnit.$dirty=!0),e!==t&&s.notice_amount_employee===t&&(s.notice_amount_employee=e)}),n.$watch("entity.details.notice_amount_employee",function(e){+e&&!s.notice_unit_employee&&(n.contractForm.detailsNoticeUnitEmployee.$setValidity("required",!1),n.contractForm.detailsNoticeUnitEmployee.$dirty=!0)}),n.$watch("entity.details.notice_unit",function(e,t){e!==t&&s.notice_unit_employee===t&&(s.notice_unit_employee=e)})}t.debug("Controller: FormGeneralController");var s=n.entity.details;n.format=o.DATE_FORMAT,n.datepickerOptions=function(){return{start:{maxDate:s.period_end_date?a(s.period_end_date,"max"):null},end:{minDate:s.period_start_date?a(s.period_start_date,"min"):null}}}(),n.dpOpen=r,function(){c()}()}return t.__name="FormGeneralController",t.$inject=["$log","$scope","HR_settings"],t}),define("job-contract/controllers/form/form-health.controller",[],function(){"use strict";function e(e,t,n){function o(e,o){e&&n.search(e,{contact_type:"Organization",contact_sub_type:o}).then(function(e){t.contacts[o]=e})}e.debug("Controller: FormHealthController"),t.contacts={Health_Insurance_Provider:[],Life_Insurance_Provider:[]},t.refreshContacts=o,function(){t.entity.health.provider&&n.getOne(t.entity.health.provider).then(function(e){t.contacts.Health_Insurance_Provider.push(e)}),t.entity.health.provider_life_insurance&&n.getOne(t.entity.health.provider_life_insurance).then(function(e){t.contacts.Life_Insurance_Provider.push(e)})}()}return e.__name="FormHealthController",e.$inject=["$log","$scope","contactService"],e}),define("job-contract/vendor/fraction",[],function(){var e=function(t,n){if(void 0!==t&&n)"number"==typeof t&&"number"==typeof n?(this.numerator=t,this.denominator=n):"string"==typeof t&&"string"==typeof n&&(this.numerator=parseInt(t),this.denominator=parseInt(n));else if(void 0===n)if(num=t,"number"==typeof num)this.numerator=num,this.denominator=1;else if("string"==typeof num){var o,r,i=num.split(" ");if(i[0]&&(o=i[0]),i[1]&&(r=i[1]),o%1==0&&r&&r.match("/"))return new e(o).add(new e(r));if(!o||r)return;if("string"==typeof o&&o.match("/")){var a=o.split("/");this.numerator=a[0],this.denominator=a[1]}else{if("string"==typeof o&&o.match("."))return new e(parseFloat(o));this.numerator=parseInt(o),this.denominator=1}}this.normalize()};return e.prototype.clone=function(){return new e(this.numerator,this.denominator)},e.prototype.toString=function(){if("NaN"===this.denominator)return"NaN";var e=this.numerator/this.denominator>0?Math.floor(this.numerator/this.denominator):Math.ceil(this.numerator/this.denominator),t=this.numerator%this.denominator,n=this.denominator,o=[];return 0!=e&&o.push(e),0!=t&&o.push((0===e?t:Math.abs(t))+"/"+n),o.length>0?o.join(" "):0},e.prototype.rescale=function(e){return this.numerator*=e,this.denominator*=e,this},e.prototype.add=function(t){var n=this.clone();return t=t instanceof e?t.clone():new e(t),td=n.denominator,n.rescale(t.denominator),t.rescale(td),n.numerator+=t.numerator,n.normalize()},e.prototype.subtract=function(t){var n=this.clone();return t=t instanceof e?t.clone():new e(t),td=n.denominator,n.rescale(t.denominator),t.rescale(td),n.numerator-=t.numerator,n.normalize()},e.prototype.multiply=function(t){var n=this.clone();if(t instanceof e)n.numerator*=t.numerator,n.denominator*=t.denominator;else{if("number"!=typeof t)return n.multiply(new e(t));n.numerator*=t}return n.normalize()},e.prototype.divide=function(t){var n=this.clone();if(t instanceof e)n.numerator*=t.denominator,n.denominator*=t.numerator;else{if("number"!=typeof t)return n.divide(new e(t));n.denominator*=t}return n.normalize()},e.prototype.equals=function(t){t instanceof e||(t=new e(t));var n=this.clone().normalize(),t=t.clone().normalize();return n.numerator===t.numerator&&n.denominator===t.denominator},e.prototype.normalize=function(){var t=function(e){return"number"==typeof e&&(e>0&&e%1>0&&e%1<1||e<0&&e%-1<0&&e%-1>-1)},n=function(e,t){if(t){var n=Math.pow(10,t);return Math.round(e*n)/n}return Math.round(e)};return function(){if(t(this.denominator)){var o=n(this.denominator,9),r=Math.pow(10,o.toString().split(".")[1].length);this.denominator=Math.round(this.denominator*r),this.numerator*=r}if(t(this.numerator)){var o=n(this.numerator,9),r=Math.pow(10,o.toString().split(".")[1].length);this.numerator=Math.round(this.numerator*r),this.denominator*=r}var i=e.gcf(this.numerator,this.denominator);return this.numerator/=i,this.denominator/=i,(this.numerator<0&&this.denominator<0||this.numerator>0&&this.denominator<0)&&(this.numerator*=-1,this.denominator*=-1),this}}(),e.gcf=function(t,n){var o=[],r=e.primeFactors(t),i=e.primeFactors(n);return r.forEach(function(e){var t=i.indexOf(e);t>=0&&(o.push(e),i.splice(t,1))}),0===o.length?1:function(){var e,t=o[0];for(e=1;eTHE FILE IS TOO LARGE AND CANNOT BE UPLOADED. PLEASE REDUCE THE SIZE OF THE FILE AND TRY AGAIN.

"),fte:c.trustAsHtml("
FTE stands forFull Time Equivalent. This is a useful measure foran organisation that has peopleworking part-time.For a full-time person, FTE is always equal to1.0, whereas for a part-time person, the FTE will representthe fraction of standard hours that the person works on aregular basis.
E.g. if the standard working day at an organisationcomprises of 8 hours, then a person who regularly works for8 hours each day would be considered to be full- time andwould have an FTE value of 1.0. A person who regularly worksfor only 4 hours each day would be considered to be apart-time person and would have an FTE value of 0.5. If theorganisation had 10 people, each with an FTE of 1.0 theactual headcount of full-time people would be 10 and theFTE headcount (equal to actual headcount multiplied by theFTE value) would also be 10. However, if the organisationhad another 10 people who each worked part-time with an FTEvalue of 0.5 the actual headcount of part-time people wouldbe 10 while the FTE headcount would only be 5. Thus for anorganisation that had a total of 10 full-time people, and 10part-time people (each with an FTE of 0.5) the actualheadcount for the organisation would be 20 while the FTEheadcount would be 15.
")},s.uploader={details:{contract_file:y.uploader("civicrm_hrjobcontract_details")},pension:{evidence_file:y.uploader("civicrm_hrjobcontract_pension",1)}},s.cancel=S,s.filesValidate=D,s.save=M,function(){e.copy(g,s.entity),s.entity.contract={is_primary:0},e.forEach(s.uploader,function(t){e.forEach(t,function(e){e.onAfterAddingAll=function(){s.filesValidate()}})}),A(),a.$broadcast("hrjc-loader-show"),P().then(function(){a.$broadcast("hrjc-loader-hide")})}()}return o.__name="ModalContractNewController",o.$inject=["$log","$q","$rootElement","$rootScope","$sce","$scope","$uibModalInstance","$uibModal","Contract","contractService","contractDetailsService","contractHourService","contractPayService","contractLeaveService","contractHealthService","contractPensionService","contractFilesService","model","utilsService","utils","settings","pubSub"],o}),define("job-contract/controllers/modal/modal-contract.controller",["common/angular","common/lodash","common/moment"],function(e,t,n){"use strict";function o(o,r,i,a,c,s,l,u,d,f,v,m,p,_,h,b,y,g,j,C,$,w,S,D,R){function P(){if("view"===y||e.equals(g,o.entity)&&e.equals(C,o.files)&&!o.uploader.details.contract_file.queue.length&&!o.uploader.pension.evidence_file.queue.length)return o.$broadcast("hrjc-loader-hide"),void i.dismiss("cancel");S.debug&&e.forEach(g,function(t,n){e.equals(t,o.entity[n])||(D.debug("======================"),D.debug("Changed entity: "+n),D.debug("Before:"),D.debug(t),D.debug("After:"),D.debug(o.entity[n]))}),r.open({appendTo:c.find("div").eq(0),templateUrl:S.pathApp+"views/modalDialog.html?v="+(new Date).getTime(),size:"sm",controller:"ModalDialogController",resolve:{content:function(){return{copyCancel:"No",title:"Alert",msg:"Are you sure you want to cancel? Changes will be lost!"}}}}).result.then(function(e){e&&(o.$broadcast("hrjc-loader-hide"),i.dismiss("cancel"))})}function M(){return r.open({appendTo:c.find("div").eq(0),templateUrl:S.pathApp+"views/modalChangeReason.html?v="+(new Date).getTime(),controller:"ModalChangeReasonController",resolve:{content:function(){return{copy:{title:Y.title}}},date:null,reasonId:null}}).result}function A(){var t=x("period_end_date"),n=x("period_start_date"),r=!e.equals(o.entity.leave,g.leave);return n||t||r}function L(){return r.open({appendTo:c.find("div").eq(0),templateUrl:S.pathApp+"views/modalConfirmEdit.html?v="+(new Date).getTime(),controller:"ModalDialogController",resolve:{content:function(){return{msg:"Save without making a new revision?"}}}}).result}function E(e,t){return o.$broadcast("hrjc-loader-show"),d.validateEffectiveDate({contact_id:S.contactId,effective_date:t}).then(function(n){if(n.success)return N(e,t);CRM.alert(n.message,"Error","error"),o.$broadcast("hrjc-loader-hide")},function(e){})}function T(){o.$broadcast("hrjc-loader-show"),o.entity.details.period_end_date=o.entity.details.period_end_date||"";var t,n,s,l,d,y=e.copy(o.entity),g=o.filesTrash,j=o.uploader,C={contract:u.save(y.contract),details:f.save(y.details),hour:v.save(y.hour),pay:m.save(y.pay),leave:p.save(y.leave),health:_.save(y.health),pension:h.save(y.pension)},$=[],w=[];for(t in g)for(s=0,l=g[t].length,s;so.fileMaxSize&&e.remove()})})}),j.details.contract_file.queue.length&&$.push(b.upload(j.details.contract_file,y.details.jobcontract_revision_id)),j.pension.evidence_file.queue.length&&$.push(b.upload(j.pension.evidence_file,y.pension.jobcontract_revision_id)),t.details.period_start_date=y.details.period_start_date,t.details.period_end_date=y.details.period_end_date,t.pay.annual_benefits=y.pay.annual_benefits,t.pay.annual_deductions=y.pay.annual_deductions,$.length?(d=r.open({appendTo:c.find("div").eq(0),templateUrl:S.pathApp+"views/modalProgress.html?v="+(new Date).getTime(),size:"sm",controller:"ModalProgressController",resolve:{uploader:function(){return j},promiseFilesUpload:function(){return $}}}),t.files=d.result,a.all(t)):(t.haveEntitlementFieldsChanged=A(),t)}).then(function(e){o.$broadcast("hrjc-loader-hide"),i.close(e),R.publish("Contract::updated")},function(e){o.$broadcast("hrjc-loader-hide"),CRM.alert(e,"Error","error")})}function F(e){var t=l("formatDate")(e,Date);return"Unspecified"!==t?t:e}function I(){return a.all([{name:"hrjobcontract_health_health_plan_type",key:"plan_type"},{name:"hrjobcontract_health_life_insurance_plan_type",key:"plan_type_life_insurance"}].map(function(e){_.getOptions(e.name,!0).then(function(n){s.options.health[e.key]=t.transform(n,function(e,t){e[t.key]=t.value},{})})}))}function U(e,t){var n=o.files[t];o.filesTrash[t].push(n[e]),n.splice(e,1)}function q(){var e=t.every(o.uploader,function(e){return t.every(e,function(e){return!e.queue||t.every(e.queue,function(e){return e.file.sizeo.fileMaxSize&&e.remove()}),F.queue.length&&P.push(b.upload(F,l))}),P.length?(s=r.open({appendTo:c.find("div").eq(0),templateUrl:S.pathApp+"views/modalProgress.html",size:"sm",controller:"ModalProgressController",resolve:{uploader:function(){return C},promiseFilesUpload:function(){return P}}}),e.files=s.result,a.all(e)):(e.haveEntitlementFieldsChanged=A(),e)}).then(function(e){o.$broadcast("hrjc-loader-hide"),i.close(e),R.publish("Contract::updated")})):(o.$broadcast("hrjc-loader-hide"),i.close())}D.debug("Controller: ModalContractController");var Y=j.copy||{};Y.close=Y.close||"Close",Y.save=Y.save||"Save changes",Y.title=Y.title||"Contract",o.action=y||"view",o.allowSave=void 0!==j.allowSave&&j.allowSave,o.copy=Y,o.entity={},o.fileMaxSize=S.CRM.maxFileSize||0,o.files={},o.filesTrash={},o.isDisabled=void 0===j.isDisabled||j.isDisabled,o.isPrimaryDisabled=+g.contract.is_primary,o.showIsPrimary=w.contractListLen>1&&"change"!==y,o.uploader={details:{contract_file:b.uploader("civicrm_hrjobcontract_details")},pension:{evidence_file:b.uploader("civicrm_hrjobcontract_pension",1)}},o.utils=w,o.cancel=P,o.fileMoveToTrash=U,o.filesValidate=q,o.save=z,function(){O(),H(),i.opened.then(function(){s.$broadcast("hrjc-loader-hide")}),s.$broadcast("hrjc-loader-show"),I().then(function(){s.$broadcast("hrjc-loader-hide")})}()}return o.__name="ModalContractController",o.$inject=["$scope","$uibModal","$uibModalInstance","$q","$rootElement","$rootScope","$filter","contractService","contractRevisionService","contractDetailsService","contractHourService","contractPayService","contractLeaveService","contractHealthService","contractPensionService","contractFilesService","action","entity","content","files","utilsService","utils","settings","$log","pubSub"],o}),define("job-contract/controllers/modal/modal-dialog.controller",[],function(){"use strict";function e(e,t,n,o,r){function i(){o.dismiss("Cancel")}function a(e){o.close(e||!0)}e.debug("Controller: ModalDialogController"),t.copyCancel=r.copyCancel||"Cancel",t.copyConfirm=r.copyConfirm||"Yes",t.msg=r.msg||"",t.title=r.title||"CiviHR Job Contract",t.cancel=i,t.confirm=a}return e.__name="ModalDialogController",e.$inject=["$log","$scope","$timeout","$uibModalInstance","content"],e}),define("job-contract/controllers/modal/modal-progress.controller",[],function(){"use strict";function e(e,t,n,o,r,i,a){function c(){r.dismiss("File upload canceled")}e.debug("Controller: ModalProgressController");var s,l;n.uploader=i,n.cancel=c,function(){for(s in i)for(l in i[s])i[s][l].queue.length&&(i[s][l].item=i[s][l].queue[0].file.name),i[s][l].onProgressItem=function(e){this.item=e.file.name};t.all(a).then(function(e){o(function(){r.close(e)},500)})}()}return e.__name="ModalProgressController",e.$inject=["$log","$q","$scope","$timeout","$uibModalInstance","uploader","promiseFilesUpload"],e}),define("job-contract/controllers/modal/modal-revision.controller",["common/angular"],function(e){"use strict";function t(t,n,o,r,i,a,c,s,l,u,d,f,v,m,p){function _(){a.dismiss("cancel")}function h(){var e=(i.currentPage-1)*i.itemsPerPage,t=e+i.itemsPerPage;i.revisionDataListPage=i.revisionDataList.slice(e,t)}function b(){var e,t=0,n=i.fields.length;for(t;t-1?"&":"?"),r=i.entity;return e.forEach(i.fields,function(e){t="editor_name"!==e.name?e.name:"editor_uid",n=e.extends?"":r+"_",e.selected&&(o+="fields["+n+t+"]=1&")}),o+="fields[sort_name]=1&fields[first_name]=1&fields[last_name]=1&fields[external_identifier]=1&fields[email]=1&fields[street_address]=1&fields[city]=1&fields[name]=1&fields[contract_contact_id]=1&fields[contract_contract_id]=1&fields[jobcontract_revision_id]=1&fields[change_reason]=1&fields[created_date]=1&fields[effective_date]=1&fields[modified_date]=1&order_bys[1][column]=id&order_bys[1][order]=ASC&order_bys[2][column]=civicrm_hrjobcontract_revision_revision_id&order_bys[2][order]=ASC&order_bys[3][column]=-&order_bys[3][order]=ASC&order_bys[4][column]=-&order_bys[4][order]=ASC&order_bys[5][column]=-&order_bys[5][order]=ASC&contract_id_op=eq&permission=access+CiviReport&row_count=&_qf_Summary_submit_csv=Preview+CSV&groups=&contract_id_value="+l[0].jobcontract_id+"&group_bys[civicrm_hrjobcontract_revision_revision_id]=1"}n.debug("Controller: ModalRevisionController"),i.$broadcast("hrjc-loader-show"),i.currentPage=1,i.entity=u,i.fields=e.copy(d),i.itemsPerPage=5,i.revisionDataList=[],i.revisionList=[],i.sortCol="effective_date",i.subFields={},i.maxSize=5,i.modalContract=v,i.sortReverse=!0,i.urlCSV=w(),i.cancel=_,i.createPage=h,i.sortBy=C,i.toggleFieldsSelected=$,function(){b(),y(),g(),j(),i.sortBy(),a.opened.then(function(){r.$broadcast("hrjc-loader-hide")})}()}return t.__name="ModalRevisionController",t.$inject=["$filter","$log","$q","$rootScope","$scope","$uibModalInstance","settings","revisionDataList","revisionList","entity","fields","model","modalContract","utils","contactService"],t}),define("job-contract/modules/job-contract.controllers",["common/angular","job-contract/controllers/contract.controller","job-contract/controllers/contract-list.controller","job-contract/controllers/revision-list.controller","job-contract/controllers/form/form-general.controller","job-contract/controllers/form/form-health.controller","job-contract/controllers/form/form-hour.controller","job-contract/controllers/form/form-leave.controller","job-contract/controllers/form/form-pay.controller","job-contract/controllers/form/form-pension.controller","job-contract/controllers/modal/modal-change-reason.controller","job-contract/controllers/modal/modal-contract-new.controller","job-contract/controllers/modal/modal-contract.controller","job-contract/controllers/modal/modal-dialog.controller","job-contract/controllers/modal/modal-progress.controller","job-contract/controllers/modal/modal-revision.controller"],function(e,t,n,o,r,i,a,c,s,l,u,d,f,v,m,p){"use strict";return e.module("job-contract.controllers",[]).controller(t.__name,t).controller(n.__name,n).controller(o.__name,o).controller(r.__name,r).controller(i.__name,i).controller(a.__name,a).controller(c.__name,c).controller(s.__name,s).controller(l.__name,l).controller(u.__name,u).controller(d.__name,d).controller(f.__name,f).controller(v.__name,v).controller(m.__name,m).controller(p.__name,p)}),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,o,r){return n.debug("AbsenceTypeAPI"),o.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(o,i,a){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),a=e.assign({},a,{absence_type_id:o,date:t(i).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",a).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,o,r,i,a){return t.debug("AbsenceType"),o.extend({all:function(e){return i.all(e).then(function(e){return e.map(function(e){return a.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return i.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return i.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,o){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=o.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,o,r,i){return e.debug("AbsencePeriod"),n.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(i.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return o.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),function(e,t){function n(){var e={nodiff:"",year:"year",years:"years",month:"month",months:"months",day:"day",days:"days",hour:"hour",hours:"hours",minute:"minute",minutes:"minutes",second:"second",seconds:"seconds",delimiter:" "};moment.fn.preciseDiff=function(e){return moment.preciseDiff(this,e)},moment.preciseDiff=function(t,n){function o(t,n){return t+" "+e[n+(1===t?"":"s")]}var r=moment(t),i=moment(n);if(r.isSame(i))return e.nodiff;if(r.isAfter(i)){var a=r;r=i,i=a}var c=i.year()-r.year(),s=i.month()-r.month(),l=i.date()-r.date();if(l<0){var u=moment(i.year()+"-"+(i.month()+1),"YYYY-MM").subtract("months",1).daysInMonth();l=u
Length Of Employment
"),e(".lengthEmployment").html(a),o&&l<0&&e(".lengthEmployment").css({color:"#FF0000"})}var r=CRM.grID,i=e("#custom-set-content-"+r+" .crm-inline-block-content div:nth-child(2) .crm-custom-data").html(),a=e("#custom-set-content-"+r+" .crm-inline-block-content div:nth-child(3) .crm-custom-data").html();i&&o(i,a,r),e(document).on("click","#_qf_CustomData_upload",function(){e(document).ajaxSuccess(function(t,n,i){i.extraData&&"CRM_Contact_Form_Inline_CustomData"==i.extraData.class_name&&i.extraData.groupID==r&&setTimeout(function(){var t=e("#custom-set-content-"+r+" .crm-inline-block-content div:nth-child(2) .crm-custom-data").html(),n=e("#custom-set-content-"+r+" .crm-inline-block-content div:nth-child(3) .crm-custom-data").html();t&&o(t,n,r)},300)})})}(CRM.$,CRM._),define("job-contract/modules/job-contract.core",["common/angular","common/ui-select","common/directives/angular-date/date-input","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/routers/compu-ng-route","common/modules/directives","common/services/dom-event-trigger","common/services/pub-sub","common/services/angular-date/date-format","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/absence-period.model","job-contract/vendor/fraction","job-contract/vendor/job-summary"],function(e){"use strict";e.module("job-contract.core",["ngAnimate","compuNgRoute","ngResource","angularFileUpload","ui.bootstrap","ui.select","common.angularDate","common.services","common.directives","common.filters","leave-absences.models"])}),define("job-contract/directives/contact.directive",[],function(){"use strict";function e(e,t,n,o){return t.debug("Directive: hrjcContact"),{restrict:"A",scope:{renderAsLink:"=?hrjcContactLink",contactId:"=?hrjcContact"},template:"{{contact.label}}",link:function(t,n){t.contactId&&t.$watch("contactId",function(r){o.getOne(t.contactId).then(function(o){t.contact=o,t.renderAsLink&&(n.html('{{contact.label}}'),e(n.contents())(t))})})}}}return e.__name="hrjcContact",e.$inject=["$compile","$log","settings","contactService"],e}),define("job-contract/directives/loader.directive",[],function(){"use strict";function e(e,t){return e.debug("Directive: hrjcLoader"),{link:function(e,t,n){function o(){var e=window.getComputedStyle(t[0]).position;return"relative"===e||"absolute"===e||"fixed"===e}function r(){o()||(t.css("position","relative"),s=!0),t.append(a),c=!0}function i(){c&&a.parentNode.removeChild(a),c=!1,s&&t.css("position","")}var a=document.createElement("div"),c=!1,s=!1;a.className="hrjc-loader spinner",n.hrjcLoaderShow&&r(),e.$on("hrjc-loader-show",function(){r()}),e.$on("hrjc-loader-hide",function(){i()})}}}return e.__name="hrjcLoader",e.$inject=["$log","$rootScope"],e}),define("job-contract/directives/number.directive",[],function(){"use strict";function e(e){return e.debug("Directive: hrjcNumber"),{require:"ngModel",link:function(e,t,n,o){var r=2,i=n.hrjcNumberFloat||!1,a=n.hrjcToHours||!1,c=n.hrjcNotNegative||!1;n.hrjcNumber&&"number"==typeof+n.hrjcNumber&&(r=n.hrjcNumber),t.bind("blur",function(){var e=parseFloat(o.$viewValue)||0;c&&e<0&&(e=0),a&&(e=.25*Math.ceil(e/.25)),o.$setViewValue(i?Math.round(100*e)/100:e.toFixed(r)),o.$render()})}}}return e.__name="hrjcNumber",e.$inject=["$log"],e}),define("job-contract/directives/validate.directive",["common/angular"],function(e){"use strict";function t(t){return t.debug("Directive: hrjcValidate"),{restrict:"A",require:"^form",scope:{isWarning:"=?hrjcValidateWarning"},link:function(t,n,o,r){function i(e,t){n.toggleClass("has-success",!e&&!t),f.toggleClass("glyphicon-ok",!e&&!t)}function a(e,t){n.toggleClass("has-warning",!e&&t),f.toggleClass("glyphicon-warning-sign",!e&&t)}function c(e){n.toggleClass("has-error",e),f.toggleClass("glyphicon-remove",e)}var s=n[0].querySelector("[name]"),l=e.element(s),u=l.attr("name"),d=document.createElement("span"),f=e.element(d);u&&(n.addClass("has-feedback"),f.addClass("glyphicon form-control-feedback"),l.after(f),t.$watch(function(){return r[u]&&r[u].$invalid},function(e){r[u].$dirty&&(i(e,t.isWarning),c(e))}),void 0!==t.isWarning&&t.$watch("isWarning",function(e){var t=r[u].$invalid;r[u].$dirty&&(i(t,e),a(t,e))}),l.bind("blur",function(){c(r[u].$invalid)}))}}}return t.__name="hrjcValidate",t.$inject=["$log"],t}),define("job-contract/modules/job-contract.directives",["common/angular","job-contract/directives/contact.directive","job-contract/directives/loader.directive","job-contract/directives/number.directive","job-contract/directives/validate.directive"],function(e,t,n,o,r){"use strict";return e.module("job-contract.directives",[]).directive(t.__name,t).directive(n.__name,n).directive(o.__name,o).directive(r.__name,r)}),define("job-contract/filters/capitalize.filter",[],function(){"use strict";function e(e){return e.debug("Filter: capitalize"),function(e){return e?e.replace(/([^\W_]+[^\s-]*) */g,function(e){ +define("job-contract/modules/job-contract.config",["common/angular"],function(e){"use strict";function t(e,t,n,o,r,i,a){t.debugEnabled(a.debug),o.resolveForAll({format:["DateFormat",function(e){return e.getDateFormat()}]}).when("/",{controller:"ContractListController",templateUrl:a.pathApp+"views/contractList.html",resolve:{contractList:["contractService",function(e){return e.get()}]}}).otherwise({redirectTo:"/"}),n.defaults.stripTrailingSlashes=!1,e.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",i.theme="bootstrap",r.showWeeks=!1}e.module("job-contract.config",["job-contract.constants"]).config(t),t.$inject=["$httpProvider","$logProvider","$resourceProvider","$routeProvider","uibDatepickerConfig","uiSelectConfig","settings"]}),define("job-contract/modules/job-contract.constants",["common/angular"],function(e){"use strict";e.module("job-contract.constants",[]).constant("settings",{classNamePrefix:"hrjc-",contactId:CRM.jobContractTabApp.contactId,debug:+CRM.debug,pathApp:CRM.jobContractTabApp.path,pathFile:CRM.url("civicrm/hrjobcontract/file/"),pathReport:CRM.url("civicrm/report/hrjobcontract/summary"),pathRest:CRM.url("civicrm/ajax/rest"),pathTpl:CRM.jobContractTabApp.path+"views/",CRM:{options:CRM.FieldOptions||{},defaultCurrency:CRM.jobContractTabApp.defaultCurrency,apiTsFmt:"YYYY-MM-DD HH:mm:ss",fields:CRM.jobContractTabApp.fields,maxFileSize:CRM.jobContractTabApp.maxFileSize}})}),define("job-contract/controllers/contract.controller",["common/lodash","common/moment"],function(e,t){"use strict";function n(n,o,r,i,a,c,s,l,u,d,f,v,m,p,_,h,b,y,g,j,C,$){function w(t){var n,o;return r.all([v.getOne({jobcontract_revision_id:t.details_revision_id}),m.getOne({jobcontract_revision_id:t.hour_revision_id}),h.getOne({jobcontract_revision_id:t.health_revision_id}),p.getOne({jobcontract_revision_id:t.pay_revision_id}),b.getOne({jobcontract_revision_id:t.pension_revision_id}),_.getOne({jobcontract_revision_id:t.leave_revision_id})]).then(function(t){return o={details:t[0],hour:t[1],health:t[2],pay:t[3],pension:t[4],leave:t[5]},n={contract:c.contract},e.extend(n,e.cloneDeep(c.model)),e.extend(n.details,o.details),e.extend(n.hour,o.hour),e.extend(n.health,o.health),e.extend(n.pay,o.pay),e.extend(n.pension,o.pension),D(n.leave,o.leave),n})}function S(){c.$on("updateContractView",function(){c.$broadcast("hrjc-loader-show"),f.fullDetails(c.revisionCurrent.jobcontract_id).then(function(e){A(e),c.$broadcast("hrjc-loader-hide")}).then(E)})}function D(t,n,o){o=o||"",e.each(t,function(t){e.extend(t,n?e.find(n,{leave_type:t.leave_type})||o:o)})}function R(n,o){var a,s,d,v,m,p,_,h,b=["details","hour","pay"],g={controller:"ModalContractController",appendTo:i.find("div").eq(0),templateUrl:u.pathApp+"views/modalForm.html?v=4448",windowClass:"modal-contract",size:"lg",resolve:{action:function(){return n||"view"},content:function(){return{}},entity:function(){return o?I.fetchRevisionDetails(o):{contract:c.contract,details:c.details,hour:c.hour,pay:c.pay,leave:c.leave,health:c.health,pension:c.pension}},files:function(){return o?r.all({details:y.get(o.details_revision_id,"civicrm_hrjobcontract_details"),pension:y.get(o.pension_revision_id,"civicrm_hrjobcontract_pension")}):T},utils:function(){return c.utils}}};switch(c.$broadcast("hrjc-loader-show"),n){case"edit":g.resolve.content=function(){return{allowSave:!0,isDisabled:!1,copy:{close:"Cancel",save:"Save without making a new revision",title:"Edit contract"}}};break;case"change":g.resolve.content=function(){return{allowSave:!0,isDisabled:!1,copy:{close:"Cancel",save:"Save and make a new revision",title:"Change contract terms"}}}}a=l.open(g),a.result.then(function(n){n&&(f.updateHeaderInfo(),A(n),L(n.details.period_end_date),n.revisionCreated?(s=t(new Date(n.revisionCreated.effective_date)),d=t(new Date(c.revisionCurrent.effective_date)),v=t(),m={revisionEntityIdObj:n.revisionCreated,details:n.details,hour:n.hour,pay:n.pay},p=d.diff(v,"day")<=0||d.diff(s,"day")<=0,n.files&&(p?E().then(function(e){m.files=e}):r.all({details:y.get(n.revisionCreated.details_revision_id,"civicrm_hrjobcontract_details")}).then(function(e){m.files=e})),c.revisionList.unshift(n.revisionCreated),c.revisionDataList.unshift(m)):(c.contract.is_primary!==n.contract.is_primary&&c.$parent.$parent.toggleIsPrimary(c.contract.id),e.each(c.revisionDataList,function(t){for(_=0,h={};b[_];)t.revisionEntityIdObj[b[_]+"_revision_id"]===c.revisionCurrent[b[_]+"_revision_id"]&&(h[b[_]]=n[b[_]],"details"===b[_]&&n.files&&E().then(function(n){h.files=n,e.extend(t,h)}),e.extend(t,h)),_++})),CRM.refreshParent("#hrjobroles"),n.haveEntitlementFieldsChanged?$.updateEntitlements(c.contract.contact_id):C.success("Success","Contract successfully updated"))})}function P(e){var t,o=[],a="leave"!==e?"getOne":"get",s=0,f=c.revisionList.length;if(c.$broadcast("hrjc-loader-show"),!e)return null;for(s;s

Change Contract Terms:
When an employeees job or role changes, i.e. promotion, secondment or move,you can use this wizard to update the details of the contract and record a newrevision of the contract. A contract history is kept so you can always see theprevious version of the contract.

Correct an error on the contract record:
If you notice an issue or error with the job terms you can correct these withoutcreating a new job history record. These changes are not stored as a new revisionof the contract.

')},c.utils={contractListLen:u.length},c.delete=j,c.modalContract=C,c.toggleIsPrimary=$,function(){for(w in R)S[w]=R[w].getFields();o.all(S).then(function(e){c.fields=e,n.debug("FIELDS:"),n.debug(e);for(w in R)D[w]=R[w].model(e[w]);return o.all(D)}).then(function(o){c.model=o,n.debug("MODEL:"),n.debug(o),u=t("orderBy")(u,"-is_primary"),e.forEach(u,function(e){+e.is_current?c.contractCurrent.push(e):c.contractPast.push(e)}),c.$watchCollection("contractCurrent",function(){c.utils.contractListLen=c.contractCurrent.length+c.contractPast.length}),c.$watchCollection("contractPast",function(){c.utils.contractListLen=c.contractCurrent.length+c.contractPast.length}),i.$broadcast("hrjc-loader-hide"),c.contractListLoaded=!0}),o.all(P).then(function(t){e.extend(c.utils,t)})}()}return n.__name="ContractListController",n.$inject=["$filter","$log","$q","$rootElement","$rootScope","$sce","$scope","$window","$uibModal","contractList","contractService","contractDetailsService","contractHourService","contractPayService","contractLeaveService","contractHealthService","contractPensionService","utilsService","settings","pubSub"],n}),define("job-contract/controllers/revision-list.controller",["common/angular","common/lodash"],function(e,t){"use strict";function n(t,n,o,r,i,a,c,s,l,u,d,f,v,m,p){function _(){var e=(a.currentPage-1)*a.itemsPerPage,t=e+a.itemsPerPage;a.revisionDataListPage=$.slice(e,t)}function h(e,t){if(1===a.revisionList.length)return void t.stopPropagation();if(e&&"number"==typeof+e){c.open({appendTo:r.find("div").eq(0),templateUrl:s.pathApp+"views/modalDialog.html",size:"sm",controller:"ModalDialogController",resolve:{content:function(){return{msg:"Are you sure you want to delete this job contract revision?"}}}}).result.then(function(t){t&&(a.$broadcast("hrjc-loader-show"),l.deleteRevision(e).then(function(t){var n=0,o=a.revisionList.length;if(!t.is_error){for(n;nt&&g(),a.sortBy(),a.createPage()})}function y(e){var t=e.effective_date,n=e.change_reason;c.open({appendTo:r.find("div").eq(0),templateUrl:s.pathApp+"views/modalChangeReason.html?v="+(new Date).getTime(),controller:"ModalChangeReasonController",resolve:{content:function(){return{copy:{title:"Edit revision data"}}},date:function(){return t},reasonId:function(){return n}}}).result.then(function(o){o.date===t&&o.reasonId===n||l.saveRevision({id:e.id,change_reason:o.reasonId,effective_date:o.date}).then(function(){e.effective_date=o.date,e.change_reason=o.reasonId,a.sortBy(),a.createPage(),a.revisionCurrent.id!==g()&&a.$emit("updateContractView")})})}function g(){var n,o=0;if(a.revisionList.length){var r=t("orderBy")(a.revisionList,["effective_date","id"]);if(e.forEach(r,function(e){new Date(e.effective_date).setHours(0,0,0,0)<=(new Date).setHours(0,0,0,0)&&(n=e)}),!n)do{n=r[o],o++}while(r[o]&&r[o-1].effective_date===r[o].effective_date);return e.extend(a.revisionCurrent,n),n.id}return null}function j(e,n){void 0!==e&&(a.sortCol===e?a.sortReverse=!a.sortReverse:a.sortCol=e),void 0!==n&&(a.sortReverse=n),$=t("orderBy")(a.revisionDataList,a.sortCol,a.sortReverse)}n.debug("Controller: RevisionListController");var C=a.contract.id,$=a.revisionDataList;a.changeReasons=i.options.contract.change_reason,a.currentPage=1,a.itemsPerPage=5,a.maxSize=5,a.sortCol="revisionEntityIdObj.effective_date",a.sortReverse=!0,a.urlCSV=function(){var t=s.pathReport+(s.pathReport.indexOf("?")>-1?"&":"?"),n=a.fields;return e.forEach(n,function(n,o){t+="fields["+o+"_revision_id]=1&",e.forEach(n,function(e){t+="fields["+o+"_"+e.name+"]=1&"})}),t+="fields[sort_name]=1&fields[first_name]=1&fields[last_name]=1&fields[external_identifier]=1&fields[email]=1&fields[street_address]=1&fields[city]=1&fields[name]=1&fields[contract_contact_id]=1&fields[contract_contract_id]=1&fields[jobcontract_revision_id]=1&fields[change_reason]=1&fields[created_date]=1&fields[effective_date]=1&fields[modified_date]=1&order_bys[1][column]=id&order_bys[1][order]=ASC&order_bys[2][column]=civicrm_hrjobcontract_revision_revision_id&order_bys[2][order]=ASC&order_bys[3][column]=-&order_bys[3][order]=ASC&order_bys[4][column]=-&order_bys[4][order]=ASC&order_bys[5][column]=-&order_bys[5][order]=ASC&contract_id_op=eq&permission=access+CiviReport&row_count=&_qf_Summary_submit_csv=Preview+CSV&groups=&contract_id_value="+C+"&group_bys[civicrm_hrjobcontract_revision_revision_id]=1"}(),a.display={effectiveDate:!0,position:!0,payScale:!0,totalSalary:!0,hours:!0,placeOfWork:!0,recordedBy:!0,changeReason:!0},a.createPage=_,a.deleteRevision=h,a.modalRevisionEdit=y,a.sortBy=j,function(){b(),a.revisionDataList||(a.$broadcast("hrjc-loader-show"),p.fetchRevisions(C).then(function(e){a.revisionList=e.revisionList,a.revisionDataList=e.revisionDataList,a.$broadcast("hrjc-loader-hide")}))}()}return n.__name="RevisionListController",n.$inject=["$filter","$log","$q","$rootElement","$rootScope","$scope","$uibModal","settings","contractService","contractDetailsService","contractHourService","contractPayService","contractFilesService","contractRevisionService","contractRevisionListService"],n}),define("job-contract/controllers/form/form-general.controller",["common/moment"],function(e){"use strict";function t(t,n,o){function r(e,t){e.preventDefault(),e.stopPropagation(),n[t]=!0}function i(t,n){if(!t||!n)return null;var o,r,i,a;return i=e(n),i.add(1,"days"),a=i.diff(t,"years"),i.add(-a,"years"),r=i.diff(t,"months"),i.add(-r,"months"),o=i.diff(t,"days"),a=a>0?a>1?a+" years ":a+" year ":"",r=r>0?r>1?r+" months ":r+" month ":"",o=o>0?o>1?o+" days":o+" day":"",a+r+o||"0 days"}function a(t,n){return n=n||"min",e(t)["max"===n?"subtract":"add"](1,"day").toDate()}function c(){n.$watch("entity.details.period_start_date",function(){n.datepickerOptions.end.minDate=a(s.period_start_date,"min"),n.duration=i(s.period_start_date,s.period_end_date)}),n.$watch("entity.details.period_end_date",function(){s.period_end_date?n.datepickerOptions.start.maxDate=a(s.period_end_date,"max"):(n.datepickerOptions.start.maxDate=null,s.end_reason=null),n.duration=i(s.period_start_date,s.period_end_date)}),n.$watch("entity.details.position",function(e,t){e!==t&&s.title===t&&(n.contractForm.detailsTitle.$setViewValue(e),n.contractForm.detailsTitle.$render())}),n.$watch("entity.details.notice_amount",function(e,t){+e&&!s.notice_unit&&(n.contractForm.detailsNoticeUnit.$setValidity("required",!1),n.contractForm.detailsNoticeUnit.$dirty=!0),e!==t&&s.notice_amount_employee===t&&(s.notice_amount_employee=e)}),n.$watch("entity.details.notice_amount_employee",function(e){+e&&!s.notice_unit_employee&&(n.contractForm.detailsNoticeUnitEmployee.$setValidity("required",!1),n.contractForm.detailsNoticeUnitEmployee.$dirty=!0)}),n.$watch("entity.details.notice_unit",function(e,t){e!==t&&s.notice_unit_employee===t&&(s.notice_unit_employee=e)})}t.debug("Controller: FormGeneralController");var s=n.entity.details;n.format=o.DATE_FORMAT,n.datepickerOptions=function(){return{start:{maxDate:s.period_end_date?a(s.period_end_date,"max"):null},end:{minDate:s.period_start_date?a(s.period_start_date,"min"):null}}}(),n.dpOpen=r,function(){c()}()}return t.__name="FormGeneralController",t.$inject=["$log","$scope","HR_settings"],t}),define("job-contract/controllers/form/form-health.controller",[],function(){"use strict";function e(e,t,n){function o(e,o){e&&n.search(e,{contact_type:"Organization",contact_sub_type:o}).then(function(e){t.contacts[o]=e})}e.debug("Controller: FormHealthController"),t.contacts={Health_Insurance_Provider:[],Life_Insurance_Provider:[]},t.refreshContacts=o,function(){t.entity.health.provider&&n.getOne(t.entity.health.provider).then(function(e){t.contacts.Health_Insurance_Provider.push(e)}),t.entity.health.provider_life_insurance&&n.getOne(t.entity.health.provider_life_insurance).then(function(e){t.contacts.Life_Insurance_Provider.push(e)})}()}return e.__name="FormHealthController",e.$inject=["$log","$scope","contactService"],e}),define("job-contract/vendor/fraction",[],function(){var e=function(t,n){if(void 0!==t&&n)"number"==typeof t&&"number"==typeof n?(this.numerator=t,this.denominator=n):"string"==typeof t&&"string"==typeof n&&(this.numerator=parseInt(t),this.denominator=parseInt(n));else if(void 0===n)if(num=t,"number"==typeof num)this.numerator=num,this.denominator=1;else if("string"==typeof num){var o,r,i=num.split(" ");if(i[0]&&(o=i[0]),i[1]&&(r=i[1]),o%1==0&&r&&r.match("/"))return new e(o).add(new e(r));if(!o||r)return;if("string"==typeof o&&o.match("/")){var a=o.split("/");this.numerator=a[0],this.denominator=a[1]}else{if("string"==typeof o&&o.match("."))return new e(parseFloat(o));this.numerator=parseInt(o),this.denominator=1}}this.normalize()};return e.prototype.clone=function(){return new e(this.numerator,this.denominator)},e.prototype.toString=function(){if("NaN"===this.denominator)return"NaN";var e=this.numerator/this.denominator>0?Math.floor(this.numerator/this.denominator):Math.ceil(this.numerator/this.denominator),t=this.numerator%this.denominator,n=this.denominator,o=[];return 0!=e&&o.push(e),0!=t&&o.push((0===e?t:Math.abs(t))+"/"+n),o.length>0?o.join(" "):0},e.prototype.rescale=function(e){return this.numerator*=e,this.denominator*=e,this},e.prototype.add=function(t){var n=this.clone();return t=t instanceof e?t.clone():new e(t),td=n.denominator,n.rescale(t.denominator),t.rescale(td),n.numerator+=t.numerator,n.normalize()},e.prototype.subtract=function(t){var n=this.clone();return t=t instanceof e?t.clone():new e(t),td=n.denominator,n.rescale(t.denominator),t.rescale(td),n.numerator-=t.numerator,n.normalize()},e.prototype.multiply=function(t){var n=this.clone();if(t instanceof e)n.numerator*=t.numerator,n.denominator*=t.denominator;else{if("number"!=typeof t)return n.multiply(new e(t));n.numerator*=t}return n.normalize()},e.prototype.divide=function(t){var n=this.clone();if(t instanceof e)n.numerator*=t.denominator,n.denominator*=t.numerator;else{if("number"!=typeof t)return n.divide(new e(t));n.denominator*=t}return n.normalize()},e.prototype.equals=function(t){t instanceof e||(t=new e(t));var n=this.clone().normalize(),t=t.clone().normalize();return n.numerator===t.numerator&&n.denominator===t.denominator},e.prototype.normalize=function(){var t=function(e){return"number"==typeof e&&(e>0&&e%1>0&&e%1<1||e<0&&e%-1<0&&e%-1>-1)},n=function(e,t){if(t){var n=Math.pow(10,t);return Math.round(e*n)/n}return Math.round(e)};return function(){if(t(this.denominator)){var o=n(this.denominator,9),r=Math.pow(10,o.toString().split(".")[1].length);this.denominator=Math.round(this.denominator*r),this.numerator*=r}if(t(this.numerator)){var o=n(this.numerator,9),r=Math.pow(10,o.toString().split(".")[1].length);this.numerator=Math.round(this.numerator*r),this.denominator*=r}var i=e.gcf(this.numerator,this.denominator);return this.numerator/=i,this.denominator/=i,(this.numerator<0&&this.denominator<0||this.numerator>0&&this.denominator<0)&&(this.numerator*=-1,this.denominator*=-1),this}}(),e.gcf=function(t,n){var o=[],r=e.primeFactors(t),i=e.primeFactors(n);return r.forEach(function(e){var t=i.indexOf(e);t>=0&&(o.push(e),i.splice(t,1))}),0===o.length?1:function(){var e,t=o[0];for(e=1;eTHE FILE IS TOO LARGE AND CANNOT BE UPLOADED. PLEASE REDUCE THE SIZE OF THE FILE AND TRY AGAIN.

"),fte:c.trustAsHtml("
FTE stands forFull Time Equivalent. This is a useful measure foran organisation that has peopleworking part-time.For a full-time person, FTE is always equal to1.0, whereas for a part-time person, the FTE will representthe fraction of standard hours that the person works on aregular basis.
E.g. if the standard working day at an organisationcomprises of 8 hours, then a person who regularly works for8 hours each day would be considered to be full- time andwould have an FTE value of 1.0. A person who regularly worksfor only 4 hours each day would be considered to be apart-time person and would have an FTE value of 0.5. If theorganisation had 10 people, each with an FTE of 1.0 theactual headcount of full-time people would be 10 and theFTE headcount (equal to actual headcount multiplied by theFTE value) would also be 10. However, if the organisationhad another 10 people who each worked part-time with an FTEvalue of 0.5 the actual headcount of part-time people wouldbe 10 while the FTE headcount would only be 5. Thus for anorganisation that had a total of 10 full-time people, and 10part-time people (each with an FTE of 0.5) the actualheadcount for the organisation would be 20 while the FTEheadcount would be 15.
")},s.uploader={details:{contract_file:y.uploader("civicrm_hrjobcontract_details")},pension:{evidence_file:y.uploader("civicrm_hrjobcontract_pension",1)}},s.cancel=S,s.filesValidate=D,s.save=M,function(){e.copy(g,s.entity),s.entity.contract={is_primary:0},e.forEach(s.uploader,function(t){e.forEach(t,function(e){e.onAfterAddingAll=function(){s.filesValidate()}})}),A(),a.$broadcast("hrjc-loader-show"),P().then(function(){a.$broadcast("hrjc-loader-hide")})}()}return o.__name="ModalContractNewController",o.$inject=["$log","$q","$rootElement","$rootScope","$sce","$scope","$uibModalInstance","$uibModal","Contract","contractService","contractDetailsService","contractHourService","contractPayService","contractLeaveService","contractHealthService","contractPensionService","contractFilesService","model","utilsService","utils","settings","pubSub"],o}),define("job-contract/controllers/modal/modal-contract.controller",["common/angular","common/lodash","common/moment"],function(e,t,n){"use strict";function o(o,r,i,a,c,s,l,u,d,f,v,m,p,_,h,b,y,g,j,C,$,w,S,D,R){function P(){if("view"===y||e.equals(g,o.entity)&&e.equals(C,o.files)&&!o.uploader.details.contract_file.queue.length&&!o.uploader.pension.evidence_file.queue.length)return o.$broadcast("hrjc-loader-hide"),void i.dismiss("cancel");S.debug&&e.forEach(g,function(t,n){e.equals(t,o.entity[n])||(D.debug("======================"),D.debug("Changed entity: "+n),D.debug("Before:"),D.debug(t),D.debug("After:"),D.debug(o.entity[n]))}),r.open({appendTo:c.find("div").eq(0),templateUrl:S.pathApp+"views/modalDialog.html?v="+(new Date).getTime(),size:"sm",controller:"ModalDialogController",resolve:{content:function(){return{copyCancel:"No",title:"Alert",msg:"Are you sure you want to cancel? Changes will be lost!"}}}}).result.then(function(e){e&&(o.$broadcast("hrjc-loader-hide"),i.dismiss("cancel"))})}function M(){return r.open({appendTo:c.find("div").eq(0),templateUrl:S.pathApp+"views/modalChangeReason.html?v="+(new Date).getTime(),controller:"ModalChangeReasonController",resolve:{content:function(){return{copy:{title:Y.title}}},date:null,reasonId:null}}).result}function A(){var t=x("period_end_date"),n=x("period_start_date"),r=!e.equals(o.entity.leave,g.leave);return n||t||r}function L(){return r.open({appendTo:c.find("div").eq(0),templateUrl:S.pathApp+"views/modalConfirmEdit.html?v="+(new Date).getTime(),controller:"ModalDialogController",resolve:{content:function(){return{msg:"Save without making a new revision?"}}}}).result}function E(e,t){return o.$broadcast("hrjc-loader-show"),d.validateEffectiveDate({contact_id:S.contactId,effective_date:t}).then(function(n){if(n.success)return N(e,t);CRM.alert(n.message,"Error","error"),o.$broadcast("hrjc-loader-hide")},function(e){})}function T(){o.$broadcast("hrjc-loader-show"),o.entity.details.period_end_date=o.entity.details.period_end_date||"";var t,n,s,l,d,y=e.copy(o.entity),g=o.filesTrash,j=o.uploader,C={contract:u.save(y.contract),details:f.save(y.details),hour:v.save(y.hour),pay:m.save(y.pay),leave:p.save(y.leave),health:_.save(y.health),pension:h.save(y.pension)},$=[],w=[];for(t in g)for(s=0,l=g[t].length,s;so.fileMaxSize&&e.remove()})})}),j.details.contract_file.queue.length&&$.push(b.upload(j.details.contract_file,y.details.jobcontract_revision_id)),j.pension.evidence_file.queue.length&&$.push(b.upload(j.pension.evidence_file,y.pension.jobcontract_revision_id)),t.details.period_start_date=y.details.period_start_date,t.details.period_end_date=y.details.period_end_date,t.pay.annual_benefits=y.pay.annual_benefits,t.pay.annual_deductions=y.pay.annual_deductions,$.length?(d=r.open({appendTo:c.find("div").eq(0),templateUrl:S.pathApp+"views/modalProgress.html?v="+(new Date).getTime(),size:"sm",controller:"ModalProgressController",resolve:{uploader:function(){return j},promiseFilesUpload:function(){return $}}}),t.files=d.result,a.all(t)):(t.haveEntitlementFieldsChanged=A(),t)}).then(function(e){o.$broadcast("hrjc-loader-hide"),i.close(e),R.publish("Contract::updated")},function(e){o.$broadcast("hrjc-loader-hide"),CRM.alert(e,"Error","error")})}function F(e){var t=l("formatDate")(e,Date);return"Unspecified"!==t?t:e}function I(){return a.all([{name:"hrjobcontract_health_health_plan_type",key:"plan_type"},{name:"hrjobcontract_health_life_insurance_plan_type",key:"plan_type_life_insurance"}].map(function(e){_.getOptions(e.name,!0).then(function(n){s.options.health[e.key]=t.transform(n,function(e,t){e[t.key]=t.value},{})})}))}function U(e,t){var n=o.files[t];o.filesTrash[t].push(n[e]),n.splice(e,1)}function q(){var e=t.every(o.uploader,function(e){return t.every(e,function(e){return!e.queue||t.every(e.queue,function(e){return e.file.sizeo.fileMaxSize&&e.remove()}),F.queue.length&&P.push(b.upload(F,l))}),P.length?(s=r.open({appendTo:c.find("div").eq(0),templateUrl:S.pathApp+"views/modalProgress.html",size:"sm",controller:"ModalProgressController",resolve:{uploader:function(){return C},promiseFilesUpload:function(){return P}}}),e.files=s.result,a.all(e)):(e.haveEntitlementFieldsChanged=A(),e)}).then(function(e){o.$broadcast("hrjc-loader-hide"),i.close(e),R.publish("Contract::updated")})):(o.$broadcast("hrjc-loader-hide"),i.close())}D.debug("Controller: ModalContractController");var Y=j.copy||{};Y.close=Y.close||"Close",Y.save=Y.save||"Save changes",Y.title=Y.title||"Contract",o.action=y||"view",o.allowSave=void 0!==j.allowSave&&j.allowSave,o.copy=Y,o.entity={},o.fileMaxSize=S.CRM.maxFileSize||0,o.files={},o.filesTrash={},o.isDisabled=void 0===j.isDisabled||j.isDisabled,o.isPrimaryDisabled=+g.contract.is_primary,o.showIsPrimary=w.contractListLen>1&&"change"!==y,o.uploader={details:{contract_file:b.uploader("civicrm_hrjobcontract_details")},pension:{evidence_file:b.uploader("civicrm_hrjobcontract_pension",1)}},o.utils=w,o.cancel=P,o.fileMoveToTrash=U,o.filesValidate=q,o.save=z,function(){O(),H(),i.opened.then(function(){s.$broadcast("hrjc-loader-hide")}),s.$broadcast("hrjc-loader-show"),I().then(function(){s.$broadcast("hrjc-loader-hide")})}()}return o.__name="ModalContractController",o.$inject=["$scope","$uibModal","$uibModalInstance","$q","$rootElement","$rootScope","$filter","contractService","contractRevisionService","contractDetailsService","contractHourService","contractPayService","contractLeaveService","contractHealthService","contractPensionService","contractFilesService","action","entity","content","files","utilsService","utils","settings","$log","pubSub"],o}),define("job-contract/controllers/modal/modal-dialog.controller",[],function(){"use strict";function e(e,t,n,o,r){function i(){o.dismiss("Cancel")}function a(e){o.close(e||!0)}e.debug("Controller: ModalDialogController"),t.copyCancel=r.copyCancel||"Cancel",t.copyConfirm=r.copyConfirm||"Yes",t.msg=r.msg||"",t.title=r.title||"CiviHR Job Contract",t.cancel=i,t.confirm=a}return e.__name="ModalDialogController",e.$inject=["$log","$scope","$timeout","$uibModalInstance","content"],e}),define("job-contract/controllers/modal/modal-progress.controller",[],function(){"use strict";function e(e,t,n,o,r,i,a){function c(){r.dismiss("File upload canceled")}e.debug("Controller: ModalProgressController");var s,l;n.uploader=i,n.cancel=c,function(){for(s in i)for(l in i[s])i[s][l].queue.length&&(i[s][l].item=i[s][l].queue[0].file.name),i[s][l].onProgressItem=function(e){this.item=e.file.name};t.all(a).then(function(e){o(function(){r.close(e)},500)})}()}return e.__name="ModalProgressController",e.$inject=["$log","$q","$scope","$timeout","$uibModalInstance","uploader","promiseFilesUpload"],e}),define("job-contract/controllers/modal/modal-revision.controller",["common/angular"],function(e){"use strict";function t(t,n,o,r,i,a,c,s,l,u,d,f,v,m,p){function _(){a.dismiss("cancel")}function h(){var e=(i.currentPage-1)*i.itemsPerPage,t=e+i.itemsPerPage;i.revisionDataListPage=i.revisionDataList.slice(e,t)}function b(){var e,t=0,n=i.fields.length;for(t;t-1?"&":"?"),r=i.entity;return e.forEach(i.fields,function(e){t="editor_name"!==e.name?e.name:"editor_uid",n=e.extends?"":r+"_",e.selected&&(o+="fields["+n+t+"]=1&")}),o+="fields[sort_name]=1&fields[first_name]=1&fields[last_name]=1&fields[external_identifier]=1&fields[email]=1&fields[street_address]=1&fields[city]=1&fields[name]=1&fields[contract_contact_id]=1&fields[contract_contract_id]=1&fields[jobcontract_revision_id]=1&fields[change_reason]=1&fields[created_date]=1&fields[effective_date]=1&fields[modified_date]=1&order_bys[1][column]=id&order_bys[1][order]=ASC&order_bys[2][column]=civicrm_hrjobcontract_revision_revision_id&order_bys[2][order]=ASC&order_bys[3][column]=-&order_bys[3][order]=ASC&order_bys[4][column]=-&order_bys[4][order]=ASC&order_bys[5][column]=-&order_bys[5][order]=ASC&contract_id_op=eq&permission=access+CiviReport&row_count=&_qf_Summary_submit_csv=Preview+CSV&groups=&contract_id_value="+l[0].jobcontract_id+"&group_bys[civicrm_hrjobcontract_revision_revision_id]=1"}n.debug("Controller: ModalRevisionController"),i.$broadcast("hrjc-loader-show"),i.currentPage=1,i.entity=u,i.fields=e.copy(d),i.itemsPerPage=5,i.revisionDataList=[],i.revisionList=[],i.sortCol="effective_date",i.subFields={},i.maxSize=5,i.modalContract=v,i.sortReverse=!0,i.urlCSV=w(),i.cancel=_,i.createPage=h,i.sortBy=C,i.toggleFieldsSelected=$,function(){b(),y(),g(),j(),i.sortBy(),a.opened.then(function(){r.$broadcast("hrjc-loader-hide")})}()}return t.__name="ModalRevisionController",t.$inject=["$filter","$log","$q","$rootScope","$scope","$uibModalInstance","settings","revisionDataList","revisionList","entity","fields","model","modalContract","utils","contactService"],t}),define("job-contract/modules/job-contract.controllers",["common/angular","job-contract/controllers/contract.controller","job-contract/controllers/contract-list.controller","job-contract/controllers/revision-list.controller","job-contract/controllers/form/form-general.controller","job-contract/controllers/form/form-health.controller","job-contract/controllers/form/form-hour.controller","job-contract/controllers/form/form-leave.controller","job-contract/controllers/form/form-pay.controller","job-contract/controllers/form/form-pension.controller","job-contract/controllers/modal/modal-change-reason.controller","job-contract/controllers/modal/modal-contract-new.controller","job-contract/controllers/modal/modal-contract.controller","job-contract/controllers/modal/modal-dialog.controller","job-contract/controllers/modal/modal-progress.controller","job-contract/controllers/modal/modal-revision.controller"],function(e,t,n,o,r,i,a,c,s,l,u,d,f,v,m,p){"use strict";return e.module("job-contract.controllers",[]).controller(t.__name,t).controller(n.__name,n).controller(o.__name,o).controller(r.__name,r).controller(i.__name,i).controller(a.__name,a).controller(c.__name,c).controller(s.__name,s).controller(l.__name,l).controller(u.__name,u).controller(d.__name,d).controller(f.__name,f).controller(v.__name,v).controller(m.__name,m).controller(p.__name,p)}),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,o,r){return n.debug("AbsenceTypeAPI"),o.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(o,i,a){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),a=e.assign({},a,{absence_type_id:o,date:t(i).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",a).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,o,r,i,a){return t.debug("AbsenceType"),o.extend({all:function(e){return i.all(e).then(function(e){return e.map(function(e){return a.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return i.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return i.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,o){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=o.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,o,r,i){return e.debug("AbsencePeriod"),n.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(i.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return o.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),function(e,t){function n(){var e={nodiff:"",year:"year",years:"years",month:"month",months:"months",day:"day",days:"days",hour:"hour",hours:"hours",minute:"minute",minutes:"minutes",second:"second",seconds:"seconds",delimiter:" "};moment.fn.preciseDiff=function(e){return moment.preciseDiff(this,e)},moment.preciseDiff=function(t,n){function o(t,n){return t+" "+e[n+(1===t?"":"s")]}var r=moment(t),i=moment(n);if(r.isSame(i))return e.nodiff;if(r.isAfter(i)){var a=r;r=i,i=a}var c=i.year()-r.year(),s=i.month()-r.month(),l=i.date()-r.date();if(l<0){var u=moment(i.year()+"-"+(i.month()+1),"YYYY-MM").subtract("months",1).daysInMonth();l=u
Length Of Employment
"),e(".lengthEmployment").html(a),o&&l<0&&e(".lengthEmployment").css({color:"#FF0000"})}var r=CRM.grID,i=e("#custom-set-content-"+r+" .crm-inline-block-content div:nth-child(2) .crm-custom-data").html(),a=e("#custom-set-content-"+r+" .crm-inline-block-content div:nth-child(3) .crm-custom-data").html();i&&o(i,a,r),e(document).on("click","#_qf_CustomData_upload",function(){e(document).ajaxSuccess(function(t,n,i){i.extraData&&"CRM_Contact_Form_Inline_CustomData"==i.extraData.class_name&&i.extraData.groupID==r&&setTimeout(function(){var t=e("#custom-set-content-"+r+" .crm-inline-block-content div:nth-child(2) .crm-custom-data").html(),n=e("#custom-set-content-"+r+" .crm-inline-block-content div:nth-child(3) .crm-custom-data").html();t&&o(t,n,r)},300)})})}(CRM.$,CRM._),define("job-contract/modules/job-contract.core",["common/angular","common/ui-select","common/directives/angular-date/date-input","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/routers/compu-ng-route","common/modules/directives","common/services/dom-event-trigger","common/services/pub-sub","common/services/angular-date/date-format","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/absence-period.model","job-contract/vendor/fraction","job-contract/vendor/job-summary"],function(e){"use strict";e.module("job-contract.core",["ngAnimate","compuNgRoute","ngResource","angularFileUpload","ui.bootstrap","ui.select","common.angularDate","common.services","common.directives","common.filters","leave-absences.models"])}),define("job-contract/directives/contact.directive",[],function(){"use strict";function e(e,t,n,o){return t.debug("Directive: hrjcContact"),{restrict:"A",scope:{renderAsLink:"=?hrjcContactLink",contactId:"=?hrjcContact"},template:"{{contact.label}}",link:function(t,n){t.contactId&&t.$watch("contactId",function(r){o.getOne(t.contactId).then(function(o){t.contact=o,t.renderAsLink&&(n.html('{{contact.label}}'),e(n.contents())(t))})})}}}return e.__name="hrjcContact",e.$inject=["$compile","$log","settings","contactService"],e}),define("job-contract/directives/loader.directive",[],function(){"use strict";function e(e,t){return e.debug("Directive: hrjcLoader"),{link:function(e,t,n){function o(){var e=window.getComputedStyle(t[0]).position;return"relative"===e||"absolute"===e||"fixed"===e}function r(){o()||(t.css("position","relative"),s=!0),t.append(a),c=!0}function i(){c&&a.parentNode.removeChild(a),c=!1,s&&t.css("position","")}var a=document.createElement("div"),c=!1,s=!1;a.className="hrjc-loader spinner",n.hrjcLoaderShow&&r(),e.$on("hrjc-loader-show",function(){r()}),e.$on("hrjc-loader-hide",function(){i()})}}}return e.__name="hrjcLoader",e.$inject=["$log","$rootScope"],e}),define("job-contract/directives/number.directive",[],function(){"use strict";function e(e){return e.debug("Directive: hrjcNumber"),{require:"ngModel",link:function(e,t,n,o){var r=2,i=n.hrjcNumberFloat||!1,a=n.hrjcToHours||!1,c=n.hrjcNotNegative||!1;n.hrjcNumber&&"number"==typeof+n.hrjcNumber&&(r=n.hrjcNumber),t.bind("blur",function(){var e=parseFloat(o.$viewValue)||0;c&&e<0&&(e=0),a&&(e=.25*Math.ceil(e/.25)),o.$setViewValue(i?Math.round(100*e)/100:e.toFixed(r)),o.$render()})}}}return e.__name="hrjcNumber",e.$inject=["$log"],e}),define("job-contract/directives/validate.directive",["common/angular"],function(e){"use strict";function t(t){return t.debug("Directive: hrjcValidate"),{restrict:"A",require:"^form",scope:{isWarning:"=?hrjcValidateWarning"},link:function(t,n,o,r){function i(e,t){n.toggleClass("has-success",!e&&!t),f.toggleClass("glyphicon-ok",!e&&!t)}function a(e,t){n.toggleClass("has-warning",!e&&t),f.toggleClass("glyphicon-warning-sign",!e&&t)}function c(e){n.toggleClass("has-error",e),f.toggleClass("glyphicon-remove",e)}var s=n[0].querySelector("[name]"),l=e.element(s),u=l.attr("name"),d=document.createElement("span"),f=e.element(d);u&&(n.addClass("has-feedback"),f.addClass("glyphicon form-control-feedback"),l.after(f),t.$watch(function(){return r[u]&&r[u].$invalid},function(e){r[u].$dirty&&(i(e,t.isWarning),c(e))}),void 0!==t.isWarning&&t.$watch("isWarning",function(e){var t=r[u].$invalid;r[u].$dirty&&(i(t,e),a(t,e))}),l.bind("blur",function(){c(r[u].$invalid)}))}}}return t.__name="hrjcValidate",t.$inject=["$log"],t}),define("job-contract/modules/job-contract.directives",["common/angular","job-contract/directives/contact.directive","job-contract/directives/loader.directive","job-contract/directives/number.directive","job-contract/directives/validate.directive"],function(e,t,n,o,r){"use strict";return e.module("job-contract.directives",[]).directive(t.__name,t).directive(n.__name,n).directive(o.__name,o).directive(r.__name,r)}),define("job-contract/filters/capitalize.filter",[],function(){"use strict";function e(e){return e.debug("Filter: capitalize"),function(e){return e?e.replace(/([^\W_]+[^\s-]*) */g,function(e){ return e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()}):""}}return e.__name="capitalize",e.$inject=["$log"],e}),define("job-contract/filters/format-amount.filter",[],function(){"use strict";function e(e){return e.debug("Filter: formatAmount"),function(e){return e&&-1===e.indexOf(".")?e+".00":e}}return e.__name="formatAmount",e.$inject=["$log"],e}),define("job-contract/filters/format-period.filter",[],function(){"use strict";function e(e,t){return t.debug("Filter: formatPeriod"),function(t){return t?e("date")(t,"yyyy/MM/dd"):"Unspecified"}}return e.__name="formatPeriod",e.$inject=["$filter","$log"],e}),define("job-contract/filters/get-obj-by-id.filter",[],function(){"use strict";function e(e){return e.debug("Filter: getObjById"),function(e,t,n){if(!e)return null;for(var o=0,r=e.length;oCiviCRM LLC info@civicrm.org - 2018-02-26 - 1.7.4 - beta + 2018-03-26 + 1.7.5 + stable 4.7 - This is a new, undeveloped module CRM/HRMed diff --git a/hrprofile/info.xml b/hrprofile/info.xml index 28fff5a815c..5a69393d18f 100644 --- a/hrprofile/info.xml +++ b/hrprofile/info.xml @@ -8,13 +8,12 @@ CiviCRM LLC info@civicrm.org - 2018-02-26 - 1.7.4 - beta + 2018-03-26 + 1.7.5 + stable 4.7 - This is a new, undeveloped module CRM/HRProfile diff --git a/hrqual/info.xml b/hrqual/info.xml index 4e6dcc3a743..90f47a8ec96 100644 --- a/hrqual/info.xml +++ b/hrqual/info.xml @@ -8,13 +8,12 @@ CiviCRM LLC info@civicrm.org - 2018-02-26 - 1.7.4 - beta + 2018-03-26 + 1.7.5 + stable 4.7 - This is a new, undeveloped module CRM/HRQual diff --git a/hrrecruitment/info.xml b/hrrecruitment/info.xml index 0adbcb6c2dd..bd33b0c44d4 100644 --- a/hrrecruitment/info.xml +++ b/hrrecruitment/info.xml @@ -8,13 +8,12 @@ CiviCRM LLC info@civicrm.org - 2018-02-26 - 1.7.4 - alpha + 2018-03-26 + 1.7.5 + stable 4.7 - This is a new, undeveloped module CRM/HRRecruitment diff --git a/hrreport/info.xml b/hrreport/info.xml index 7f4ad9d5b82..5eacd53c769 100644 --- a/hrreport/info.xml +++ b/hrreport/info.xml @@ -8,13 +8,12 @@ CiviCRM LLC info@civicrm.org - 2018-02-26 - 1.7.4 - beta + 2018-03-26 + 1.7.5 + stable 4.7 - This is a new, undeveloped module CRM/HRReport diff --git a/hrstaffdir/info.xml b/hrstaffdir/info.xml index cbfec84ab47..a377cca7dae 100644 --- a/hrstaffdir/info.xml +++ b/hrstaffdir/info.xml @@ -8,13 +8,12 @@ CiviCRM LLC info@civicrm.org - 2018-02-26 - 1.7.4 - beta + 2018-03-26 + 1.7.5 + stable 4.7 - This is a new, undeveloped module CRM/Hrstaffdir diff --git a/hrui/info.xml b/hrui/info.xml index 4caf678024e..f50dd7776ea 100644 --- a/hrui/info.xml +++ b/hrui/info.xml @@ -8,13 +8,12 @@ CiviCRM LLC info@civicrm.org - 2018-02-26 - 1.7.4 - beta + 2018-03-26 + 1.7.5 + stable 4.7 - This is a new, undeveloped module CRM/HRUI diff --git a/hrvisa/info.xml b/hrvisa/info.xml index e4946ed0750..55e5dc10387 100644 --- a/hrvisa/info.xml +++ b/hrvisa/info.xml @@ -10,11 +10,10 @@ 2017-08-22 1.7.0-RC - beta + stable 4.7 - This is a new, undeveloped module CRM/HRVisa diff --git a/org.civicrm.bootstrapcivihr/info.xml b/org.civicrm.bootstrapcivihr/info.xml index ba01c773394..ae09b9a9f74 100644 --- a/org.civicrm.bootstrapcivihr/info.xml +++ b/org.civicrm.bootstrapcivihr/info.xml @@ -5,12 +5,12 @@ A CiviHR extension of the CiviCRM Bootstrap theme AGPL-3.0 - Alessandro Verdura - alessandro@compucorp.co.uk + Compucorp Ltd + info@compucorp.co.uk - 2018-02-26 - 1.7.4 - alpha + 2018-03-26 + 1.7.5 + stable 4.7 diff --git a/org.civicrm.hremergency/info.xml b/org.civicrm.hremergency/info.xml index 80bf56b060b..6aaea248694 100644 --- a/org.civicrm.hremergency/info.xml +++ b/org.civicrm.hremergency/info.xml @@ -2,19 +2,19 @@ hremergency Emergency Contacts (CiviHR) - + Emergency Contacts extension for CiviHR AGPL-3.0 - gregmeszaros - meszaros275@gmail.com + Compucorp Ltd + info@compucorp.co.uk - 2018-02-26 - 1.7.4 - alpha + 2018-03-26 + 1.7.5 + stable 4.7 - Emergency Contacts extensions for CiviHR + CRM/Hremergency diff --git a/org.civicrm.reqangular/info.xml b/org.civicrm.reqangular/info.xml index 43c60e7738b..12c58d4887d 100755 --- a/org.civicrm.reqangular/info.xml +++ b/org.civicrm.reqangular/info.xml @@ -7,16 +7,15 @@ angularResource, angularBootstrap, angularFileUpload AGPL-3.0 - Mateusz Cieplinski - mateusz@coldrun.pl + Compucorp Ltd + info@compucorp.co.uk - 2018-02-26 - 1.7.4 - alpha + 2018-03-26 + 1.7.5 + stable 4.7 - This is a new, undeveloped module CRM/Reqangular diff --git a/uk.co.compucorp.civicrm.hrcomments/info.xml b/uk.co.compucorp.civicrm.hrcomments/info.xml index 859798b1015..fec9297662c 100644 --- a/uk.co.compucorp.civicrm.hrcomments/info.xml +++ b/uk.co.compucorp.civicrm.hrcomments/info.xml @@ -8,9 +8,9 @@ Compucorp Ltd info@compucorp.co.uk - 2018-02-26 - 1.7.4 - alpha + 2018-03-26 + 1.7.5 + stable 4.2 diff --git a/uk.co.compucorp.civicrm.hrcontactactionsmenu/info.xml b/uk.co.compucorp.civicrm.hrcontactactionsmenu/info.xml index 52dcb1ded66..241605144c9 100644 --- a/uk.co.compucorp.civicrm.hrcontactactionsmenu/info.xml +++ b/uk.co.compucorp.civicrm.hrcontactactionsmenu/info.xml @@ -9,9 +9,9 @@ Compucorp Ltd info@compucorp.co.uk - 2017-12-20 - 1.7.2 - alpha + 2018-03-26 + 1.7.5 + stable 4.7 diff --git a/uk.co.compucorp.civicrm.hrcore/info.xml b/uk.co.compucorp.civicrm.hrcore/info.xml index c64d057d84e..aa25c303ad0 100644 --- a/uk.co.compucorp.civicrm.hrcore/info.xml +++ b/uk.co.compucorp.civicrm.hrcore/info.xml @@ -8,9 +8,9 @@ Compucorp Ltd info@compucorp.co.uk - 2018-02-26 - 1.7.4 - alpha + 2018-03-26 + 1.7.5 + stable 4.7 diff --git a/uk.co.compucorp.civicrm.hrcore/templates/CRM/HRCore/UserMenuMarkup.tpl b/uk.co.compucorp.civicrm.hrcore/templates/CRM/HRCore/UserMenuMarkup.tpl index e1e251a9306..185637e274e 100644 --- a/uk.co.compucorp.civicrm.hrcore/templates/CRM/HRCore/UserMenuMarkup.tpl +++ b/uk.co.compucorp.civicrm.hrcore/templates/CRM/HRCore/UserMenuMarkup.tpl @@ -10,7 +10,7 @@
- + diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Page/AbsencePeriod.tpl b/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Page/AbsencePeriod.tpl index 5295c5da427..1248cb4366c 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Page/AbsencePeriod.tpl +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Page/AbsencePeriod.tpl @@ -15,7 +15,7 @@ {foreach from=$rows item=row} - + diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Page/AbsenceType.tpl b/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Page/AbsenceType.tpl index f3e72eb1bf5..342646cfe85 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Page/AbsenceType.tpl +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Page/AbsenceType.tpl @@ -21,7 +21,7 @@ {foreach from=$rows item=row} - + diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Page/PublicHoliday.tpl b/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Page/PublicHoliday.tpl index 89376f30d64..843cd706c88 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Page/PublicHoliday.tpl +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Page/PublicHoliday.tpl @@ -16,7 +16,7 @@ {foreach from=$rows item=row} - + diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Page/WorkPattern.tpl b/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Page/WorkPattern.tpl index 4e0a29e3c59..246a3758b83 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Page/WorkPattern.tpl +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Page/WorkPattern.tpl @@ -20,8 +20,8 @@ {foreach from=$rows item=row} - - + + - + - + - + @@ -93,8 +102,18 @@ {/section} {literal} {/literal} diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/absence-tab/components/absence-tab-custom-work-pattern-modal.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/absence-tab/components/absence-tab-custom-work-pattern-modal.html index 320516ee55f..6059a0b83a7 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/absence-tab/components/absence-tab-custom-work-pattern-modal.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/absence-tab/components/absence-tab-custom-work-pattern-modal.html @@ -46,7 +46,7 @@
diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/sickness.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/sickness.html index 286fda35960..0bebad4ca50 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/sickness.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/sickness.html @@ -4,7 +4,7 @@
-
+
- - - +
+
+
+ + +
+
+
+ + + +
- - -
diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/sickness.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/sickness.html index 0bebad4ca50..7da9dd80eaf 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/sickness.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/sickness.html @@ -3,8 +3,8 @@
-
-
+
+
{$contact.id}{$contact.display_name}{$contact.display_name|escape} - {$absenceType->title} + {$absenceType->title|escape} {$calculation->getPreviousPeriodProposedEntitlement()|timeUnitApplier:$calculationUnit}
{$row.title}{$row.title|escape} {$row.start_date|crmDate} {$row.end_date|crmDate} {$row.weight}
{$row.title}{$row.title|escape} {if $row.allow_accruals_request eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if} {if $row.is_default eq 1}{/if} {$row.weight}
{$row.title}{$row.title|escape} {$row.date|crmDate} {if $row.is_active eq 1} {ts}Enabled{/ts} {else} {ts}Disabled{/ts} {/if} {$row.action|replace:'xx':$row.id}
{$row.label}{$row.description}{$row.label|escape}{$row.description|escape} {$row.number_of_weeks} {$row.number_of_hours} diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveRequestTest.php b/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveRequestTest.php index b9839074c4d..8ecec50ad5a 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveRequestTest.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveRequestTest.php @@ -902,6 +902,13 @@ public function testLeaveRequestShouldNotBeCreatedWhenAbsenceTypeIsNotActive() { } public function testNumberOfDaysOfLeaveRequestShouldNotBeGreaterMaxConsecutiveLeaveDaysForAbsenceType() { + WorkPatternFabricator::fabricateWithA40HourWorkWeek(['is_default' => 1]); + $contactID = 1; + HRJobContractFabricator::fabricate( + ['contact_id' => $contactID], + ['period_start_date' => '2017-01-01'] + ); + $absenceType = AbsenceTypeFabricator::fabricate([ 'max_consecutive_leave_days' => 2.5 ]); @@ -913,7 +920,7 @@ public function testNumberOfDaysOfLeaveRequestShouldNotBeGreaterMaxConsecutiveLe LeaveRequest::create([ 'type_id' => $absenceType->id, - 'contact_id' => 1, + 'contact_id' => $contactID, 'status_id' => 1, 'from_date' => CRM_Utils_Date::processDate('now'), 'from_date_type' => 1, @@ -923,6 +930,86 @@ public function testNumberOfDaysOfLeaveRequestShouldNotBeGreaterMaxConsecutiveLe ]); } + public function testLeaveRequestCanBeCreatedWhenNumberOfLeaveWorkingDaysNotGreaterThanMaxConsecutiveDays() { + $absencePeriod = AbsencePeriodFabricator::fabricate([ + 'start_date' => CRM_Utils_Date::processDate('2017-01-01'), + 'end_date' => CRM_Utils_Date::processDate('2017-06-14'), + ]); + + WorkPatternFabricator::fabricateWithA40HourWorkWeek(['is_default' => 1]); + $contactID = 1; + HRJobContractFabricator::fabricate( + ['contact_id' => $contactID], + ['period_start_date' => '2017-01-01'] + ); + + $absenceType = AbsenceTypeFabricator::fabricate([ + 'max_consecutive_leave_days' => 4 + ]); + + $periodEntitlement = LeavePeriodEntitlementFabricator::fabricate([ + 'type_id' => $absenceType->id, + 'contact_id' => $contactID, + 'period_id' => $absencePeriod->id + ]); + + $this->createLeaveBalanceChange($periodEntitlement->id, 10); + + //The leave days are six days but in reality there are just 4 working days + //because 2017-01-07 and 2017-01-08 fall on weekends. So request should be allowed + //to be created. + LeaveRequest::create([ + 'type_id' => $absenceType->id, + 'contact_id' => $contactID, + 'status_id' => 1, + 'from_date' => CRM_Utils_Date::processDate('2017-01-05'), + 'from_date_type' => 1, + 'to_date' => CRM_Utils_Date::processDate('2017-01-10'), + 'to_date_type' => 1, + 'request_type' => LeaveRequest::REQUEST_TYPE_LEAVE + ]); + } + + public function testLeaveRequestCanBeCreatedWhenNumberOfLeaveWorkingDaysNotGreaterThanMaxConsecutiveDaysForWorkPatternWithMultipleWeeks() { + $absencePeriod = AbsencePeriodFabricator::fabricate([ + 'start_date' => CRM_Utils_Date::processDate('2017-01-01'), + 'end_date' => CRM_Utils_Date::processDate('2017-06-14'), + ]); + + WorkPatternFabricator::fabricateWithTwoWeeksAnd31AndHalfHours(['is_default' => 1]); + $contactID = 1; + HRJobContractFabricator::fabricate( + ['contact_id' => $contactID], + ['period_start_date' => '2017-01-01'] + ); + + $absenceType = AbsenceTypeFabricator::fabricate([ + 'max_consecutive_leave_days' => 5 + ]); + + $periodEntitlement = LeavePeriodEntitlementFabricator::fabricate([ + 'type_id' => $absenceType->id, + 'contact_id' => $contactID, + 'period_id' => $absencePeriod->id + ]); + + $this->createLeaveBalanceChange($periodEntitlement->id, 10); + + //The leave days are twelve days but in reality there are just 5 working days + //Mon(2017-01-02), Wed(2017-01-04) and Fri(2017-01-06) for first week + // and Tue((2017-01-10), Thur(2017-01-12) for second week to be created. + LeaveRequest::create([ + 'type_id' => $absenceType->id, + 'contact_id' => $contactID, + 'status_id' => 1, + 'from_date' => CRM_Utils_Date::processDate('2017-01-02'), + 'from_date_type' => 1, + 'to_date' => CRM_Utils_Date::processDate('2017-01-13'), + 'to_date_type' => 1, + 'request_type' => LeaveRequest::REQUEST_TYPE_LEAVE + ]); + } + public function testAUserCannotCancelOwnLeaveRequestWhenAbsenceTypeDoesNotAllowIt() { $contactID = 5; $this->registerCurrentLoggedInContactInSession($contactID); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/api/v3/LeaveRequestTest.php b/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/api/v3/LeaveRequestTest.php index c6f3a332e0f..aab38d5e4ea 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/api/v3/LeaveRequestTest.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/api/v3/LeaveRequestTest.php @@ -2767,6 +2767,13 @@ public function testLeaveRequestIsValidShouldReturnErrorWhenRequestTypeIsSicknes } public function testLeaveRequestIsValidShouldReturnErrorWhenLeaveDaysIsGreaterThanAbsenceTypeMaxConsecutiveLeaveDays() { + WorkPatternFabricator::fabricateWithA40HourWorkWeek(['is_default' => 1]); + $contactID = 1; + HRJobContractFabricator::fabricate( + ['contact_id' => $contactID], + ['period_start_date' => '2017-01-01'] + ); + $maxConsecutiveLeaveDays = 2; $absenceType = AbsenceTypeFabricator::fabricate([ 'max_consecutive_leave_days' => $maxConsecutiveLeaveDays @@ -2776,7 +2783,7 @@ public function testLeaveRequestIsValidShouldReturnErrorWhenLeaveDaysIsGreaterTh $toDate = new DateTime('+4 days'); $result = civicrm_api3('LeaveRequest', 'isvalid', [ 'type_id' => $absenceType->id, - 'contact_id' => 1, + 'contact_id' => $contactID, 'status_id' => 1, 'from_date' => $fromDate->format('YmdHis'), 'from_date_type' => 1, diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/toil_amounts_install.xml b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/toil_amounts_install.xml index f0769dab950..df75313c402 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/toil_amounts_install.xml +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/toil_amounts_install.xml @@ -14,18 +14,6 @@ - - - 0 - zero_days - 0 - 1 - 0 - 1 - 1 - hrleaveandabsences_toil_amounts - - 0.25 diff --git a/uk.co.compucorp.civicrm.hrsampledata/info.xml b/uk.co.compucorp.civicrm.hrsampledata/info.xml index 01e7f4414b3..bffdb204eab 100644 --- a/uk.co.compucorp.civicrm.hrsampledata/info.xml +++ b/uk.co.compucorp.civicrm.hrsampledata/info.xml @@ -8,9 +8,9 @@ Compucorp info@compucorp.com - 2018-02-26 - 1.7.4 - beta + 2018-03-26 + 1.7.5 + stable 4.7 From 6dc6f1c11a970afe68fae833794c251ca461ce57 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Wed, 28 Mar 2018 13:06:38 +0100 Subject: [PATCH 071/203] PCHR-3353: Add 'is_multiple' value to API request to prevent change As mentioned in the comment there is a bug where not including 'is_multiple' will set it to false. There is a core PR to fix this, but this is a quick fix to avoid waiting for core --- .../CRM/Hremergency/Upgrader/Steps/1004.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/org.civicrm.hremergency/CRM/Hremergency/Upgrader/Steps/1004.php b/org.civicrm.hremergency/CRM/Hremergency/Upgrader/Steps/1004.php index cf222bce359..b84233654ba 100644 --- a/org.civicrm.hremergency/CRM/Hremergency/Upgrader/Steps/1004.php +++ b/org.civicrm.hremergency/CRM/Hremergency/Upgrader/Steps/1004.php @@ -4,9 +4,13 @@ trait CRM_Hremergency_Upgrader_Steps_1004 { /** * Upgrade CustomGroup, setting Emergency_Contacts is_reserved to Yes. + * * Title was included here because of an issue with webform_civicrm * @see https://www.drupal.org/project/webform_civicrm/issues/2947922 * + * is_multiple was included because of an issue with CiviCRM core + * @see https://issues.civicrm.org/jira/browse/CRM-21853 + * * @return bool */ public function upgrade_1004() { @@ -15,10 +19,11 @@ public function upgrade_1004() { 'return' => ['id'], 'name' => 'Emergency_Contacts', ]); - + civicrm_api3('CustomGroup', 'create', [ 'id' => $result['id'], 'is_reserved' => 1, + 'is_multiple' => 1, 'title' => 'Emergency Contacts' ]); From e37e3fc764052d41392104b20a34a1c279495610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Olivo?= Date: Wed, 28 Mar 2018 13:20:19 -0400 Subject: [PATCH 072/203] PCHR-3411: Remove unnecesary relationship types --- .../CRM/HRCore/Upgrader.php | 1 + .../CRM/HRCore/Upgrader/Steps/1012.php | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php index e15a417dc7b..e194b80139f 100755 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php @@ -19,6 +19,7 @@ class CRM_HRCore_Upgrader extends CRM_HRCore_Upgrader_Base { use CRM_HRCore_Upgrader_Steps_1009; use CRM_HRCore_Upgrader_Steps_1010; use CRM_HRCore_Upgrader_Steps_1011; + use CRM_HRCore_Upgrader_Steps_1012; /** * @var array diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php new file mode 100644 index 00000000000..cb024df911b --- /dev/null +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php @@ -0,0 +1,28 @@ + [ 'IN' => $relationshipsToBeDeleted ] + ]); + + foreach($result['values'] as $relationship) { + civicrm_api3('RelationshipType', 'delete', [ + 'id' => $relationship['id'] + ]); + } + + return TRUE; + } +} From 3eb5d660fcad6ccadc8d69bc57dc2f07c33fed65 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Thu, 29 Mar 2018 10:34:36 +0100 Subject: [PATCH 073/203] PCHR-3392: Quickfix to prevent bug changing 'is_multiple' to false See https://issues.civicrm.org/jira/browse/CRM-21853 for details of the bug --- hrjobcontract/CRM/Hrjobcontract/Upgrader.php | 17 ++++++++++++----- .../CRM/HRCore/Upgrader/Steps/1014.php | 5 +++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php index bbf8d939910..1ddc054ede4 100755 --- a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php +++ b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php @@ -1192,16 +1192,23 @@ public function upgrade_1035() { ]; $result = civicrm_api3('CustomGroup', 'get', [ - 'return' => ['id'], + 'return' => ['id', 'name'], 'name' => ['IN' => $customGroups], ]); if ($result['count'] > 0) { foreach ($result['values'] as $value) { - civicrm_api3('CustomGroup', 'create', [ - 'id' => $value['id'], - 'is_reserved' => 1, - ]); + $params = ['id' => $value['id'], 'is_reserved' => 1]; + + /** + * 'is_multiple' is added to prevent bug that changes it to false + * @see https://issues.civicrm.org/jira/browse/CRM-21853 + */ + if ($value['name'] === 'HRJobContract_Dates') { + $params['is_multiple'] = 1; + } + + civicrm_api3('CustomGroup', 'create', $params); } } diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1014.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1014.php index 3093a8db73a..d354c323bd6 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1014.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1014.php @@ -16,10 +16,15 @@ public function upgrade_1014() { 'name' => 'Identify', ]); + /** + * 'is_multiple' is added to prevent bug that changes it to false + * @see https://issues.civicrm.org/jira/browse/CRM-21853 + */ if ($result['id']) { civicrm_api3('CustomGroup', 'create', [ 'id' => $result['id'], 'is_reserved' => 1, + 'is_multiple' => 1, ]); } From c5b7f6eba87b086f489f20adbed03b992af1e817 Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Mon, 26 Mar 2018 18:02:34 +0100 Subject: [PATCH 074/203] PCHR-3460 PR Feedback --- .../js/dist/job-roles.min.js | 4 +- .../controllers/job-roles.controller.js | 60 +++++++++++++------ .../views/include/add_new_role.html | 10 ++-- .../views/include/job_role_panel.html | 10 ++-- 4 files changed, 53 insertions(+), 31 deletions(-) diff --git a/com.civicrm.hrjobroles/js/dist/job-roles.min.js b/com.civicrm.hrjobroles/js/dist/job-roles.min.js index 56a4735f0ef..fff2f9a4304 100644 --- a/com.civicrm.hrjobroles/js/dist/job-roles.min.js +++ b/com.civicrm.hrjobroles/js/dist/job-roles.min.js @@ -12,6 +12,6 @@ Build date: 2014-01-10 */ -define("job-roles/modules/job-roles.config",["common/angular"],function(e){"use strict";function t(e,t,n,r,a){t.debugEnabled(a.debug),r.resolveForAll({format:["DateFormat",function(e){return e.getDateFormat()}]}).when("/",{templateUrl:a.pathBaseUrl+a.pathTpl+"mainTemplate.html?v=1",resolve:{},controller:"JobRolesController",controllerAs:"jobroles"}).otherwise({redirectTo:"/"}),n.defaults.stripTrailingSlashes=!1,e.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}e.module("hrjobroles.config",["hrjobroles.constants"]).config(t),t.$inject=["$httpProvider","$logProvider","$resourceProvider","$routeProvider","settings"]}),define("job-roles/modules/job-roles.constants",["common/angular"],function(e){"use strict";e.module("hrjobroles.constants",[]).constant("settings",{classNamePrefix:"hrjobroles-",contactId:decodeURIComponent((new RegExp("[?|&]cid=([^&;]+?)(&|#|;|$)").exec(location.search)||[null,""])[1].replace(/\+/g,"%20"))||null,debug:!0,pathApp:CRM.vars.hrjobroles.path,pathRest:CRM.url("civicrm/ajax/rest"),pathBaseUrl:CRM.vars.hrjobroles.baseURL+"/",pathTpl:"views/",pathIncludeTpl:"views/include/"})}),define("job-roles/controllers/job-roles.controller",["common/angular","common/lodash","common/moment"],function(e,t,n){"use strict";function r(r,a,o,i,s,l,u,c,d,f,m,p,b,h,v,g){function _(e,t){void 0===ye.editData[e]&&(ye.editData[e]={}),"cost_centre"===t?(void 0!==ye.editData[e].cost_centers&&ye.editData[e].cost_centers instanceof Array||(ye.editData[e].cost_centers=[]),ye.editData[e].cost_centers.push({id:ye.editData[e].cost_centers.length+1,cost_centre_id:"",type:"1",percentage:"0",amount:"0"})):(void 0!==ye.editData[e].funders&&ye.editData[e].funders instanceof Array||(ye.editData[e].funders=[]),ye.editData[e].funders.push({id:ye.editData[e].funders.length+1,funder_id:"",type:"1",percentage:"0",amount:"0"}))}function $(){ye.add_new=!0}function w(){ye.add_new=!1,delete ye.editData.new_role_id}function y(e,t){ye.viewTab[e]=t}function D(t,n){P(t)&&(t=null),P(n)&&(n=null);var r=!0;return!!t&&(e.forEach(ye.contractsData,function(e){ge(t)===ge(e.start_date)&&ge(n)===ge(e.end_date)&&(r=!1)}),r)}function E(){return void 0===ye.editData.new_role_id||void 0===ye.editData.new_role_id.title||""===ye.editData.new_role_id.title||void 0===ye.editData.new_role_id.job_contract_id||""===ye.editData.new_role_id.job_contract_id}function j(e){ye.collapsedRows[e]=!ye.collapsedRows[e]}function C(e){return v.getContracts(e).then(function(e){for(var t=[],n={},r=0;r-1&&t.start.push(e),r.indexOf("end_date")>-1&&t.end.push(e)}),b.validate(e.start,e.end,e.contractStart,e.contractEnd),0===n}function he(e){e.start_date.$error.custom=[],e.end_date.$error.custom=[];var t=J(e.contract.$viewValue);return void 0===t?"Contract is missing":!!be({start:e.start_date.$viewValue,end:e.end_date.$viewValue,contractStart:t.start_date,contractEnd:t.end_date},{start:e.start_date.$error.custom,end:e.end_date.$error.custom})||"Error"}function ve(e){if("title"===e||" "===e)return"Title cannot be title!"}a.debug("Controller: JobRolesController");var ge=r("formatDate"),_e={},$e=r("getActiveValues"),we=["funders","cost_centers"],ye=this;ye.contactId=m.contactId,ye.format=p.DATE_FORMAT,ye.loading=!0,ye.pastJobRoles=[],ye.presentJobRoles=[],ye.collapsedRows=[],ye.contactList=[],ye.editData={},ye.viewTab=[],ye.CalendarShow=[],ye.contractsData=[],ye.DepartmentsData={},ye.LevelsData={},ye.LocationsData={},ye.RegionsData={},ye.addNewRoleUrl=m.pathBaseUrl+m.pathIncludeTpl+"add_new_role.html",ye.jobRolePanelUrl=m.pathBaseUrl+m.pathIncludeTpl+"job_role_panel.html",ye.rowTypes={},ye.rowTypes[0]={id:0,name:"Fixed"},ye.rowTypes[1]={id:1,name:"%"},ye.addAdditionalRow=_,ye.addNewRole=$,ye.cancelNewRole=w,ye.changeTab=y,ye.checkIfDatesAreCustom=D,ye.checkNewRole=E,ye.collapseRow=j,ye.deleteAdditionalRow=F,ye.dpOpen=A,ye.getContactList=k,ye.getCostLabel=L,ye.initData=B,ye.isChanged=H,ye.isOpen=V,ye.isRowCollapsed=Y,ye.isTab=G,ye.onAfterSave=K,ye.onCancel=Z,ye.onContractEdited=X,ye.onContractSelected=Q,ye.open=ee,ye.removeRole=ne,ye.saveNewRole=re,ye.select=ae,ye.showRowType=oe,ye.showSave=ie,ye.status="",ye.today=le,ye.updateAdditionalRowType=ue,ye.updateRole=me,ye.validateRole=he,ye.validateTitle=ve,function(){se(),ye.today(),o.all([I(),M(ye.contactId),ye.getContactList()]).then(function(){ye.loading=!1})}()}return r.__name="JobRolesController",r.$inject=["$filter","$log","$q","$rootElement","$route","$routeParams","$scope","$timeout","$uibModal","DOMEventTrigger","settings","HR_settings","dateValidation","filtersService","jobRoleService","pubSub"],r}),define("job-roles/controllers/modal-dialog.controller",[],function(){"use strict";function e(e,t,n,r){function a(){e.dismiss("Cancel")}function o(t){e.close(t||!0)}t.debug("Controller: ModalDialogController");var i=this;i.copyCancel=r.copyCancel||"Cancel",i.copyConfirm=r.copyConfirm||"Yes",i.msg=r.msg||"",i.title=r.title||"CiviHR Job Roles",i.cancel=a,i.confirm=o}return e.__name="ModalDialogController",e.$inject=["$uibModalInstance","$log","$timeout","content"],e}),define("job-roles/modules/job-roles.controllers",["common/angular","job-roles/controllers/job-roles.controller","job-roles/controllers/modal-dialog.controller"],function(e,t,n){"use strict";return e.module("hrjobroles.controllers",[]).controller(t.__name,t).controller(n.__name,n)}),angular.module("xeditable",[]).value("editableOptions",{theme:"default",buttons:"right",blurElem:"cancel",blurForm:"ignore",activate:"focus"}),angular.module("xeditable").directive("editableBsdate",["editableDirectiveFactory",function(e){return e({directiveName:"editableBsdate",inputTpl:''})}]),angular.module("xeditable").directive("editableBstime",["editableDirectiveFactory",function(e){return e({directiveName:"editableBstime",inputTpl:"",render:function(){this.parent.render.call(this);var e=angular.element('
');e.attr("ng-model",this.inputEl.attr("ng-model")),this.inputEl.removeAttr("ng-model"),this.attrs.eNgChange&&(e.attr("ng-change",this.inputEl.attr("ng-change")),this.inputEl.removeAttr("ng-change")),this.inputEl.wrap(e)}})}]),angular.module("xeditable").directive("editableCheckbox",["editableDirectiveFactory",function(e){return e({directiveName:"editableCheckbox",inputTpl:'',render:function(){this.parent.render.call(this),this.attrs.eTitle&&(this.inputEl.wrap(""),this.inputEl.after(angular.element("").text(this.attrs.eTitle)))},autosubmit:function(){var e=this;e.inputEl.bind("change",function(){setTimeout(function(){e.scope.$apply(function(){e.scope.$form.$submit()})},500)})}})}]),angular.module("xeditable").directive("editableChecklist",["editableDirectiveFactory","editableNgOptionsParser",function(e,t){return e({directiveName:"editableChecklist",inputTpl:"",useCopy:!0,render:function(){this.parent.render.call(this);var e=t(this.attrs.eNgOptions),n='';this.inputEl.removeAttr("ng-model"),this.inputEl.removeAttr("ng-options"),this.inputEl.html(n)}})}]),function(){var e="text|email|tel|number|url|search|color|date|datetime|time|month|week".split("|");angular.forEach(e,function(e){var t="editable"+e.charAt(0).toUpperCase()+e.slice(1);angular.module("xeditable").directive(t,["editableDirectiveFactory",function(n){return n({directiveName:t,inputTpl:''})}])}),angular.module("xeditable").directive("editableRange",["editableDirectiveFactory",function(e){return e({directiveName:"editableRange",inputTpl:'',render:function(){this.parent.render.call(this),this.inputEl.after("{{$data}}")}})}])}(),angular.module("xeditable").directive("editableRadiolist",["editableDirectiveFactory","editableNgOptionsParser",function(e,t){return e({directiveName:"editableRadiolist",inputTpl:"",render:function(){this.parent.render.call(this);var e=t(this.attrs.eNgOptions),n='';this.inputEl.removeAttr("ng-model"),this.inputEl.removeAttr("ng-options"),this.inputEl.html(n)},autosubmit:function(){var e=this;e.inputEl.bind("change",function(){setTimeout(function(){e.scope.$apply(function(){e.scope.$form.$submit()})},500)})}})}]),angular.module("xeditable").directive("editableSelect",["editableDirectiveFactory",function(e){return e({directiveName:"editableSelect",inputTpl:"",autosubmit:function(){var e=this;e.inputEl.bind("change",function(){e.scope.$apply(function(){e.scope.$form.$submit()})})}})}]),angular.module("xeditable").directive("editableTextarea",["editableDirectiveFactory",function(e){return e({directiveName:"editableTextarea",inputTpl:"",addListeners:function(){var e=this;e.parent.addListeners.call(e),e.single&&"no"!==e.buttons&&e.autosubmit()},autosubmit:function(){var e=this;e.inputEl.bind("keydown",function(t){(t.ctrlKey||t.metaKey)&&13===t.keyCode&&e.scope.$apply(function(){e.scope.$form.$submit()})})}})}]),angular.module("xeditable").factory("editableController",["$q","editableUtils",function(e,t){function n(e,n,r,a,o,i,s,l,u){var c,d,f=this;f.scope=e,f.elem=r,f.attrs=n,f.inputEl=null,f.editorEl=null,f.single=!0,f.error="",f.theme=o[i.theme]||o.default,f.parent={},f.inputTpl="",f.directiveName="",f.useCopy=!1,f.single=null,f.buttons="right",f.init=function(t){if(f.single=t,f.name=n.eName||n[f.directiveName],!n[f.directiveName])throw"You should provide value for `"+f.directiveName+"` in editable element!";c=a(n[f.directiveName]),f.buttons=f.single?f.attrs.buttons||i.buttons:"no",n.eName&&f.scope.$watch("$data",function(e){f.scope.$form.$data[n.eName]=e}),n.onshow&&(f.onshow=function(){return f.catchError(a(n.onshow)(e))}),n.onhide&&(f.onhide=function(){return a(n.onhide)(e)}),n.oncancel&&(f.oncancel=function(){return a(n.oncancel)(e)}),n.onbeforesave&&(f.onbeforesave=function(){return f.catchError(a(n.onbeforesave)(e))}),n.onaftersave&&(f.onaftersave=function(){return f.catchError(a(n.onaftersave)(e))}),e.$parent.$watch(n[f.directiveName],function(){f.handleEmpty()})},f.render=function(){var e=f.theme;f.inputEl=angular.element(f.inputTpl),f.controlsEl=angular.element(e.controlsTpl),f.controlsEl.append(f.inputEl),"no"!==f.buttons&&(f.buttonsEl=angular.element(e.buttonsTpl),f.submitEl=angular.element(e.submitTpl),f.cancelEl=angular.element(e.cancelTpl),f.buttonsEl.append(f.submitEl).append(f.cancelEl),f.controlsEl.append(f.buttonsEl),f.inputEl.addClass("editable-has-buttons")),f.errorEl=angular.element(e.errorTpl),f.controlsEl.append(f.errorEl),f.editorEl=angular.element(f.single?e.formTpl:e.noformTpl),f.editorEl.append(f.controlsEl);for(var r in n.$attr)if(!(r.length<=1)){var a=!1,o=r.substring(1,2);if("e"===r.substring(0,1)&&o===o.toUpperCase()&&"Form"!==(a=r.substring(1))&&"NgSubmit"!==a){a=a.substring(0,1).toLowerCase()+t.camelToDash(a.substring(1));var s=""===n[r]?a:n[r];f.inputEl.attr(a,s)}}f.inputEl.addClass("editable-input"),f.inputEl.attr("ng-model","$data"),f.editorEl.addClass(t.camelToDash(f.directiveName)),f.single&&(f.editorEl.attr("editable-form","$form"),f.editorEl.attr("blur",f.attrs.blur||("no"===f.buttons?"cancel":i.blurElem))),angular.isFunction(e.postrender)&&e.postrender.call(f)},f.setLocalValue=function(){f.scope.$data=f.useCopy?angular.copy(c(e.$parent)):c(e.$parent)},f.show=function(){return f.setLocalValue(),f.render(),r.after(f.editorEl),l(f.editorEl)(e),f.addListeners(),r.addClass("editable-hide"),f.onshow()},f.hide=function(){return f.editorEl.remove(),r.removeClass("editable-hide"),f.onhide()},f.cancel=function(){f.oncancel()},f.addListeners=function(){f.inputEl.bind("keyup",function(e){if(f.single)switch(e.keyCode){case 27:f.scope.$apply(function(){f.scope.$form.$cancel()})}}),f.single&&"no"===f.buttons&&f.autosubmit(),f.editorEl.bind("click",function(e){1===e.which&&f.scope.$form.$visible&&(f.scope.$form._clicked=!0)})},f.setWaiting=function(e){e?(d=!f.inputEl.attr("disabled")&&!f.inputEl.attr("ng-disabled")&&!f.inputEl.attr("ng-enabled"))&&(f.inputEl.attr("disabled","disabled"),f.buttonsEl&&f.buttonsEl.find("button").attr("disabled","disabled")):d&&(f.inputEl.removeAttr("disabled"),f.buttonsEl&&f.buttonsEl.find("button").removeAttr("disabled"))},f.activate=function(){setTimeout(function(){var e=f.inputEl[0];"focus"===i.activate&&e.focus&&e.focus(),"select"===i.activate&&e.select&&e.select()},0)},f.setError=function(t){angular.isObject(t)||(e.$error=t,f.error=t)},f.catchError=function(e,t){return angular.isObject(e)&&!0!==t?u.when(e).then(angular.bind(this,function(e){this.catchError(e,!0)}),angular.bind(this,function(e){this.catchError(e,!0)})):t&&angular.isObject(e)&&e.status&&200!==e.status&&e.data&&angular.isString(e.data)?(this.setError(e.data),e=e.data):angular.isString(e)&&this.setError(e),e},f.save=function(){c.assign(e.$parent,angular.copy(f.scope.$data))},f.handleEmpty=function(){var t=c(e.$parent),n=null===t||void 0===t||""===t||angular.isArray(t)&&0===t.length;r.toggleClass("editable-empty",n)},f.autosubmit=angular.noop,f.onshow=angular.noop,f.onhide=angular.noop,f.oncancel=angular.noop,f.onbeforesave=angular.noop,f.onaftersave=angular.noop}return n.$inject=["$scope","$attrs","$element","$parse","editableThemes","editableOptions","$rootScope","$compile","$q"],n}]),angular.module("xeditable").factory("editableDirectiveFactory",["$parse","$compile","editableThemes","$rootScope","$document","editableController","editableFormController",function(e,t,n,r,a,o,i){return function(t){return{restrict:"A",scope:!0,require:[t.directiveName,"?^form"],controller:o,link:function(n,o,s,l){var u,c=l[0],d=!1;if(l[1])u=l[1],d=!0;else if(s.eForm){var f=e(s.eForm)(n);if(f)u=f,d=!0;else for(var m=0;m=0&&e.splice(n,1),t},camelToDash:function(e){var t=/[A-Z]/g;return e.replace(t,function(e,t){return(t?"-":"")+e.toLowerCase()})},dashToCamel:function(e){var t=/([\:\-\_]+(.))/g,n=/^moz([A-Z])/;return e.replace(t,function(e,t,n,r){return r?n.toUpperCase():n}).replace(n,"Moz$1")}}}]),angular.module("xeditable").factory("editableNgOptionsParser",[function(){function e(e){var n;if(!(n=e.match(t)))throw"ng-options parse error";var r,a=n[2]||n[1],o=n[4]||n[6],i=n[5],s=(n[3],n[2]?n[1]:o),l=n[7],u=n[8],c=u?n[8]:null;return void 0===i?(r=o+" in "+l,void 0!==u&&(r+=" track by "+c)):r="("+i+", "+o+") in "+l,{ngRepeat:r,locals:{valueName:o,keyName:i,valueFn:s,displayFn:a}}}var t=/^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+(.*?)(?:\s+track\s+by\s+(.*?))?$/;return e}]),angular.module("xeditable").factory("editableThemes",function(){return{default:{formTpl:'
',noformTpl:'',controlsTpl:'',inputTpl:"",errorTpl:'
',buttonsTpl:'',submitTpl:'',cancelTpl:''},bs2:{formTpl:'
',noformTpl:'',controlsTpl:'
',inputTpl:"",errorTpl:'
',buttonsTpl:'',submitTpl:'',cancelTpl:''},bs3:{formTpl:'
', -noformTpl:'',controlsTpl:'
',inputTpl:"",errorTpl:'
',buttonsTpl:'',submitTpl:'',cancelTpl:'',buttonsClass:"",inputClass:"",postrender:function(){switch(this.directiveName){case"editableText":case"editableSelect":case"editableTextarea":case"editableEmail":case"editableTel":case"editableNumber":case"editableUrl":case"editableSearch":case"editableDate":case"editableDatetime":case"editableTime":case"editableMonth":case"editableWeek":if(this.inputEl.addClass("form-control"),this.theme.inputClass){if(this.inputEl.attr("multiple")&&("input-sm"===this.theme.inputClass||"input-lg"===this.theme.inputClass))break;this.inputEl.addClass(this.theme.inputClass)}}this.buttonsEl&&this.theme.buttonsClass&&this.buttonsEl.find("button").addClass(this.theme.buttonsClass)}}}}),function(e,t,n){"use strict";function r(e){return F(e)?e:Object.keys(e).map(function(t){return e[t]})}function a(e){return null===e}function o(e,t){return-1==Object.keys(e).map(function(r){return t[r]!==n&&t[r]==e[r]}).indexOf(!1)}function i(e,t){if(""===t)return e;var n=e.indexOf(t.charAt(0));return-1!==n&&i(e.substr(n+1),t.substr(1))}function s(e,t,n){var r=0;return e.filter(function(e){var a=D(n)?t>r&&n(e):t>r;return r=a?r+1:r,a})}function l(e,t,n){return n.round(e*n.pow(10,t))/n.pow(10,t)}function u(e,t,n){return t=t||[],Object.keys(e).forEach(function(r){if(T(e[r])&&!F(e[r])){var a=n?n+"."+r:n;u(e[r],t,a||r)}else{var o=n?n+"."+r:r;t.push(o)}}),t}function c(e){return e&&e.$evalAsync&&e.$watch}function d(){return function(e,t){return e>t}}function f(){return function(e,t){return e>=t}}function m(){return function(e,t){return t>e}}function p(){return function(e,t){return t>=e}}function b(){return function(e,t){return e==t}}function h(){return function(e,t){return e!=t}}function v(){return function(e,t){return e===t}}function g(){return function(e,t){return e!==t}}function _(e){return function(t,n){return t=T(t)?r(t):t,!(!F(t)||E(n))&&t.some(function(t){return T(t)||j(n)?e(n)(t):t===n})}}function $(e,t){return t=t||0,t>=e.length?e:F(e[t])?$(e.slice(0,t).concat(e[t],e.slice(t+1)),t):$(e,t+1)}function w(e){return function(t,n){function a(e,t){return!E(t)&&e.some(function(e){return N(e,t)})}if(t=T(t)?r(t):t,!F(t))return t;var o=[],i=e(n);return t.filter(E(n)?function(e,t,n){return n.indexOf(e)===t}:function(e){var t=i(e);return!a(o,t)&&(o.push(t),!0)})}}function y(e,t,n){return t?e+n+y(e,--t,n):e}var D=t.isDefined,E=t.isUndefined,j=t.isFunction,C=t.isString,R=t.isNumber,T=t.isObject,F=t.isArray,x=t.forEach,A=t.extend,S=t.copy,N=t.equals;String.prototype.contains||(String.prototype.contains=function(){return-1!==String.prototype.indexOf.apply(this,arguments)}),t.module("a8m.angular",[]).filter("isUndefined",function(){return function(e){return t.isUndefined(e)}}).filter("isDefined",function(){return function(e){return t.isDefined(e)}}).filter("isFunction",function(){return function(e){return t.isFunction(e)}}).filter("isString",function(){return function(e){return t.isString(e)}}).filter("isNumber",function(){return function(e){return t.isNumber(e)}}).filter("isArray",function(){return function(e){return t.isArray(e)}}).filter("isObject",function(){return function(e){return t.isObject(e)}}).filter("isEqual",function(){return function(e,n){return t.equals(e,n)}}),t.module("a8m.conditions",[]).filter({isGreaterThan:d,">":d,isGreaterThanOrEqualTo:f,">=":f,isLessThan:m,"<":m,isLessThanOrEqualTo:p,"<=":p,isEqualTo:b,"==":b,isNotEqualTo:h,"!=":h,isIdenticalTo:v,"===":v,isNotIdenticalTo:g,"!==":g}),t.module("a8m.is-null",[]).filter("isNull",function(){return function(e){return a(e)}}),t.module("a8m.after-where",[]).filter("afterWhere",function(){return function(e,t){if(e=T(e)?r(e):e,!F(e)||E(t))return e;var n=e.map(function(e){return o(t,e)}).indexOf(!0);return e.slice(-1===n?0:n)}}),t.module("a8m.after",[]).filter("after",function(){return function(e,t){return e=T(e)?r(e):e,F(e)?e.slice(t):e}}),t.module("a8m.before-where",[]).filter("beforeWhere",function(){return function(e,t){if(e=T(e)?r(e):e,!F(e)||E(t))return e;var n=e.map(function(e){return o(t,e)}).indexOf(!0);return e.slice(0,-1===n?e.length:++n)}}),t.module("a8m.before",[]).filter("before",function(){return function(e,t){return e=T(e)?r(e):e,F(e)?e.slice(0,t?--t:t):e}}),t.module("a8m.concat",[]).filter("concat",[function(){return function(e,t){if(E(t))return e;if(F(e))return e.concat(T(t)?r(t):t);if(T(e)){return r(e).concat(T(t)?r(t):t)}return e}}]),t.module("a8m.contains",[]).filter({contains:["$parse",_],some:["$parse",_]}),t.module("a8m.count-by",[]).filter("countBy",["$parse",function(e){return function(t,n){var a,o={},i=e(n);return t=T(t)?r(t):t,!F(t)||E(n)?t:(t.forEach(function(e){a=i(e),o[a]||(o[a]=0),o[a]++}),o)}}]),t.module("a8m.defaults",[]).filter("defaults",["$parse",function(e){return function(t,n){if(t=T(t)?r(t):t,!F(t)||!T(n))return t;var a=u(n);return t.forEach(function(t){a.forEach(function(r){var a=e(r),o=a.assign;E(a(t))&&o(t,a(n))})}),t}}]),t.module("a8m.every",[]).filter("every",["$parse",function(e){return function(t,n){return t=T(t)?r(t):t,!(F(t)&&!E(n))||t.every(function(t){return T(t)||j(n)?e(n)(t):t===n})}}]),t.module("a8m.filter-by",[]).filter("filterBy",["$parse",function(e){return function(t,a,o){var i;return o=C(o)||R(o)?String(o).toLowerCase():n,t=T(t)?r(t):t,!F(t)||E(o)?t:t.filter(function(t){return a.some(function(n){if(~n.indexOf("+")){var r=n.replace(new RegExp("\\s","g"),"").split("+");i=r.reduce(function(n,r,a){return 1===a?e(n)(t)+" "+e(r)(t):n+" "+e(r)(t)})}else i=e(n)(t);return!(!C(i)&&!R(i))&&String(i).toLowerCase().contains(o)})})}}]),t.module("a8m.first",[]).filter("first",["$parse",function(e){return function(t){var a,o,i;return t=T(t)?r(t):t,F(t)?(i=Array.prototype.slice.call(arguments,1),a=R(i[0])?i[0]:1,o=R(i[0])?R(i[1])?n:i[1]:i[0],i.length?s(t,a,o?e(o):o):t[0]):t}}]),t.module("a8m.flatten",[]).filter("flatten",function(){return function(e,t){return t=t||!1,e=T(e)?r(e):e,F(e)?t?[].concat.apply([],e):$(e,0):e}}),t.module("a8m.fuzzy-by",[]).filter("fuzzyBy",["$parse",function(e){return function(t,n,a,o){var s,l,u=o||!1;return t=T(t)?r(t):t,!F(t)||E(n)||E(a)?t:(l=e(n),t.filter(function(e){return s=l(e),!!C(s)&&(s=u?s:s.toLowerCase(),a=u?a:a.toLowerCase(),!1!==i(s,a))}))}}]),t.module("a8m.fuzzy",[]).filter("fuzzy",function(){return function(e,t,n){function a(e,t){var n,r;return 0=0&&R(t)&&isFinite(t)?1024>t?l(t,n,e)+" B":1048576>t?l(t/1024,n,e)+" KB":1073741824>t?l(t/1048576,n,e)+" MB":l(t/1073741824,n,e)+" GB":"NaN"}}]),t.module("a8m.math.degrees",["a8m.math"]).filter("degrees",["$math",function(e){return function(t,n){if(R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)){var r=180*t/e.PI;return e.round(r*e.pow(10,n))/e.pow(10,n)}return"NaN"}}]),t.module("a8m.math.kbFmt",["a8m.math"]).filter("kbFmt",["$math",function(e){return function(t,n){return R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)?1024>t?l(t,n,e)+" KB":1048576>t?l(t/1024,n,e)+" MB":l(t/1048576,n,e)+" GB":"NaN"}}]),t.module("a8m.math",[]).factory("$math",["$window",function(e){return e.Math}]),t.module("a8m.math.max",["a8m.math"]).filter("max",["$math","$parse",function(e,t){function n(n,r){var a=n.map(function(e){return t(r)(e)});return a.indexOf(e.max.apply(e,a))}return function(t,r){return F(t)?E(r)?e.max.apply(e,t):t[n(t,r)]:t}}]),t.module("a8m.math.min",["a8m.math"]).filter("min",["$math","$parse",function(e,t){function n(n,r){var a=n.map(function(e){return t(r)(e)});return a.indexOf(e.min.apply(e,a))}return function(t,r){return F(t)?E(r)?e.min.apply(e,t):t[n(t,r)]:t}}]),t.module("a8m.math.percent",["a8m.math"]).filter("percent",["$math","$window",function(e,t){return function(n,r,a){var o=C(n)?t.Number(n):n;return r=r||100,a=a||!1,!R(o)||t.isNaN(o)?n:a?e.round(o/r*100):o/r*100}}]),t.module("a8m.math.radians",["a8m.math"]).filter("radians",["$math",function(e){return function(t,n){if(R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)){var r=3.14159265359*t/180;return e.round(r*e.pow(10,n))/e.pow(10,n)}return"NaN"}}]),t.module("a8m.math.radix",[]).filter("radix",function(){return function(e,t){var n=/^[2-9]$|^[1-2]\d$|^3[0-6]$/;return R(e)&&n.test(t)?e.toString(t).toUpperCase():e}}),t.module("a8m.math.shortFmt",["a8m.math"]).filter("shortFmt",["$math",function(e){return function(t,n){return R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)?1e3>t?t:1e6>t?l(t/1e3,n,e)+" K":1e9>t?l(t/1e6,n,e)+" M":l(t/1e9,n,e)+" B":"NaN"}}]),t.module("a8m.math.sum",[]).filter("sum",function(){return function(e,t){return F(e)?e.reduce(function(e,t){return e+t},t||0):e}}),t.module("a8m.ends-with",[]).filter("endsWith",function(){return function(e,t,n){var r,a=n||!1;return!C(e)||E(t)?e:(e=a?e:e.toLowerCase(),r=e.length-t.length,-1!==e.indexOf(a?t:t.toLowerCase(),r))}}),t.module("a8m.latinize",[]).filter("latinize",[function(){function e(e){return e.replace(/[^\u0000-\u007E]/g,function(e){return n[e]||e})}for(var t=[{base:"A",letters:"AⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ"},{base:"AA",letters:"Ꜳ"},{base:"AE",letters:"ÆǼǢ"},{base:"AO",letters:"Ꜵ"},{base:"AU",letters:"Ꜷ"},{base:"AV",letters:"ꜸꜺ"},{base:"AY",letters:"Ꜽ"},{base:"B",letters:"BⒷBḂḄḆɃƂƁ"},{base:"C",letters:"CⒸCĆĈĊČÇḈƇȻꜾ"},{base:"D",letters:"DⒹDḊĎḌḐḒḎĐƋƊƉꝹ"},{base:"DZ",letters:"DZDŽ"},{base:"Dz",letters:"DzDž"},{base:"E",letters:"EⒺEÈÉÊỀẾỄỂẼĒḔḖĔĖËẺĚȄȆẸỆȨḜĘḘḚƐƎ"},{base:"F",letters:"FⒻFḞƑꝻ"},{base:"G",letters:"GⒼGǴĜḠĞĠǦĢǤƓꞠꝽꝾ"},{base:"H",letters:"HⒽHĤḢḦȞḤḨḪĦⱧⱵꞍ"},{base:"I",letters:"IⒾIÌÍÎĨĪĬİÏḮỈǏȈȊỊĮḬƗ"},{base:"J",letters:"JⒿJĴɈ"},{base:"K",letters:"KⓀKḰǨḲĶḴƘⱩꝀꝂꝄꞢ"},{base:"L",letters:"LⓁLĿĹĽḶḸĻḼḺŁȽⱢⱠꝈꝆꞀ"},{base:"LJ",letters:"LJ"},{base:"Lj",letters:"Lj"},{base:"M",letters:"MⓂMḾṀṂⱮƜ"},{base:"N",letters:"NⓃNǸŃÑṄŇṆŅṊṈȠƝꞐꞤ"},{base:"NJ",letters:"NJ"},{base:"Nj",letters:"Nj"},{base:"O",letters:"OⓄOÒÓÔỒỐỖỔÕṌȬṎŌṐṒŎȮȰÖȪỎŐǑȌȎƠỜỚỠỞỢỌỘǪǬØǾƆƟꝊꝌ"},{base:"OI",letters:"Ƣ"},{base:"OO",letters:"Ꝏ"},{base:"OU",letters:"Ȣ"},{base:"OE",letters:"ŒŒ"},{base:"oe",letters:"œœ"},{base:"P",letters:"PⓅPṔṖƤⱣꝐꝒꝔ"},{base:"Q",letters:"QⓆQꝖꝘɊ"},{base:"R",letters:"RⓇRŔṘŘȐȒṚṜŖṞɌⱤꝚꞦꞂ"},{base:"S",letters:"SⓈSẞŚṤŜṠŠṦṢṨȘŞⱾꞨꞄ"},{base:"T",letters:"TⓉTṪŤṬȚŢṰṮŦƬƮȾꞆ"},{base:"TZ",letters:"Ꜩ"},{base:"U",letters:"UⓊUÙÚÛŨṸŪṺŬÜǛǗǕǙỦŮŰǓȔȖƯỪỨỮỬỰỤṲŲṶṴɄ"},{base:"V",letters:"VⓋVṼṾƲꝞɅ"},{base:"VY",letters:"Ꝡ"},{base:"W",letters:"WⓌWẀẂŴẆẄẈⱲ"},{base:"X",letters:"XⓍXẊẌ"},{base:"Y",letters:"YⓎYỲÝŶỸȲẎŸỶỴƳɎỾ"},{base:"Z",letters:"ZⓏZŹẐŻŽẒẔƵȤⱿⱫꝢ"},{base:"a",letters:"aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐ"},{base:"aa",letters:"ꜳ"},{base:"ae",letters:"æǽǣ"},{base:"ao",letters:"ꜵ"},{base:"au",letters:"ꜷ"},{base:"av",letters:"ꜹꜻ"},{base:"ay",letters:"ꜽ"},{base:"b",letters:"bⓑbḃḅḇƀƃɓ"},{base:"c",letters:"cⓒcćĉċčçḉƈȼꜿↄ"},{base:"d",letters:"dⓓdḋďḍḑḓḏđƌɖɗꝺ"},{base:"dz",letters:"dzdž"},{base:"e",letters:"eⓔeèéêềếễểẽēḕḗĕėëẻěȅȇẹệȩḝęḙḛɇɛǝ"},{base:"f",letters:"fⓕfḟƒꝼ"},{base:"g",letters:"gⓖgǵĝḡğġǧģǥɠꞡᵹꝿ"},{base:"h",letters:"hⓗhĥḣḧȟḥḩḫẖħⱨⱶɥ"},{base:"hv",letters:"ƕ"},{base:"i",letters:"iⓘiìíîĩīĭïḯỉǐȉȋịįḭɨı"},{base:"j",letters:"jⓙjĵǰɉ"},{base:"k",letters:"kⓚkḱǩḳķḵƙⱪꝁꝃꝅꞣ"},{base:"l",letters:"lⓛlŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇ"},{base:"lj",letters:"lj"},{base:"m",letters:"mⓜmḿṁṃɱɯ"},{base:"n",letters:"nⓝnǹńñṅňṇņṋṉƞɲʼnꞑꞥ"},{base:"nj",letters:"nj"},{base:"o",letters:"oⓞoòóôồốỗổõṍȭṏōṑṓŏȯȱöȫỏőǒȍȏơờớỡởợọộǫǭøǿɔꝋꝍɵ"},{base:"oi",letters:"ƣ"},{base:"ou",letters:"ȣ"},{base:"oo",letters:"ꝏ"},{base:"p",letters:"pⓟpṕṗƥᵽꝑꝓꝕ"},{base:"q",letters:"qⓠqɋꝗꝙ"},{base:"r",letters:"rⓡrŕṙřȑȓṛṝŗṟɍɽꝛꞧꞃ"},{base:"s",letters:"sⓢsßśṥŝṡšṧṣṩșşȿꞩꞅẛ"},{base:"t",letters:"tⓣtṫẗťṭțţṱṯŧƭʈⱦꞇ"},{base:"tz",letters:"ꜩ"},{base:"u",letters:"uⓤuùúûũṹūṻŭüǜǘǖǚủůűǔȕȗưừứữửựụṳųṷṵʉ"},{base:"v",letters:"vⓥvṽṿʋꝟʌ"},{base:"vy",letters:"ꝡ"},{base:"w",letters:"wⓦwẁẃŵẇẅẘẉⱳ"},{base:"x",letters:"xⓧxẋẍ"},{base:"y",letters:"yⓨyỳýŷỹȳẏÿỷẙỵƴɏỿ"},{base:"z",letters:"zⓩzźẑżžẓẕƶȥɀⱬꝣ"}],n={},r=0;r<]*>/g,""):e}}),t.module("a8m.test",[]).filter("test",function(){return function(e,t,n){var r=new RegExp(t,n);return C(e)?r.test(e):e}}),t.module("a8m.trim",[]).filter("trim",function(){return function(e,t){var n=t||"\\s";return C(e)?e.replace(new RegExp("^"+n+"+|"+n+"+$","g"),""):e}}),t.module("a8m.truncate",[]).filter("truncate",function(){return function(e,t,n,r){return t=E(t)?e.length:t,r=r||!1,n=n||"",!C(e)||e.length<=t?e:e.substring(0,r?-1===e.indexOf(" ",t)?e.length:e.indexOf(" ",t):t)+n}}),t.module("a8m.ucfirst",[]).filter("ucfirst",[function(){return function(e){return C(e)?e.split(" ").map(function(e){return e.charAt(0).toUpperCase()+e.substring(1)}).join(" "):e}}]),t.module("a8m.uri-component-encode",[]).filter("uriComponentEncode",["$window",function(e){return function(t){return C(t)?e.encodeURIComponent(t):t}}]),t.module("a8m.uri-encode",[]).filter("uriEncode",["$window",function(e){return function(t){return C(t)?e.encodeURI(t):t}}]),t.module("a8m.wrap",[]).filter("wrap",function(){return function(e,t,n){return C(e)&&D(t)?[t,e,n||t].join(""):e}}),t.module("a8m.filter-watcher",[]).provider("filterWatcher",function(){this.$get=["$window","$rootScope",function(e,n){function r(e,n){return[e,t.toJson(n)].join("#").replace(/"/g,"")}function a(e){var t=e.targetScope.$id;x(d[t],function(e){delete u[e]}),delete d[t]}function o(){f(function(){n.$$phase||(u={})})}function i(e,t){var n=e.$id;return E(d[n])&&(e.$on("$destroy",a),d[n]=[]),d[n].push(t)}function s(e,t){var n=r(e,t);return u[n]}function l(e,t,n,a){var s=r(e,t);return u[s]=a,c(n)?i(n,s):o(),a}var u={},d={},f=e.setTimeout;return{isMemoized:s,memoize:l}}]}),t.module("angular.filter",["a8m.ucfirst","a8m.uri-encode","a8m.uri-component-encode","a8m.slugify","a8m.latinize","a8m.strip-tags","a8m.stringular","a8m.truncate","a8m.starts-with","a8m.ends-with","a8m.wrap","a8m.trim","a8m.ltrim","a8m.rtrim","a8m.repeat","a8m.test","a8m.match","a8m.to-array","a8m.concat","a8m.contains","a8m.unique","a8m.is-empty","a8m.after","a8m.after-where","a8m.before","a8m.before-where","a8m.defaults","a8m.where","a8m.reverse","a8m.remove","a8m.remove-with","a8m.group-by","a8m.count-by","a8m.search-field","a8m.fuzzy-by","a8m.fuzzy","a8m.omit","a8m.pick","a8m.every","a8m.filter-by","a8m.xor","a8m.map","a8m.first","a8m.last","a8m.flatten","a8m.join","a8m.math","a8m.math.max","a8m.math.min","a8m.math.percent","a8m.math.radix","a8m.math.sum","a8m.math.degrees","a8m.math.radians","a8m.math.byteFmt","a8m.math.kbFmt","a8m.math.shortFmt","a8m.angular","a8m.conditions","a8m.is-null","a8m.filter-watcher"])}(window,window.angular),define("job-roles/modules/job-roles.core",["common/angular","common/ui-select","common/directives/angular-date/date-input","common/modules/directives","common/modules/routers/compu-ng-route","common/filters/angular-date/format-date","common/services/angular-date/date-format","common/services/dom-event-trigger","common/services/pub-sub","job-roles/vendor/angular-editable","job-roles/vendor/angular-filter"],function(e){"use strict";e.module("hrjobroles.core",["angular.filter","ngAnimate","ngSanitize","ngResource","ui.bootstrap","ui.select","xeditable","common.angularDate","common.directives","common.services","compuNgRoute"])}),define("job-roles/filters/get-active-values.filter",["common/lodash"],function(e){"use strict";function t(t){return t.debug("Filter: getActiveValues"),function(t){var n={};return e.each(t,function(e,t){"1"===e.is_active&&(n[t]=e)}),n}}return t.__name="getActiveValues",t.$inject=["$log"],t}),define("job-roles/modules/job-roles.filters",["common/angular","job-roles/filters/get-active-values.filter"],function(e,t){"use strict";return e.module("hrjobroles.filters",[]).filter(t.__name,t)}),define("job-roles/modules/job-roles.run",["common/angular"],function(e){"use strict";function t(e,t,n,r){n.theme="bs3",t.contactId=r.contactId,t.pathBaseUrl=r.pathBaseUrl,t.pathTpl=r.pathTpl,t.pathIncludeTpl=r.pathIncludeTpl,t.prefix=r.classNamePrefix}e.module("hrjobroles.run",["hrjobroles.constants"]).run(t),t.$inject=["$q","$rootScope","editableOptions","settings"]}),define("job-roles/services/date-validation.service",["common/moment"],function(e){function t(t){function n(e,t){e.isValid()||l("Date is not valid!!",t)}function r(e,t){e.isSameOrAfter(t)&&l("Start Date cannot be the same as or after the End Date.",["start_date","end_date"])}function a(e,t){e.isBefore(t)&&l("Start Date cannot be lower than Contract Start Date.",["start_date"])}function o(e,t){e.isAfter(t)&&l("Start Date cannot be higher than Contract End Date.",["start_date"])}function i(e,t){e.isAfter(t)&&l("End Date cannot be higher than Contract End Date.",["end_date"])}function s(t,n){return t instanceof Date&&(t=e(t).valueOf()),e(t,n,!0).startOf("day")}var l=function(e,t){throw new Error(e,t[0])},u={dateFormats:["x","YYYY-MM-DD"],setErrorCallback:function(e){if("function"!=typeof e)throw new TypeError("Error callback must be a function.");l=e},validate:function(e,t,l,u){e=s(e,this.dateFormats),l=s(l,this.dateFormats),u=s(u,this.dateFormats),n(e,["start_date"]),o(e,u),a(e,l),(0===t||t)&&(t=s(t,this.dateFormats),n(t,["end_date"]),i(t,u),r(e,t))}};return t.DATE_FORMAT&&u.dateFormats.push(t.DATE_FORMAT.toUpperCase()),u}return t.__name="dateValidation",t.$inject=["HR_settings"],t}),define("job-roles/services/filters.service",[],function(){"use strict";function e(){return{isNotUndefined:function(e){try{return e.constructor===Array?e.filter(function(e){return"undefined"!==e&&void 0!==e}):e}catch(t){return e}},issetCostCentre:function(e){try{return e.constructor===Array?e.filter(function(e){return""!==e.cost_centre_id&&("1"===e.type&&parseInt(e.percentage)>0||"0"===e.type&&parseInt(e.amount)>0)}):e}catch(t){return e}},issetFunder:function(e){try{return e.constructor===Array?e.filter(function(e){return""!==e.funder_id&&("1"===e.type&&parseInt(e.percentage)>0||"0"===e.type&&parseInt(e.amount)>0)}):e}catch(t){return e}}}}return e.__name="filtersService",e}),define("job-roles/services/job-role.service",["common/lodash"],function(e){"use strict";function t(t,n,r){function a(n){var r=n["api.HRJobContractRevision.get"].values;delete n["api.HRJobContractRevision.get"],n.revisions=e.compact(r.map(function(e){var r=e["api.HRJobDetails.getsingle"];return r.period_start_date===n.period_start_date&&r.period_end_date===n.period_end_date?null:(r.period_start_date=t("formatDate")(r.period_start_date),r.period_end_date=t("formatDate")(r.period_end_date),r)}))}return{getContracts:function(e){var t=r.defer();return CRM.api3("HRJobContract","get",{sequential:1,contact_id:e,deleted:0,return:"title,period_end_date,period_start_date","api.HRJobContractRevision.get":{jobcontract_id:"$value.id","api.HRJobDetails.getsingle":{jobcontract_revision_id:"$value.id"}}}).done(function(e){e.values.forEach(a),t.resolve(e)}).error(function(){t.reject("An error occured while fetching items")}),t.promise},getAllJobRoles:function(e){var t=r.defer();return CRM.api3("HrJobRoles","get",{sequential:1,return:"id,job_contract_id,title,description,status,funder,funder_val_type,percent_pay_funder,amount_pay_funder,cost_center,cost_center_val_type,percent_pay_cost_center,amount_pay_cost_center,level_type,location,region,department,end_date,start_date",job_contract_id:{IN:e}}).done(function(e){t.resolve(e)}).error(function(e){t.reject("An error occured while fetching items")}),t.promise},deleteJobRole:function(e){var t=r.defer();return CRM.api3("HrJobRoles","delete",{sequential:1,id:e}).done(function(e){t.resolve(e)}).error(function(e){t.reject("An error occured while deleting items")}),t.promise},createJobRole:function(e){var t="|",n="|",a="|",o="|",i="|",s="|",l="|",u="|";if(void 0!==e.funders)for(var c=0,d=e.funders.length;c-1&&t.start.push(e),r.indexOf("end_date")>-1&&t.end.push(e)}),b.validate(e.start,e.end,e.contractStart,e.contractEnd),0===n}function ve(e){e.start_date.$error.custom=[],e.end_date.$error.custom=[];var t=J(e.contract.$viewValue);return void 0===t?"Contract is missing":!!he({start:e.start_date.$viewValue,end:e.end_date.$viewValue,contractStart:t.start_date,contractEnd:t.end_date},{start:e.start_date.$error.custom,end:e.end_date.$error.custom})||"Error"}function ge(e){if("title"===e||" "===e)return"Title cannot be title!"}a.debug("Controller: JobRolesController");var _e=r("formatDate"),$e={},we=r("getActiveValues"),ye=["funders","cost_centers"],De=this;De.contactId=m.contactId,De.format=p.DATE_FORMAT,De.loading=!0,De.pastJobRoles=[],De.presentJobRoles=[],De.collapsedRows=[],De.contactList=[],De.editData={},De.viewTab=[],De.CalendarShow=[],De.contractsData=[],De.DepartmentsData={},De.LevelsData={},De.LocationsData={},De.RegionsData={},De.addNewRoleUrl=m.pathBaseUrl+m.pathIncludeTpl+"add_new_role.html",De.jobRolePanelUrl=m.pathBaseUrl+m.pathIncludeTpl+"job_role_panel.html",De.rowTypes={},De.rowTypes[0]={id:0,name:"Fixed"},De.rowTypes[1]={id:1,name:"%"},De.addAdditionalRow=_,De.addNewRole=$,De.cancelNewRole=w,De.changeTab=y,De.checkIfDatesAreCustom=D,De.checkNewRole=E,De.collapseRow=j,De.deleteAdditionalRow=F,De.dpOpen=A,De.getContactList=k,De.getCostLabel=L,De.initData=z,De.isChanged=P,De.isOpen=Y,De.isRowCollapsed=G,De.isTab=K,De.onAfterSave=Z,De.onCancel=X,De.onContractEdited=Q,De.onContractSelected=ee,De.open=te,De.removeRole=re,De.saveNewRole=ae,De.select=oe,De.showRowType=ie,De.showSave=se,De.status="",De.today=ue,De.updateAdditionalRowType=ce,De.updateRole=pe,De.validateRole=ve,De.validateTitle=ge,function(){le(),De.today(),o.all([q(),M(De.contactId),De.getContactList()]).then(function(){De.loading=!1})}()}return r.__name="JobRolesController",r.$inject=["$filter","$log","$q","$rootElement","$route","$routeParams","$scope","$timeout","$uibModal","DOMEventTrigger","settings","HR_settings","dateValidation","filtersService","jobRoleService","pubSub"],r}),define("job-roles/controllers/modal-dialog.controller",[],function(){"use strict";function e(e,t,n,r){function a(){e.dismiss("Cancel")}function o(t){e.close(t||!0)}t.debug("Controller: ModalDialogController");var i=this;i.copyCancel=r.copyCancel||"Cancel",i.copyConfirm=r.copyConfirm||"Yes",i.msg=r.msg||"",i.title=r.title||"CiviHR Job Roles",i.cancel=a,i.confirm=o}return e.__name="ModalDialogController",e.$inject=["$uibModalInstance","$log","$timeout","content"],e}),define("job-roles/modules/job-roles.controllers",["common/angular","job-roles/controllers/job-roles.controller","job-roles/controllers/modal-dialog.controller"],function(e,t,n){"use strict";return e.module("hrjobroles.controllers",[]).controller(t.__name,t).controller(n.__name,n)}),angular.module("xeditable",[]).value("editableOptions",{theme:"default",buttons:"right",blurElem:"cancel",blurForm:"ignore",activate:"focus"}),angular.module("xeditable").directive("editableBsdate",["editableDirectiveFactory",function(e){return e({directiveName:"editableBsdate",inputTpl:''})}]),angular.module("xeditable").directive("editableBstime",["editableDirectiveFactory",function(e){return e({directiveName:"editableBstime",inputTpl:"",render:function(){this.parent.render.call(this);var e=angular.element('
');e.attr("ng-model",this.inputEl.attr("ng-model")),this.inputEl.removeAttr("ng-model"),this.attrs.eNgChange&&(e.attr("ng-change",this.inputEl.attr("ng-change")),this.inputEl.removeAttr("ng-change")),this.inputEl.wrap(e)}})}]),angular.module("xeditable").directive("editableCheckbox",["editableDirectiveFactory",function(e){return e({directiveName:"editableCheckbox",inputTpl:'',render:function(){this.parent.render.call(this),this.attrs.eTitle&&(this.inputEl.wrap(""),this.inputEl.after(angular.element("").text(this.attrs.eTitle)))},autosubmit:function(){var e=this;e.inputEl.bind("change",function(){setTimeout(function(){e.scope.$apply(function(){e.scope.$form.$submit()})},500)})}})}]),angular.module("xeditable").directive("editableChecklist",["editableDirectiveFactory","editableNgOptionsParser",function(e,t){return e({directiveName:"editableChecklist",inputTpl:"",useCopy:!0,render:function(){this.parent.render.call(this);var e=t(this.attrs.eNgOptions),n='';this.inputEl.removeAttr("ng-model"),this.inputEl.removeAttr("ng-options"),this.inputEl.html(n)}})}]),function(){var e="text|email|tel|number|url|search|color|date|datetime|time|month|week".split("|");angular.forEach(e,function(e){var t="editable"+e.charAt(0).toUpperCase()+e.slice(1);angular.module("xeditable").directive(t,["editableDirectiveFactory",function(n){return n({directiveName:t,inputTpl:''})}])}),angular.module("xeditable").directive("editableRange",["editableDirectiveFactory",function(e){return e({directiveName:"editableRange",inputTpl:'',render:function(){this.parent.render.call(this),this.inputEl.after("{{$data}}")}})}])}(),angular.module("xeditable").directive("editableRadiolist",["editableDirectiveFactory","editableNgOptionsParser",function(e,t){return e({directiveName:"editableRadiolist",inputTpl:"",render:function(){this.parent.render.call(this);var e=t(this.attrs.eNgOptions),n='';this.inputEl.removeAttr("ng-model"),this.inputEl.removeAttr("ng-options"),this.inputEl.html(n)},autosubmit:function(){var e=this;e.inputEl.bind("change",function(){setTimeout(function(){e.scope.$apply(function(){e.scope.$form.$submit()})},500)})}})}]),angular.module("xeditable").directive("editableSelect",["editableDirectiveFactory",function(e){return e({directiveName:"editableSelect",inputTpl:"",autosubmit:function(){var e=this;e.inputEl.bind("change",function(){e.scope.$apply(function(){e.scope.$form.$submit()})})}})}]),angular.module("xeditable").directive("editableTextarea",["editableDirectiveFactory",function(e){return e({directiveName:"editableTextarea",inputTpl:"",addListeners:function(){var e=this;e.parent.addListeners.call(e),e.single&&"no"!==e.buttons&&e.autosubmit()},autosubmit:function(){var e=this;e.inputEl.bind("keydown",function(t){(t.ctrlKey||t.metaKey)&&13===t.keyCode&&e.scope.$apply(function(){e.scope.$form.$submit()})})}})}]),angular.module("xeditable").factory("editableController",["$q","editableUtils",function(e,t){function n(e,n,r,a,o,i,s,l,u){var c,d,f=this;f.scope=e,f.elem=r,f.attrs=n,f.inputEl=null,f.editorEl=null,f.single=!0,f.error="",f.theme=o[i.theme]||o.default,f.parent={},f.inputTpl="",f.directiveName="",f.useCopy=!1,f.single=null,f.buttons="right",f.init=function(t){if(f.single=t,f.name=n.eName||n[f.directiveName],!n[f.directiveName])throw"You should provide value for `"+f.directiveName+"` in editable element!";c=a(n[f.directiveName]),f.buttons=f.single?f.attrs.buttons||i.buttons:"no",n.eName&&f.scope.$watch("$data",function(e){f.scope.$form.$data[n.eName]=e}),n.onshow&&(f.onshow=function(){return f.catchError(a(n.onshow)(e))}),n.onhide&&(f.onhide=function(){return a(n.onhide)(e)}),n.oncancel&&(f.oncancel=function(){return a(n.oncancel)(e)}),n.onbeforesave&&(f.onbeforesave=function(){return f.catchError(a(n.onbeforesave)(e))}),n.onaftersave&&(f.onaftersave=function(){return f.catchError(a(n.onaftersave)(e))}),e.$parent.$watch(n[f.directiveName],function(){f.handleEmpty()})},f.render=function(){var e=f.theme;f.inputEl=angular.element(f.inputTpl),f.controlsEl=angular.element(e.controlsTpl),f.controlsEl.append(f.inputEl),"no"!==f.buttons&&(f.buttonsEl=angular.element(e.buttonsTpl),f.submitEl=angular.element(e.submitTpl),f.cancelEl=angular.element(e.cancelTpl),f.buttonsEl.append(f.submitEl).append(f.cancelEl),f.controlsEl.append(f.buttonsEl),f.inputEl.addClass("editable-has-buttons")),f.errorEl=angular.element(e.errorTpl),f.controlsEl.append(f.errorEl),f.editorEl=angular.element(f.single?e.formTpl:e.noformTpl),f.editorEl.append(f.controlsEl);for(var r in n.$attr)if(!(r.length<=1)){var a=!1,o=r.substring(1,2);if("e"===r.substring(0,1)&&o===o.toUpperCase()&&"Form"!==(a=r.substring(1))&&"NgSubmit"!==a){a=a.substring(0,1).toLowerCase()+t.camelToDash(a.substring(1));var s=""===n[r]?a:n[r];f.inputEl.attr(a,s)}}f.inputEl.addClass("editable-input"),f.inputEl.attr("ng-model","$data"),f.editorEl.addClass(t.camelToDash(f.directiveName)),f.single&&(f.editorEl.attr("editable-form","$form"),f.editorEl.attr("blur",f.attrs.blur||("no"===f.buttons?"cancel":i.blurElem))),angular.isFunction(e.postrender)&&e.postrender.call(f)},f.setLocalValue=function(){f.scope.$data=f.useCopy?angular.copy(c(e.$parent)):c(e.$parent)},f.show=function(){return f.setLocalValue(),f.render(),r.after(f.editorEl),l(f.editorEl)(e),f.addListeners(),r.addClass("editable-hide"),f.onshow()},f.hide=function(){return f.editorEl.remove(),r.removeClass("editable-hide"),f.onhide()},f.cancel=function(){f.oncancel()},f.addListeners=function(){f.inputEl.bind("keyup",function(e){if(f.single)switch(e.keyCode){case 27:f.scope.$apply(function(){f.scope.$form.$cancel()})}}),f.single&&"no"===f.buttons&&f.autosubmit(),f.editorEl.bind("click",function(e){1===e.which&&f.scope.$form.$visible&&(f.scope.$form._clicked=!0)})},f.setWaiting=function(e){e?(d=!f.inputEl.attr("disabled")&&!f.inputEl.attr("ng-disabled")&&!f.inputEl.attr("ng-enabled"))&&(f.inputEl.attr("disabled","disabled"),f.buttonsEl&&f.buttonsEl.find("button").attr("disabled","disabled")):d&&(f.inputEl.removeAttr("disabled"),f.buttonsEl&&f.buttonsEl.find("button").removeAttr("disabled"))},f.activate=function(){setTimeout(function(){var e=f.inputEl[0];"focus"===i.activate&&e.focus&&e.focus(),"select"===i.activate&&e.select&&e.select()},0)},f.setError=function(t){angular.isObject(t)||(e.$error=t,f.error=t)},f.catchError=function(e,t){return angular.isObject(e)&&!0!==t?u.when(e).then(angular.bind(this,function(e){this.catchError(e,!0)}),angular.bind(this,function(e){this.catchError(e,!0)})):t&&angular.isObject(e)&&e.status&&200!==e.status&&e.data&&angular.isString(e.data)?(this.setError(e.data),e=e.data):angular.isString(e)&&this.setError(e),e},f.save=function(){c.assign(e.$parent,angular.copy(f.scope.$data))},f.handleEmpty=function(){var t=c(e.$parent),n=null===t||void 0===t||""===t||angular.isArray(t)&&0===t.length;r.toggleClass("editable-empty",n)},f.autosubmit=angular.noop,f.onshow=angular.noop,f.onhide=angular.noop,f.oncancel=angular.noop,f.onbeforesave=angular.noop,f.onaftersave=angular.noop}return n.$inject=["$scope","$attrs","$element","$parse","editableThemes","editableOptions","$rootScope","$compile","$q"],n}]),angular.module("xeditable").factory("editableDirectiveFactory",["$parse","$compile","editableThemes","$rootScope","$document","editableController","editableFormController",function(e,t,n,r,a,o,i){return function(t){return{restrict:"A",scope:!0,require:[t.directiveName,"?^form"],controller:o,link:function(n,o,s,l){var u,c=l[0],d=!1;if(l[1])u=l[1],d=!0;else if(s.eForm){var f=e(s.eForm)(n);if(f)u=f,d=!0;else for(var m=0;m=0&&e.splice(n,1),t},camelToDash:function(e){var t=/[A-Z]/g;return e.replace(t,function(e,t){return(t?"-":"")+e.toLowerCase()})},dashToCamel:function(e){var t=/([\:\-\_]+(.))/g,n=/^moz([A-Z])/;return e.replace(t,function(e,t,n,r){return r?n.toUpperCase():n}).replace(n,"Moz$1")}}}]),angular.module("xeditable").factory("editableNgOptionsParser",[function(){function e(e){var n;if(!(n=e.match(t)))throw"ng-options parse error";var r,a=n[2]||n[1],o=n[4]||n[6],i=n[5],s=(n[3],n[2]?n[1]:o),l=n[7],u=n[8],c=u?n[8]:null;return void 0===i?(r=o+" in "+l,void 0!==u&&(r+=" track by "+c)):r="("+i+", "+o+") in "+l,{ngRepeat:r,locals:{valueName:o,keyName:i,valueFn:s,displayFn:a}}}var t=/^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+(.*?)(?:\s+track\s+by\s+(.*?))?$/;return e}]),angular.module("xeditable").factory("editableThemes",function(){return{default:{formTpl:'
',noformTpl:'',controlsTpl:'',inputTpl:"",errorTpl:'
',buttonsTpl:'',submitTpl:'',cancelTpl:''},bs2:{formTpl:'
',noformTpl:'',controlsTpl:'
',inputTpl:"",errorTpl:'
',buttonsTpl:'',submitTpl:'',cancelTpl:''},bs3:{ +formTpl:'
',noformTpl:'',controlsTpl:'
',inputTpl:"",errorTpl:'
',buttonsTpl:'',submitTpl:'',cancelTpl:'',buttonsClass:"",inputClass:"",postrender:function(){switch(this.directiveName){case"editableText":case"editableSelect":case"editableTextarea":case"editableEmail":case"editableTel":case"editableNumber":case"editableUrl":case"editableSearch":case"editableDate":case"editableDatetime":case"editableTime":case"editableMonth":case"editableWeek":if(this.inputEl.addClass("form-control"),this.theme.inputClass){if(this.inputEl.attr("multiple")&&("input-sm"===this.theme.inputClass||"input-lg"===this.theme.inputClass))break;this.inputEl.addClass(this.theme.inputClass)}}this.buttonsEl&&this.theme.buttonsClass&&this.buttonsEl.find("button").addClass(this.theme.buttonsClass)}}}}),function(e,t,n){"use strict";function r(e){return F(e)?e:Object.keys(e).map(function(t){return e[t]})}function a(e){return null===e}function o(e,t){return-1==Object.keys(e).map(function(r){return t[r]!==n&&t[r]==e[r]}).indexOf(!1)}function i(e,t){if(""===t)return e;var n=e.indexOf(t.charAt(0));return-1!==n&&i(e.substr(n+1),t.substr(1))}function s(e,t,n){var r=0;return e.filter(function(e){var a=D(n)?t>r&&n(e):t>r;return r=a?r+1:r,a})}function l(e,t,n){return n.round(e*n.pow(10,t))/n.pow(10,t)}function u(e,t,n){return t=t||[],Object.keys(e).forEach(function(r){if(T(e[r])&&!F(e[r])){var a=n?n+"."+r:n;u(e[r],t,a||r)}else{var o=n?n+"."+r:r;t.push(o)}}),t}function c(e){return e&&e.$evalAsync&&e.$watch}function d(){return function(e,t){return e>t}}function f(){return function(e,t){return e>=t}}function m(){return function(e,t){return t>e}}function p(){return function(e,t){return t>=e}}function b(){return function(e,t){return e==t}}function h(){return function(e,t){return e!=t}}function v(){return function(e,t){return e===t}}function g(){return function(e,t){return e!==t}}function _(e){return function(t,n){return t=T(t)?r(t):t,!(!F(t)||E(n))&&t.some(function(t){return T(t)||j(n)?e(n)(t):t===n})}}function $(e,t){return t=t||0,t>=e.length?e:F(e[t])?$(e.slice(0,t).concat(e[t],e.slice(t+1)),t):$(e,t+1)}function w(e){return function(t,n){function a(e,t){return!E(t)&&e.some(function(e){return N(e,t)})}if(t=T(t)?r(t):t,!F(t))return t;var o=[],i=e(n);return t.filter(E(n)?function(e,t,n){return n.indexOf(e)===t}:function(e){var t=i(e);return!a(o,t)&&(o.push(t),!0)})}}function y(e,t,n){return t?e+n+y(e,--t,n):e}var D=t.isDefined,E=t.isUndefined,j=t.isFunction,C=t.isString,R=t.isNumber,T=t.isObject,F=t.isArray,x=t.forEach,A=t.extend,S=t.copy,N=t.equals;String.prototype.contains||(String.prototype.contains=function(){return-1!==String.prototype.indexOf.apply(this,arguments)}),t.module("a8m.angular",[]).filter("isUndefined",function(){return function(e){return t.isUndefined(e)}}).filter("isDefined",function(){return function(e){return t.isDefined(e)}}).filter("isFunction",function(){return function(e){return t.isFunction(e)}}).filter("isString",function(){return function(e){return t.isString(e)}}).filter("isNumber",function(){return function(e){return t.isNumber(e)}}).filter("isArray",function(){return function(e){return t.isArray(e)}}).filter("isObject",function(){return function(e){return t.isObject(e)}}).filter("isEqual",function(){return function(e,n){return t.equals(e,n)}}),t.module("a8m.conditions",[]).filter({isGreaterThan:d,">":d,isGreaterThanOrEqualTo:f,">=":f,isLessThan:m,"<":m,isLessThanOrEqualTo:p,"<=":p,isEqualTo:b,"==":b,isNotEqualTo:h,"!=":h,isIdenticalTo:v,"===":v,isNotIdenticalTo:g,"!==":g}),t.module("a8m.is-null",[]).filter("isNull",function(){return function(e){return a(e)}}),t.module("a8m.after-where",[]).filter("afterWhere",function(){return function(e,t){if(e=T(e)?r(e):e,!F(e)||E(t))return e;var n=e.map(function(e){return o(t,e)}).indexOf(!0);return e.slice(-1===n?0:n)}}),t.module("a8m.after",[]).filter("after",function(){return function(e,t){return e=T(e)?r(e):e,F(e)?e.slice(t):e}}),t.module("a8m.before-where",[]).filter("beforeWhere",function(){return function(e,t){if(e=T(e)?r(e):e,!F(e)||E(t))return e;var n=e.map(function(e){return o(t,e)}).indexOf(!0);return e.slice(0,-1===n?e.length:++n)}}),t.module("a8m.before",[]).filter("before",function(){return function(e,t){return e=T(e)?r(e):e,F(e)?e.slice(0,t?--t:t):e}}),t.module("a8m.concat",[]).filter("concat",[function(){return function(e,t){if(E(t))return e;if(F(e))return e.concat(T(t)?r(t):t);if(T(e)){return r(e).concat(T(t)?r(t):t)}return e}}]),t.module("a8m.contains",[]).filter({contains:["$parse",_],some:["$parse",_]}),t.module("a8m.count-by",[]).filter("countBy",["$parse",function(e){return function(t,n){var a,o={},i=e(n);return t=T(t)?r(t):t,!F(t)||E(n)?t:(t.forEach(function(e){a=i(e),o[a]||(o[a]=0),o[a]++}),o)}}]),t.module("a8m.defaults",[]).filter("defaults",["$parse",function(e){return function(t,n){if(t=T(t)?r(t):t,!F(t)||!T(n))return t;var a=u(n);return t.forEach(function(t){a.forEach(function(r){var a=e(r),o=a.assign;E(a(t))&&o(t,a(n))})}),t}}]),t.module("a8m.every",[]).filter("every",["$parse",function(e){return function(t,n){return t=T(t)?r(t):t,!(F(t)&&!E(n))||t.every(function(t){return T(t)||j(n)?e(n)(t):t===n})}}]),t.module("a8m.filter-by",[]).filter("filterBy",["$parse",function(e){return function(t,a,o){var i;return o=C(o)||R(o)?String(o).toLowerCase():n,t=T(t)?r(t):t,!F(t)||E(o)?t:t.filter(function(t){return a.some(function(n){if(~n.indexOf("+")){var r=n.replace(new RegExp("\\s","g"),"").split("+");i=r.reduce(function(n,r,a){return 1===a?e(n)(t)+" "+e(r)(t):n+" "+e(r)(t)})}else i=e(n)(t);return!(!C(i)&&!R(i))&&String(i).toLowerCase().contains(o)})})}}]),t.module("a8m.first",[]).filter("first",["$parse",function(e){return function(t){var a,o,i;return t=T(t)?r(t):t,F(t)?(i=Array.prototype.slice.call(arguments,1),a=R(i[0])?i[0]:1,o=R(i[0])?R(i[1])?n:i[1]:i[0],i.length?s(t,a,o?e(o):o):t[0]):t}}]),t.module("a8m.flatten",[]).filter("flatten",function(){return function(e,t){return t=t||!1,e=T(e)?r(e):e,F(e)?t?[].concat.apply([],e):$(e,0):e}}),t.module("a8m.fuzzy-by",[]).filter("fuzzyBy",["$parse",function(e){return function(t,n,a,o){var s,l,u=o||!1;return t=T(t)?r(t):t,!F(t)||E(n)||E(a)?t:(l=e(n),t.filter(function(e){return s=l(e),!!C(s)&&(s=u?s:s.toLowerCase(),a=u?a:a.toLowerCase(),!1!==i(s,a))}))}}]),t.module("a8m.fuzzy",[]).filter("fuzzy",function(){return function(e,t,n){function a(e,t){var n,r;return 0=0&&R(t)&&isFinite(t)?1024>t?l(t,n,e)+" B":1048576>t?l(t/1024,n,e)+" KB":1073741824>t?l(t/1048576,n,e)+" MB":l(t/1073741824,n,e)+" GB":"NaN"}}]),t.module("a8m.math.degrees",["a8m.math"]).filter("degrees",["$math",function(e){return function(t,n){if(R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)){var r=180*t/e.PI;return e.round(r*e.pow(10,n))/e.pow(10,n)}return"NaN"}}]),t.module("a8m.math.kbFmt",["a8m.math"]).filter("kbFmt",["$math",function(e){return function(t,n){return R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)?1024>t?l(t,n,e)+" KB":1048576>t?l(t/1024,n,e)+" MB":l(t/1048576,n,e)+" GB":"NaN"}}]),t.module("a8m.math",[]).factory("$math",["$window",function(e){return e.Math}]),t.module("a8m.math.max",["a8m.math"]).filter("max",["$math","$parse",function(e,t){function n(n,r){var a=n.map(function(e){return t(r)(e)});return a.indexOf(e.max.apply(e,a))}return function(t,r){return F(t)?E(r)?e.max.apply(e,t):t[n(t,r)]:t}}]),t.module("a8m.math.min",["a8m.math"]).filter("min",["$math","$parse",function(e,t){function n(n,r){var a=n.map(function(e){return t(r)(e)});return a.indexOf(e.min.apply(e,a))}return function(t,r){return F(t)?E(r)?e.min.apply(e,t):t[n(t,r)]:t}}]),t.module("a8m.math.percent",["a8m.math"]).filter("percent",["$math","$window",function(e,t){return function(n,r,a){var o=C(n)?t.Number(n):n;return r=r||100,a=a||!1,!R(o)||t.isNaN(o)?n:a?e.round(o/r*100):o/r*100}}]),t.module("a8m.math.radians",["a8m.math"]).filter("radians",["$math",function(e){return function(t,n){if(R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)){var r=3.14159265359*t/180;return e.round(r*e.pow(10,n))/e.pow(10,n)}return"NaN"}}]),t.module("a8m.math.radix",[]).filter("radix",function(){return function(e,t){var n=/^[2-9]$|^[1-2]\d$|^3[0-6]$/;return R(e)&&n.test(t)?e.toString(t).toUpperCase():e}}),t.module("a8m.math.shortFmt",["a8m.math"]).filter("shortFmt",["$math",function(e){return function(t,n){return R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)?1e3>t?t:1e6>t?l(t/1e3,n,e)+" K":1e9>t?l(t/1e6,n,e)+" M":l(t/1e9,n,e)+" B":"NaN"}}]),t.module("a8m.math.sum",[]).filter("sum",function(){return function(e,t){return F(e)?e.reduce(function(e,t){return e+t},t||0):e}}),t.module("a8m.ends-with",[]).filter("endsWith",function(){return function(e,t,n){var r,a=n||!1;return!C(e)||E(t)?e:(e=a?e:e.toLowerCase(),r=e.length-t.length,-1!==e.indexOf(a?t:t.toLowerCase(),r))}}),t.module("a8m.latinize",[]).filter("latinize",[function(){function e(e){return e.replace(/[^\u0000-\u007E]/g,function(e){return n[e]||e})}for(var t=[{base:"A",letters:"AⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ"},{base:"AA",letters:"Ꜳ"},{base:"AE",letters:"ÆǼǢ"},{base:"AO",letters:"Ꜵ"},{base:"AU",letters:"Ꜷ"},{base:"AV",letters:"ꜸꜺ"},{base:"AY",letters:"Ꜽ"},{base:"B",letters:"BⒷBḂḄḆɃƂƁ"},{base:"C",letters:"CⒸCĆĈĊČÇḈƇȻꜾ"},{base:"D",letters:"DⒹDḊĎḌḐḒḎĐƋƊƉꝹ"},{base:"DZ",letters:"DZDŽ"},{base:"Dz",letters:"DzDž"},{base:"E",letters:"EⒺEÈÉÊỀẾỄỂẼĒḔḖĔĖËẺĚȄȆẸỆȨḜĘḘḚƐƎ"},{base:"F",letters:"FⒻFḞƑꝻ"},{base:"G",letters:"GⒼGǴĜḠĞĠǦĢǤƓꞠꝽꝾ"},{base:"H",letters:"HⒽHĤḢḦȞḤḨḪĦⱧⱵꞍ"},{base:"I",letters:"IⒾIÌÍÎĨĪĬİÏḮỈǏȈȊỊĮḬƗ"},{base:"J",letters:"JⒿJĴɈ"},{base:"K",letters:"KⓀKḰǨḲĶḴƘⱩꝀꝂꝄꞢ"},{base:"L",letters:"LⓁLĿĹĽḶḸĻḼḺŁȽⱢⱠꝈꝆꞀ"},{base:"LJ",letters:"LJ"},{base:"Lj",letters:"Lj"},{base:"M",letters:"MⓂMḾṀṂⱮƜ"},{base:"N",letters:"NⓃNǸŃÑṄŇṆŅṊṈȠƝꞐꞤ"},{base:"NJ",letters:"NJ"},{base:"Nj",letters:"Nj"},{base:"O",letters:"OⓄOÒÓÔỒỐỖỔÕṌȬṎŌṐṒŎȮȰÖȪỎŐǑȌȎƠỜỚỠỞỢỌỘǪǬØǾƆƟꝊꝌ"},{base:"OI",letters:"Ƣ"},{base:"OO",letters:"Ꝏ"},{base:"OU",letters:"Ȣ"},{base:"OE",letters:"ŒŒ"},{base:"oe",letters:"œœ"},{base:"P",letters:"PⓅPṔṖƤⱣꝐꝒꝔ"},{base:"Q",letters:"QⓆQꝖꝘɊ"},{base:"R",letters:"RⓇRŔṘŘȐȒṚṜŖṞɌⱤꝚꞦꞂ"},{base:"S",letters:"SⓈSẞŚṤŜṠŠṦṢṨȘŞⱾꞨꞄ"},{base:"T",letters:"TⓉTṪŤṬȚŢṰṮŦƬƮȾꞆ"},{base:"TZ",letters:"Ꜩ"},{base:"U",letters:"UⓊUÙÚÛŨṸŪṺŬÜǛǗǕǙỦŮŰǓȔȖƯỪỨỮỬỰỤṲŲṶṴɄ"},{base:"V",letters:"VⓋVṼṾƲꝞɅ"},{base:"VY",letters:"Ꝡ"},{base:"W",letters:"WⓌWẀẂŴẆẄẈⱲ"},{base:"X",letters:"XⓍXẊẌ"},{base:"Y",letters:"YⓎYỲÝŶỸȲẎŸỶỴƳɎỾ"},{base:"Z",letters:"ZⓏZŹẐŻŽẒẔƵȤⱿⱫꝢ"},{base:"a",letters:"aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐ"},{base:"aa",letters:"ꜳ"},{base:"ae",letters:"æǽǣ"},{base:"ao",letters:"ꜵ"},{base:"au",letters:"ꜷ"},{base:"av",letters:"ꜹꜻ"},{base:"ay",letters:"ꜽ"},{base:"b",letters:"bⓑbḃḅḇƀƃɓ"},{base:"c",letters:"cⓒcćĉċčçḉƈȼꜿↄ"},{base:"d",letters:"dⓓdḋďḍḑḓḏđƌɖɗꝺ"},{base:"dz",letters:"dzdž"},{base:"e",letters:"eⓔeèéêềếễểẽēḕḗĕėëẻěȅȇẹệȩḝęḙḛɇɛǝ"},{base:"f",letters:"fⓕfḟƒꝼ"},{base:"g",letters:"gⓖgǵĝḡğġǧģǥɠꞡᵹꝿ"},{base:"h",letters:"hⓗhĥḣḧȟḥḩḫẖħⱨⱶɥ"},{base:"hv",letters:"ƕ"},{base:"i",letters:"iⓘiìíîĩīĭïḯỉǐȉȋịįḭɨı"},{base:"j",letters:"jⓙjĵǰɉ"},{base:"k",letters:"kⓚkḱǩḳķḵƙⱪꝁꝃꝅꞣ"},{base:"l",letters:"lⓛlŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇ"},{base:"lj",letters:"lj"},{base:"m",letters:"mⓜmḿṁṃɱɯ"},{base:"n",letters:"nⓝnǹńñṅňṇņṋṉƞɲʼnꞑꞥ"},{base:"nj",letters:"nj"},{base:"o",letters:"oⓞoòóôồốỗổõṍȭṏōṑṓŏȯȱöȫỏőǒȍȏơờớỡởợọộǫǭøǿɔꝋꝍɵ"},{base:"oi",letters:"ƣ"},{base:"ou",letters:"ȣ"},{base:"oo",letters:"ꝏ"},{base:"p",letters:"pⓟpṕṗƥᵽꝑꝓꝕ"},{base:"q",letters:"qⓠqɋꝗꝙ"},{base:"r",letters:"rⓡrŕṙřȑȓṛṝŗṟɍɽꝛꞧꞃ"},{base:"s",letters:"sⓢsßśṥŝṡšṧṣṩșşȿꞩꞅẛ"},{base:"t",letters:"tⓣtṫẗťṭțţṱṯŧƭʈⱦꞇ"},{base:"tz",letters:"ꜩ"},{base:"u",letters:"uⓤuùúûũṹūṻŭüǜǘǖǚủůűǔȕȗưừứữửựụṳųṷṵʉ"},{base:"v",letters:"vⓥvṽṿʋꝟʌ"},{base:"vy",letters:"ꝡ"},{base:"w",letters:"wⓦwẁẃŵẇẅẘẉⱳ"},{base:"x",letters:"xⓧxẋẍ"},{base:"y",letters:"yⓨyỳýŷỹȳẏÿỷẙỵƴɏỿ"},{base:"z",letters:"zⓩzźẑżžẓẕƶȥɀⱬꝣ"}],n={},r=0;r<]*>/g,""):e}}),t.module("a8m.test",[]).filter("test",function(){return function(e,t,n){var r=new RegExp(t,n);return C(e)?r.test(e):e}}),t.module("a8m.trim",[]).filter("trim",function(){return function(e,t){var n=t||"\\s";return C(e)?e.replace(new RegExp("^"+n+"+|"+n+"+$","g"),""):e}}),t.module("a8m.truncate",[]).filter("truncate",function(){return function(e,t,n,r){return t=E(t)?e.length:t,r=r||!1,n=n||"",!C(e)||e.length<=t?e:e.substring(0,r?-1===e.indexOf(" ",t)?e.length:e.indexOf(" ",t):t)+n}}),t.module("a8m.ucfirst",[]).filter("ucfirst",[function(){return function(e){return C(e)?e.split(" ").map(function(e){return e.charAt(0).toUpperCase()+e.substring(1)}).join(" "):e}}]),t.module("a8m.uri-component-encode",[]).filter("uriComponentEncode",["$window",function(e){return function(t){return C(t)?e.encodeURIComponent(t):t}}]),t.module("a8m.uri-encode",[]).filter("uriEncode",["$window",function(e){return function(t){return C(t)?e.encodeURI(t):t}}]),t.module("a8m.wrap",[]).filter("wrap",function(){return function(e,t,n){return C(e)&&D(t)?[t,e,n||t].join(""):e}}),t.module("a8m.filter-watcher",[]).provider("filterWatcher",function(){this.$get=["$window","$rootScope",function(e,n){function r(e,n){return[e,t.toJson(n)].join("#").replace(/"/g,"")}function a(e){var t=e.targetScope.$id;x(d[t],function(e){delete u[e]}),delete d[t]}function o(){f(function(){n.$$phase||(u={})})}function i(e,t){var n=e.$id;return E(d[n])&&(e.$on("$destroy",a),d[n]=[]),d[n].push(t)}function s(e,t){var n=r(e,t);return u[n]}function l(e,t,n,a){var s=r(e,t);return u[s]=a,c(n)?i(n,s):o(),a}var u={},d={},f=e.setTimeout;return{isMemoized:s,memoize:l}}]}),t.module("angular.filter",["a8m.ucfirst","a8m.uri-encode","a8m.uri-component-encode","a8m.slugify","a8m.latinize","a8m.strip-tags","a8m.stringular","a8m.truncate","a8m.starts-with","a8m.ends-with","a8m.wrap","a8m.trim","a8m.ltrim","a8m.rtrim","a8m.repeat","a8m.test","a8m.match","a8m.to-array","a8m.concat","a8m.contains","a8m.unique","a8m.is-empty","a8m.after","a8m.after-where","a8m.before","a8m.before-where","a8m.defaults","a8m.where","a8m.reverse","a8m.remove","a8m.remove-with","a8m.group-by","a8m.count-by","a8m.search-field","a8m.fuzzy-by","a8m.fuzzy","a8m.omit","a8m.pick","a8m.every","a8m.filter-by","a8m.xor","a8m.map","a8m.first","a8m.last","a8m.flatten","a8m.join","a8m.math","a8m.math.max","a8m.math.min","a8m.math.percent","a8m.math.radix","a8m.math.sum","a8m.math.degrees","a8m.math.radians","a8m.math.byteFmt","a8m.math.kbFmt","a8m.math.shortFmt","a8m.angular","a8m.conditions","a8m.is-null","a8m.filter-watcher"])}(window,window.angular),define("job-roles/modules/job-roles.core",["common/angular","common/ui-select","common/directives/angular-date/date-input","common/modules/directives","common/modules/routers/compu-ng-route","common/filters/angular-date/format-date","common/services/angular-date/date-format","common/services/dom-event-trigger","common/services/pub-sub","job-roles/vendor/angular-editable","job-roles/vendor/angular-filter"],function(e){"use strict";e.module("hrjobroles.core",["angular.filter","ngAnimate","ngSanitize","ngResource","ui.bootstrap","ui.select","xeditable","common.angularDate","common.directives","common.services","compuNgRoute"])}),define("job-roles/filters/get-active-values.filter",["common/lodash"],function(e){"use strict";function t(t){return t.debug("Filter: getActiveValues"),function(t){var n={};return e.each(t,function(e,t){"1"===e.is_active&&(n[t]=e)}),n}}return t.__name="getActiveValues",t.$inject=["$log"],t}),define("job-roles/modules/job-roles.filters",["common/angular","job-roles/filters/get-active-values.filter"],function(e,t){"use strict";return e.module("hrjobroles.filters",[]).filter(t.__name,t)}),define("job-roles/modules/job-roles.run",["common/angular"],function(e){"use strict";function t(e,t,n,r){n.theme="bs3",t.contactId=r.contactId,t.pathBaseUrl=r.pathBaseUrl,t.pathTpl=r.pathTpl,t.pathIncludeTpl=r.pathIncludeTpl,t.prefix=r.classNamePrefix}e.module("hrjobroles.run",["hrjobroles.constants"]).run(t),t.$inject=["$q","$rootScope","editableOptions","settings"]}),define("job-roles/services/date-validation.service",["common/moment"],function(e){function t(t){function n(e,t){e.isValid()||l("Date is not valid!!",t)}function r(e,t){e.isSameOrAfter(t)&&l("Start Date cannot be the same as or after the End Date.",["start_date","end_date"])}function a(e,t){e.isBefore(t)&&l("Start Date cannot be lower than Contract Start Date.",["start_date"])}function o(e,t){e.isAfter(t)&&l("Start Date cannot be higher than Contract End Date.",["start_date"])}function i(e,t){e.isAfter(t)&&l("End Date cannot be higher than Contract End Date.",["end_date"])}function s(t,n){return t instanceof Date&&(t=e(t).valueOf()),e(t,n,!0).startOf("day")}var l=function(e,t){throw new Error(e,t[0])},u={dateFormats:["x","YYYY-MM-DD"],setErrorCallback:function(e){if("function"!=typeof e)throw new TypeError("Error callback must be a function.");l=e},validate:function(e,t,l,u){e=s(e,this.dateFormats),l=s(l,this.dateFormats),u=s(u,this.dateFormats),n(e,["start_date"]),o(e,u),a(e,l),(0===t||t)&&(t=s(t,this.dateFormats),n(t,["end_date"]),i(t,u),r(e,t))}};return t.DATE_FORMAT&&u.dateFormats.push(t.DATE_FORMAT.toUpperCase()),u}return t.__name="dateValidation",t.$inject=["HR_settings"],t}),define("job-roles/services/filters.service",[],function(){"use strict";function e(){return{isNotUndefined:function(e){try{return e.constructor===Array?e.filter(function(e){return"undefined"!==e&&void 0!==e}):e}catch(t){return e}},issetCostCentre:function(e){try{return e.constructor===Array?e.filter(function(e){return""!==e.cost_centre_id&&("1"===e.type&&parseInt(e.percentage)>0||"0"===e.type&&parseInt(e.amount)>0)}):e}catch(t){return e}},issetFunder:function(e){try{return e.constructor===Array?e.filter(function(e){return""!==e.funder_id&&("1"===e.type&&parseInt(e.percentage)>0||"0"===e.type&&parseInt(e.amount)>0)}):e}catch(t){return e}}}}return e.__name="filtersService",e}),define("job-roles/services/job-role.service",["common/lodash"],function(e){"use strict";function t(t,n,r){function a(n){var r=n["api.HRJobContractRevision.get"].values;delete n["api.HRJobContractRevision.get"],n.revisions=e.compact(r.map(function(e){var r=e["api.HRJobDetails.getsingle"];return r.period_start_date===n.period_start_date&&r.period_end_date===n.period_end_date?null:(r.period_start_date=t("formatDate")(r.period_start_date),r.period_end_date=t("formatDate")(r.period_end_date),r)}))}return{getContracts:function(e){var t=r.defer();return CRM.api3("HRJobContract","get",{sequential:1,contact_id:e,deleted:0,return:"title,period_end_date,period_start_date","api.HRJobContractRevision.get":{jobcontract_id:"$value.id","api.HRJobDetails.getsingle":{jobcontract_revision_id:"$value.id"}}}).done(function(e){e.values.forEach(a),t.resolve(e)}).error(function(){t.reject("An error occured while fetching items")}),t.promise},getAllJobRoles:function(e){var t=r.defer();return CRM.api3("HrJobRoles","get",{sequential:1,return:"id,job_contract_id,title,description,status,funder,funder_val_type,percent_pay_funder,amount_pay_funder,cost_center,cost_center_val_type,percent_pay_cost_center,amount_pay_cost_center,level_type,location,region,department,end_date,start_date",job_contract_id:{IN:e}}).done(function(e){t.resolve(e)}).error(function(e){t.reject("An error occured while fetching items")}),t.promise},deleteJobRole:function(e){var t=r.defer();return CRM.api3("HrJobRoles","delete",{sequential:1,id:e}).done(function(e){t.resolve(e)}).error(function(e){t.reject("An error occured while deleting items")}),t.promise},createJobRole:function(e){var t="|",n="|",a="|",o="|",i="|",s="|",l="|",u="|";if(void 0!==e.funders)for(var c=0,d=e.funders.length;c - + data-option-edit-path="civicrm/admin/options/hrjc_location?reset=1"> @@ -125,7 +125,7 @@ - @@ -150,7 +150,7 @@ - @@ -175,7 +175,7 @@ - diff --git a/com.civicrm.hrjobroles/views/include/job_role_panel.html b/com.civicrm.hrjobroles/views/include/job_role_panel.html index ad992fdc223..51ee14cee44 100755 --- a/com.civicrm.hrjobroles/views/include/job_role_panel.html +++ b/com.civicrm.hrjobroles/views/include/job_role_panel.html @@ -172,10 +172,10 @@ - + data-option-edit-path="civicrm/admin/options/hrjc_location?reset=1"> @@ -205,7 +205,7 @@ - @@ -238,7 +238,7 @@ - @@ -271,7 +271,7 @@ - From e7c57966eb8957a2eb409ce5fcd2893ace90c8f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Olivo?= Date: Thu, 29 Mar 2018 11:14:00 -0400 Subject: [PATCH 075/203] PCHR-3411: PR Feedback --- .../CRM/HRCore/Upgrader/Steps/1012.php | 73 +++++++++++++++++-- 1 file changed, 68 insertions(+), 5 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php index cb024df911b..84e96a54346 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php @@ -3,9 +3,24 @@ trait CRM_HRCore_Upgrader_Steps_1012 { /** - * Removes relationship types that are not necessary for CiviHR. + * Disables relationship types that are not necessary for CiviHR and + * removes existing relationships belonging to these types. */ public function upgrade_1012() { + $relationshipTypesToBeDisabled = $this->up1012_getRelationshipTypesToBeDisabled(); + + $this->up1012_disableRelationshipTypes($relationshipTypesToBeDisabled); + $this->up1012_removeRelationshipsForTypes($relationshipTypesToBeDisabled); + + return TRUE; + } + + /** + * Returns the Ids of the the relationship types to be disabled. + * + * @return Array[int] + */ + private function up1012_getRelationshipTypesToBeDisabled() { $relationshipsToBeDeleted = [ 'Case Coordinator is', 'Employee of', @@ -17,12 +32,60 @@ public function upgrade_1012() { 'name_a_b' => [ 'IN' => $relationshipsToBeDeleted ] ]); - foreach($result['values'] as $relationship) { - civicrm_api3('RelationshipType', 'delete', [ - 'id' => $relationship['id'] + return array_column($result['values'], 'id'); + } + + /** + * Disables relationship types. + * + * @param Array[int] $relationshipTypeIds + */ + private function up1012_disableRelationshipTypes($relationshipTypeIds) { + foreach ($relationshipTypeIds as $relationshipTypeId) { + civicrm_api3('RelationshipType', 'create', [ + 'id' => $relationshipTypeId, + 'is_active' => 0 ]); } + } - return TRUE; + /** + * Removes relationships for the given relationship types. + * + * @param Array[int] $relationshipTypeIds + */ + private function up1012_removeRelationshipsForTypes($relationshipTypeIds) { + foreach ($relationshipTypeIds as $relationshipTypeId) { + $relationships = $this->up1012_getRelationshipsForType($relationshipTypeId); + $this->up1012_removeRelationships($relationships); + } + } + + /** + * Returns all the relationships associated with a given type. + * + * @param Array[int] $relationshipTypeIds + * + * @return Array + */ + private function up1012_getRelationshipsForType($relationshipTypeId) { + $result = civicrm_api3('Relationship', 'get', [ + 'relationship_type_id' => $relationshipTypeId + ]); + + return $result['values']; + } + + /** + * Removes the relationships provided. + * + * @param Array + */ + private function up1012_removeRelationships($relationships) { + foreach ($relationships as $relationship) { + civicrm_api3('Relationship', 'delete', [ + 'id' => $relationship['id'] + ]); + } } } From b3125ec3433bfe2dc7bb5c1e2f4b366d8fd44d13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Olivo?= Date: Thu, 29 Mar 2018 11:37:47 -0400 Subject: [PATCH 076/203] PCHR-3411: Fix lint issues --- .../CRM/HRCore/Upgrader/Steps/1012.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php index 84e96a54346..d66cc670f52 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1012.php @@ -18,7 +18,7 @@ public function upgrade_1012() { /** * Returns the Ids of the the relationship types to be disabled. * - * @return Array[int] + * @return int[] */ private function up1012_getRelationshipTypesToBeDisabled() { $relationshipsToBeDeleted = [ @@ -38,7 +38,7 @@ private function up1012_getRelationshipTypesToBeDisabled() { /** * Disables relationship types. * - * @param Array[int] $relationshipTypeIds + * @param int[] $relationshipTypeIds */ private function up1012_disableRelationshipTypes($relationshipTypeIds) { foreach ($relationshipTypeIds as $relationshipTypeId) { @@ -52,7 +52,7 @@ private function up1012_disableRelationshipTypes($relationshipTypeIds) { /** * Removes relationships for the given relationship types. * - * @param Array[int] $relationshipTypeIds + * @param int[] $relationshipTypeIds */ private function up1012_removeRelationshipsForTypes($relationshipTypeIds) { foreach ($relationshipTypeIds as $relationshipTypeId) { @@ -64,9 +64,9 @@ private function up1012_removeRelationshipsForTypes($relationshipTypeIds) { /** * Returns all the relationships associated with a given type. * - * @param Array[int] $relationshipTypeIds + * @param int $relationshipTypeId * - * @return Array + * @return array */ private function up1012_getRelationshipsForType($relationshipTypeId) { $result = civicrm_api3('Relationship', 'get', [ @@ -79,7 +79,7 @@ private function up1012_getRelationshipsForType($relationshipTypeId) { /** * Removes the relationships provided. * - * @param Array + * @param array $relationships */ private function up1012_removeRelationships($relationships) { foreach ($relationships as $relationship) { @@ -88,4 +88,5 @@ private function up1012_removeRelationships($relationships) { ]); } } + } From a23425391159e99cc68d5b88512a2bc6ba00d6ea Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Fri, 30 Mar 2018 16:39:23 +0100 Subject: [PATCH 077/203] PCHR-3506: Move leave request template to system workflow message --- .../CRM/HRLeaveAndAbsences/Upgrader.php | 1 + .../HRLeaveAndAbsences/Upgrader/Step/1024.php | 86 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1024.php diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php index 8cb6897b1eb..b56f3bb9a64 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php @@ -29,6 +29,7 @@ class CRM_HRLeaveAndAbsences_Upgrader extends CRM_HRLeaveAndAbsences_Upgrader_Ba use CRM_HRLeaveAndAbsences_Upgrader_Step_1021; use CRM_HRLeaveAndAbsences_Upgrader_Step_1022; use CRM_HRLeaveAndAbsences_Upgrader_Step_1023; + use CRM_HRLeaveAndAbsences_Upgrader_Step_1024; /** * A list of directories to be scanned for XML installation files diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1024.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1024.php new file mode 100644 index 00000000000..aa933f878ae --- /dev/null +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1024.php @@ -0,0 +1,86 @@ +up1024_createLeaveWorkflowOptionGroup(); + + if ($result['count'] > 0) { + $this->up1024_createLeaveWorkflowOptionValue($result['id']); + } + + return TRUE; + } + + /** + * Create Leave Message Template Workflow Option Group. + * + * @return array + */ + public function up1024_createLeaveWorkflowOptionGroup() { + $workflow = 'Message Template Workflow for Leave'; + + return civicrm_api3('OptionGroup', 'create', [ + 'name' => 'msg_tpl_workflow_leave', + 'title' => $workflow, + 'description' => $workflow, + ]); + } + + /** + * Create Leave Message Template Workflow Option Values. + * + * @param $id + */ + public function up1024_createLeaveWorkflowOptionValue($id) { + $optionValues = [ + [ + 'option_group_id' => $id, + 'label' => 'CiviHR Leave Request Notification', + 'name' => 'civihr_leave_request', + ], + [ + 'option_group_id' => $id, + 'label' => 'CiviHR TOIL Request Notification', + 'name' => 'civihr_toil_request', + ], + [ + 'option_group_id' => $id, + 'label' => 'CiviHR Sickness Record Notification', + 'name' => 'civihr_sickness_record', + ] + ]; + + foreach ($optionValues as $optionValue) { + $result = civicrm_api3('OptionValue', 'create', $optionValue); + if ($result['count'] > 0) { + $this->up1024_updateLeaveMsgTemplate( + $result['id'], + $optionValue['label'] + ); + } + } + } + + /** + * Update message template workflow id for option group msg_tpl_workflow_leave + * + * @param $workflowId + * @param $msgLabel + */ + public function up1024_updateLeaveMsgTemplate($workflowId, $msgLabel) { + civicrm_api3('MessageTemplate', 'get', array( + 'return' => ['id'], + 'msg_title' => $msgLabel, + 'api.MessageTemplate.create' => [ + 'workflow_id' => $workflowId, + 'id' => "\$values['id']" + ], + )); + } +} From ef7f3aa18d144f5bedf05b8d3a950c1d88b1b28b Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Mon, 2 Apr 2018 15:17:11 +0100 Subject: [PATCH 078/203] PCHR-3506: Fixed jenkins build failure --- .../HRLeaveAndAbsences/Upgrader/Step/1024.php | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1024.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1024.php index aa933f878ae..f2393b12ad5 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1024.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1024.php @@ -8,7 +8,8 @@ trait CRM_HRLeaveAndAbsences_Upgrader_Step_1024 { * @return bool */ public function upgrade_1024() { - $result = $this->up1024_createLeaveWorkflowOptionGroup(); + $templateName = 'msg_tpl_workflow_leave'; + $result = $this->up1024_createLeaveWorkflowOptionGroup($templateName); if ($result['count'] > 0) { $this->up1024_createLeaveWorkflowOptionValue($result['id']); @@ -20,37 +21,42 @@ public function upgrade_1024() { /** * Create Leave Message Template Workflow Option Group. * + * @param $templateName + * * @return array */ - public function up1024_createLeaveWorkflowOptionGroup() { + public function up1024_createLeaveWorkflowOptionGroup($templateName) { $workflow = 'Message Template Workflow for Leave'; - return civicrm_api3('OptionGroup', 'create', [ - 'name' => 'msg_tpl_workflow_leave', + $result = civicrm_api3('OptionGroup', 'create', [ + 'name' => $templateName, 'title' => $workflow, 'description' => $workflow, ]); + CRM_Core_PseudoConstant::flush(); + + return $result; } /** * Create Leave Message Template Workflow Option Values. * - * @param $id + * @param $templateName */ - public function up1024_createLeaveWorkflowOptionValue($id) { + public function up1024_createLeaveWorkflowOptionValue($templateName) { $optionValues = [ [ - 'option_group_id' => $id, + 'option_group_id' => $templateName, 'label' => 'CiviHR Leave Request Notification', 'name' => 'civihr_leave_request', ], [ - 'option_group_id' => $id, + 'option_group_id' => $templateName, 'label' => 'CiviHR TOIL Request Notification', 'name' => 'civihr_toil_request', ], [ - 'option_group_id' => $id, + 'option_group_id' => $templateName, 'label' => 'CiviHR Sickness Record Notification', 'name' => 'civihr_sickness_record', ] @@ -79,7 +85,7 @@ public function up1024_updateLeaveMsgTemplate($workflowId, $msgLabel) { 'msg_title' => $msgLabel, 'api.MessageTemplate.create' => [ 'workflow_id' => $workflowId, - 'id' => "\$values['id']" + 'id' => '$value.id' ], )); } From 5db0c159167b9af217a84c97ce89008d1d3476a2 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Tue, 3 Apr 2018 14:52:58 +0100 Subject: [PATCH 079/203] PCHR-3509: Use role machine names instead of role names --- .../HRCore/CMSData/Role/DrupalRoleService.php | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/CMSData/Role/DrupalRoleService.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/CMSData/Role/DrupalRoleService.php index 398428fa1ef..614da90a456 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/CMSData/Role/DrupalRoleService.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/CMSData/Role/DrupalRoleService.php @@ -5,7 +5,7 @@ /** * Implementation of RoleServiceInterface to interact with a Drupal 7 system */ -class CRM_HRCore_CMSData_Role_DrupalRoleService implements RoleServiceInterface{ +class CRM_HRCore_CMSData_Role_DrupalRoleService implements RoleServiceInterface { /** * @inheritdoc @@ -26,13 +26,13 @@ public function getLatestLoginByRole() { $result = $query->execute()->fetchAllKeyed(); - $roleNames = $this->getRoleNames(); + $roleNames = $this->getRoleMachineNames(); $rolesToExclude = ['authenticated user', 'anonymous user']; $roleNames = array_diff($roleNames, $rolesToExclude); $returnArray = array_fill_keys($roleNames, NULL); foreach ($result as $rid => $loginTimestamp) { - if (array_key_exists($rid, $roleNames)) { + if (isset($roleNames[$rid])) { $roleName = $roleNames[$rid]; $loginDate = NULL; if ($loginTimestamp != 0) { @@ -62,4 +62,25 @@ public function getRoleIds($roles) { return $roleIds; } + /** + * Gets the machine names for roles that have them. Roles without machine + * names, such as 'anonymous user' will default to the role name + * + * @return array + * The array will be in the format 'rid' => 'machine_name' + */ + private function getRoleMachineNames() { + $result = db_select('role', 'r') + ->fields('r', ['rid', 'name', 'machine_name']) + ->execute() + ->fetchAllAssoc('rid', PDO::FETCH_BOTH); + + // use name if machine_name is not set + array_walk($result, function (&$role) { + $role['machine_name'] = $role['machine_name'] ?: $role['name']; + }); + + return array_column($result, 'machine_name', 'rid'); + } + } From eea2ee2b455092ab44c2bae36e2eca1be20111da Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Thu, 15 Mar 2018 15:58:04 +0000 Subject: [PATCH 080/203] PCHR-3438: Move unrelated to TOIL code to Leave subcontroller --- ...ave-request-popup-details-tab.component.js | 410 +++--------------- .../request-modal-details-leave.controller.js | 399 ++++++++++++++++- 2 files changed, 450 insertions(+), 359 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-popup-details-tab.component.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-popup-details-tab.component.js index 2b0b5b7bd79..9542d38f3a4 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-popup-details-tab.component.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-popup-details-tab.component.js @@ -31,16 +31,15 @@ define([ DetailsTabController.$inject = ['$controller', '$log', '$rootScope', '$scope', '$q', 'HR_settings', 'shared-settings', 'Calendar', 'OptionGroup', - 'PublicHoliday', 'LeaveRequest', '$timeout']; + 'LeaveRequest', '$timeout']; function DetailsTabController ($controller, $log, $rootScope, $scope, $q, HRSettings, sharedSettings, Calendar, OptionGroup, - PublicHoliday, LeaveRequest, $timeout) { + LeaveRequest, $timeout) { $log.debug('Component: leave-request-popup-details-tab'); var originalOpeningBalance = null; var listeners = []; var vm = this; - var workDays = {}; vm.canManage = false; vm.calendar = {}; @@ -121,9 +120,15 @@ define([ vm.dateChangeHandler = dateChangeHandler; vm.dateTypeChangeHandler = dateTypeChangeHandler; vm.daysSelectionModeChangeHandler = daysSelectionModeChangeHandler; + vm.disableAndShowLoadingTimeInput = disableAndShowLoadingTimeInput; + vm.getMomentDateWithGivenTime = getMomentDateWithGivenTime; + vm.handleError = handleError; + vm.isCalculationUnit = isCalculationUnit; vm.isLeaveType = isLeaveType; vm.isNotWorkingDay = isNotWorkingDay; vm.performBalanceChangeCalculation = performBalanceChangeCalculation; + vm.setRequestDateTimesAndDateTypes = setRequestDateTimesAndDateTypes; + vm.updateEndTimeInputMinTime = updateEndTimeInputMinTime; vm.$onDestroy = unsubscribeFromEvents; (function init () { @@ -148,8 +153,9 @@ define([ .then(!vm.isMode('create') && initDates) .then(setDaysSelectionMode) .then(function () { - if (!vm.isMode('create') && isCalculationUnit('hours')) { - return initTimes() + if (!vm.isMode('create')) { + return $q.resolve() + .then(vm.initTimesExtended) .then(setRequestDateTimesAndDateTypes); } }) @@ -157,11 +163,8 @@ define([ .then(initOriginalOpeningBalance) .then(setOpeningBalance) .then(initBalanceChange) - .then(function () { - if (!vm.isMode('view') && !isLeaveType('toil')) { - initTimeAndDeductionInputsWatchers(); - } - }) + .then(initFromTimeWatcher) + .then(!vm.isMode('view') && vm.initWatchersExtended) .catch(handleError) .finally(function () { vm.loading.tab = false; @@ -207,7 +210,7 @@ define([ return $q.resolve() .then(function () { - resetUIDayTypesTimeAndDeductions(dateType); + resetUIInputs(dateType); if (dateType === 'from') { resetToDateIfGreaterThanFromDate(); @@ -223,7 +226,6 @@ define([ vm.loading[dateType + 'DayTypes'] = true; }) - .then(vm.onDateChangeExtended) .then(function () { return getAbsencePeriod(dateType); }) @@ -246,15 +248,7 @@ define([ } }) .then(function () { - return loadDayTypesForDate(vm.uiOptions[dateType + 'Date'], dateType); - }) - .then(function () { - if (isCalculationUnit('hours')) { - return loadTimeRangesFromWorkPattern(dateType) - .then(function () { - setDeductionMaximumBoundary(dateType, true); - }); - } + return vm.onDateChangeExtended && vm.onDateChangeExtended(dateType); }) .then(function () { setRequestDateTimesAndDateTypes(); @@ -265,7 +259,15 @@ define([ return performBalanceChangeCalculation(); } }) - .catch(handleError); + .catch(handleError) + .finally(function () { + vm.loading[dateType + 'DayTypes'] = false; + + if (isCalculationUnit('hours')) { + vm.uiOptions.times.from.loading = false; + vm.uiOptions.times.to.loading = false; + } + }); } /** @@ -289,21 +291,10 @@ define([ function daysSelectionModeChangeHandler () { vm.uiOptions.toDate = null; - resetUIDayTypesTimeAndDeductions('to'); + resetUIInputs('to'); return $q.resolve() - .then(function () { - if (isCalculationUnit('hours') && vm.uiOptions.fromDate) { - disableAndShowLoadingTimeInput('from'); - (!vm.uiOptions.multipleDays) && disableAndShowLoadingTimeInput('to'); - - return loadTimeRangesFromWorkPattern('from') - .then(function () { - setDeductionMaximumBoundary('from', true); - }) - .then(setRequestDateTimesAndDateTypes); - } - }) + .then(setRequestDateTimesAndDateTypes) .then(vm.setDaysSelectionModeExtended) .then(!vm.uiOptions.multipleDays && performBalanceChangeCalculation); } @@ -321,79 +312,6 @@ define([ timeObject.disabled = true; } - /** - * Enables a time input of the specified type - * and sets provided data such as minumum and maximum time values and time - * - * @param {String} type from|to - */ - function enableAndSetDataToTimeInput (type, data) { - var timeObject = vm.uiOptions.times[type]; - var timeMin = _.clone(data.time_from); - var timeMax = _.clone(data.time_to); - - if (!vm.uiOptions.multipleDays) { - if (type === 'from' && timeMax && timeMin) { - timeMax = getMomentDateWithGivenTime(timeMax) - .subtract(vm.uiOptions.time_interval, 'minutes') - .format('HH:mm'); - } - if (type === 'to' && timeMin && timeMax) { - timeMin = getMomentDateWithGivenTime(timeMin) - .add(vm.uiOptions.time_interval, 'minutes') - .format('HH:mm'); - } - } - - timeObject.min = timeMin || '00:00'; - timeObject.max = timeMax || '00:00'; - timeObject.time = type === 'to' ? timeObject.max : timeObject.min; - timeObject.disabled = false; - } - - /** - * This method will be used on the view to return a list of available - * leave request day types (All day, Half-day AM, Half-day PM, Non working day, - * Weekend, Public holiday) for the given date (which is the date - * selected by the user via datepicker) - * - * If no date is passed, then no list is returned - * - * @param {Date} date - * @param {String} dayType - set to from if from date is selected else to - * @return {Promise} of array with day types - */ - function filterLeaveRequestDayTypes (date, dayType) { - if (!date) { - return $q.reject([]); - } - - date = convertDateToServerFormat(date); - - return PublicHoliday.isPublicHoliday(date) - .then(function (result) { - if (result) { - return vm.requestDayTypes.filter(function (publicHoliday) { - return publicHoliday.name === 'public_holiday'; - }); - } - - return getDayTypesFromDate(date, vm.requestDayTypes) - .then(function (inCalendarList) { - return inCalendarList.length - ? inCalendarList - : vm.requestDayTypes.filter(function (dayType) { - return _.includes(['all_day', 'half_day_am', 'half_day_pm'], dayType.name); - }); - }); - }) - .then(function (dayTypes) { - setDayTypes(dayType, dayTypes); - - return dayTypes; - }); - } - /** * Gets absence period for the given date * @@ -409,28 +327,6 @@ define([ }) || {}; } - /** - * Gets list of day types if its found to be weekend or non working in calendar - * - * @param {Date} date to Checks - * @param {Array} listOfDayTypes array of day types - * @return {Array} non-empty if found else empty array - */ - function getDayTypesFromDate (date, listOfDayTypes) { - date = moment(date); - - return $q.all([ - vm.calendar.isNonWorkingDay(date), - vm.calendar.isWeekend(date) - ]).then(function (results) { - return results[0] ? 'non_working_day' : (results[1] ? 'weekend' : null); - }).then(function (nameFilter) { - return !nameFilter ? [] : listOfDayTypes.filter(function (day) { - return day.name === nameFilter; - }); - }); - } - /** * Gets leave type. * @@ -470,18 +366,6 @@ define([ .catch(handleError); } - /** - * Calculates time difference in hours - * - * @param {String} timeFrom in HH:mm format - * @param {String} timeTo in HH:mm format - * @return {Number} amount of hours, eg. 7.5 - */ - function getTimeDifferenceInHours (timeFrom, timeTo) { - return moment.duration(timeTo) - .subtract(moment.duration(timeFrom)).asHours(); - } - /** * Handles errors * @@ -515,33 +399,12 @@ define([ var attributes = vm.request.attributes(); vm.uiOptions.fromDate = convertDateFormatFromServer(vm.request.from_date); + // to_date and type has been reset in above call so reinitialize from clone + vm.request.to_date = attributes.to_date; + vm.request.to_date_type = attributes.to_date_type; + vm.uiOptions.toDate = convertDateFormatFromServer(vm.request.to_date); - return loadDayTypesForDate(vm.uiOptions.fromDate, 'from') - .then(function () { - // to_date and type has been reset in above call so reinitialize from clone - vm.request.to_date = attributes.to_date; - vm.request.to_date_type = attributes.to_date_type; - vm.uiOptions.toDate = convertDateFormatFromServer(vm.request.to_date); - - return loadDayTypesForDate(vm.uiOptions.toDate, 'to'); - }); - } - - /** - * Initialises a watcher for a custom deduction input of a specified date type - * - * @param {String} dateType from|to - */ - function initDeductionInputWatcher (dateType) { - $scope.$watch('detailsTab.uiOptions.times.' + dateType + '.amount', function (amount, oldAmount) { - if (isCalculationUnit('days') || +amount === +oldAmount) { - return; - } - - setRequestHoursDeductions(); - // @NOTE `vm.` is needed for testing purposes - vm.performBalanceChangeCalculation(); - }); + return vm.initDayTypesExtended ? vm.initDayTypesExtended() : $q.resolve(); } /** @@ -582,85 +445,24 @@ define([ } /** - * Initialises time for a given date type. - * In general cases simply extracts the time from the date string and - * sets the time to the correspondent times property. - * If the time is outside the allowed range (for example after work parrern change), - * then it sets the minimum allowed time for "from" time - * and the maximum allowed time for "to" time. - * - * @param {String} dateType from|to + * Initialises watcher for from time values. + * The value of the from time input affects the min value of the to time input */ - function initTime (dateType) { - var time = moment(vm.request[dateType + '_date']).format('HH:mm'); - var timeObject = vm.uiOptions.times[dateType]; - var isOutsideWorkPatternRange = - getTimeDifferenceInHours(timeObject.min, time) <= 0 || - getTimeDifferenceInHours(timeObject.max, time) >= 0; - - if (isOutsideWorkPatternRange) { - time = dateType === 'from' ? timeObject.min : timeObject.max; - } - - vm.uiOptions.times[dateType].time = time; - } - - /** - * Initialises and sets the "from" and "to" times - * - * @return {Promise} - */ - function initTimes () { - var dateTypes = vm.uiOptions.multipleDays ? ['from', 'to'] : ['from']; - var times = vm.uiOptions.times; - - return $q.all(dateTypes.map(loadTimeRangesFromWorkPattern)) - .then(function () { - ['from', 'to'].forEach(function (dateType) { - initTime(dateType); - - setDeductionMaximumBoundary(dateType); - - times[dateType].amount = - Math.min(vm.request[dateType + '_date_amount'], times[dateType].maxAmount).toString(); - }); + function initFromTimeWatcher () { + $rootScope.$watch( + function () { + return vm.uiOptions.times.from.time; + }, + function (newValue, oldValue) { + if (newValue === oldValue) { + return; + } if (!vm.uiOptions.multipleDays) { - updateEndTimeInputMinTime(vm.uiOptions.times.from.time); + updateEndTimeInputMinTime(newValue); + setRequestDateTimesAndDateTypes(); } - }).then(setRequestHoursDeductions); - } - - /** - * Initialises watchers for time and deductions inputs - */ - function initTimeAndDeductionInputsWatchers () { - ['from', 'to'].forEach(function (dateType) { - initDeductionInputWatcher(dateType); - initTimeInputWatcher(dateType); - }); - } - - /** - * Initialises a watcher for a time input of a specified date type - * - * @param {String} dateType from|to - */ - function initTimeInputWatcher (dateType) { - $scope.$watch('detailsTab.uiOptions.times.' + dateType + '.time', function (time, oldTime) { - if (isCalculationUnit('days') || time === oldTime) { - return; - } - - setRequestDateTimesAndDateTypes(); - - if (!time) { - return; - } - - (!vm.uiOptions.multipleDays && dateType === 'from') && updateEndTimeInputMinTime(time); - setDeductionMaximumBoundary(dateType, true); - }); + }); } /** @@ -694,21 +496,6 @@ define([ return _.includes(['weekend', 'non_working_day', 'public_holiday'], dayType); } - /** - * Loads absence types and calendar data on component initialization and - * when they need to be updated. - * - * @param {Date} date - the selected date - * @param {String} dayType - set to from if from date is selected else to - * @return {Promise} - */ - function loadDayTypesForDate (date, dateType) { - return filterLeaveRequestDayTypes(date, dateType) - .then(function () { - vm.loading[dateType + 'DayTypes'] = false; - }); - } - /** * Initializes leave request day types * @@ -721,41 +508,6 @@ define([ }); } - /** - * Loads time ranges from work pattern, - * sets time ranges for timepickers and maximum value for deduction. - * - * @param {String} dateType from|to - * @return {Promise} - */ - function loadTimeRangesFromWorkPattern (dateType) { - var date = vm.uiOptions[dateType + 'Date']; - var timeObject = vm.uiOptions.times[dateType]; - var isSingleDayRequest = !vm.uiOptions.multipleDays; - - if (!date) { - return $q.resolve(); - } - - return vm.request.getWorkDayForDate(convertDateToServerFormat(date)) - .then(function (workDay) { - workDays[dateType] = workDay; - - enableAndSetDataToTimeInput(dateType, workDay); - (isSingleDayRequest && dateType === 'from') && enableAndSetDataToTimeInput('to', workDay); - }) - .catch(function (err) { - workDays[dateType] = {}; - - return handleError(err); - }) - .finally(function () { - timeObject.loading = false; - - isSingleDayRequest && (vm.uiOptions.times['to'].loading = false); - }); - } - /** * Initializes user's calendar (work patterns) * @@ -832,7 +584,7 @@ define([ ) { vm.uiOptions.toDate = null; - resetUIDayTypesTimeAndDeductions('to'); + resetUIInputs('to'); } } @@ -841,19 +593,14 @@ define([ * * @param {String} dateType from|to */ - function resetUIDayTypesTimeAndDeductions (dateType) { + function resetUIInputs (dateType) { var time = vm.uiOptions.times[dateType]; vm['request' + _.startCase(dateType) + 'DayTypes'] = []; - time.time = ''; - time.min = '00:00'; - time.max = '00:00'; - time.amount = '0'; - time.maxAmount = '0'; time.loading = false; setRequestDateTimesAndDateTypes(); - setRequestHoursDeductions(); + (vm.resetUIInputsExtended) && vm.resetUIInputsExtended(dateType); toggleBalance(); } @@ -910,44 +657,6 @@ define([ return $q.resolve().then(vm.setDaysSelectionModeExtended); } - /** - * Sets the collection for given day types to sent list of day types, - * also initializes the day types - * - * @param {String} dateType from|to - * @param {Array} listOfDayTypes collection of available day types - */ - function setDayTypes (dateType, listOfDayTypes) { - // will create either of leaveRequestFromDayTypes or leaveRequestToDayTypes key - var keyForDayTypeCollection = 'request' + _.startCase(dateType) + 'DayTypes'; - - vm[keyForDayTypeCollection] = listOfDayTypes; - - if (vm.isMode('create')) { - vm.request[dateType + '_date_type'] = vm[keyForDayTypeCollection][0].value; - } - } - - /** - * Sets deduction maximum and default amounts for a given day type - * - * @param {String} timeType from|to - * @param {Boolean} setDefaultValue if TRUE, then set the current value to maximum - */ - function setDeductionMaximumBoundary (timeType, setDefaultValue) { - var uiOptions = vm.uiOptions; - var dateType = uiOptions.multipleDays ? timeType : 'from'; - var timeObject = uiOptions.times[dateType]; - var timeFrom = uiOptions.multipleDays && dateType === 'to' ? timeObject.min : uiOptions.times.from.time; - var timeTo = uiOptions.multipleDays && dateType === 'from' ? timeObject.max : uiOptions.times.to.time; - var deduction = workDays[dateType].number_of_hours - ? getTimeDifferenceInHours(timeFrom, timeTo).toString() - : '0'; - - timeObject.maxAmount = deduction; - (setDefaultValue) && (timeObject.amount = timeObject.maxAmount); - } - /** * Updates the opening balance depending on the mode * In case of "edit" or "view" mode, sets original balance @@ -986,22 +695,12 @@ define([ vm.request.to_date_type = vm.request.from_date_type; } - if (isCalculationUnit('hours') && !isLeaveType('toil')) { + if (isCalculationUnit('hours') || isLeaveType('toil')) { vm.request.from_date = vm.request.from_date && times.from.time ? vm.request.from_date + ' ' + times.from.time : null; vm.request.to_date = vm.request.to_date && times.to.time ? vm.request.to_date + ' ' + times.to.time : null; } } - /** - * Sets deductions in hours from UI to vm.request - */ - function setRequestHoursDeductions () { - var times = vm.uiOptions.times; - - vm.request.from_date_amount = !isNaN(+times.from.amount) ? times.from.amount : null; - vm.request.to_date_amount = !isNaN(+times.to.amount) ? times.to.amount : null; - } - /** * Shows or hides the balance breakdown depending on various conditions */ @@ -1040,11 +739,10 @@ define([ return $q.resolve() .then(absenceTypeUnitChanged && setDaysSelectionMode) .then(function () { - if (absenceTypeUnitChanged && isCalculationUnit('hours')) { - return loadTimeRangesFromWorkPattern('from') - .then(function () { - setDeductionMaximumBoundary('from', true); - }); + if (absenceTypeUnitChanged) { + return vm.onAbsenceTypeUpdateExtended + ? vm.onAbsenceTypeUpdateExtended() + : $q.resolve(); } }) .then(absenceTypeUnitChanged && setRequestDateTimesAndDateTypes) @@ -1068,7 +766,7 @@ define([ if (moment(vm.uiOptions.toDate).isAfter(vm.period.end_date)) { vm.uiOptions.toDate = undefined; - resetUIDayTypesTimeAndDeductions('to'); + resetUIInputs('to'); } setOpeningBalance(); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller.js index 7a212012335..813e6ea9634 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller.js @@ -1,19 +1,30 @@ /* eslint-env amd */ define([ + 'common/lodash', + 'common/moment', 'leave-absences/shared/modules/controllers' -], function (controllers) { +], function (_, moment, controllers) { controllers.controller('RequestModalDetailsLeaveController', RequestModalDetailsLeaveController); - RequestModalDetailsLeaveController.$inject = ['$controller', '$log', '$q', 'detailsController']; + RequestModalDetailsLeaveController.$inject = ['$controller', '$log', '$q', '$rootScope', 'detailsController', 'PublicHoliday']; + + function RequestModalDetailsLeaveController ($controller, $log, $q, $rootScope, detailsController, PublicHoliday) { + var workDays = {}; - function RequestModalDetailsLeaveController ($controller, $log, $q, detailsController) { $log.debug('RequestModalDetailsLeaveController'); detailsController.calculateBalanceChange = calculateBalanceChange; detailsController.canCalculateChange = canCalculateChange; detailsController.canSubmit = canSubmit; detailsController.initChildController = initChildController; + detailsController.initDayTypesExtended = initDayTypes; + detailsController.initTimesExtended = initTimes; + detailsController.initWatchersExtended = initWatchers; + detailsController.onAbsenceTypeUpdateExtended = updateFromTimeRangeAndDeductionBoundary; + detailsController.onDateChangeExtended = loadDayTypesTimeRangesAndSetDeductionBoundaries; + detailsController.resetUIInputsExtended = resetUIInputsExtended; + detailsController.setDaysSelectionModeExtended = setDaysSelectionModeExtended; /** * Calculates balance change by fetching the balance breakdown via the API @@ -57,6 +68,113 @@ define([ return detailsController.canCalculateChange(); } + /** + * Enables a time input of the specified type + * and sets provided data such as minumum and maximum time values and time + * + * @param {String} type from|to + */ + function enableAndSetDataToTimeInput (type, data) { + var timeObject = detailsController.uiOptions.times[type]; + var timeMin = _.clone(data.time_from); + var timeMax = _.clone(data.time_to); + + if (!detailsController.uiOptions.multipleDays) { + if (type === 'from' && timeMax && timeMin) { + timeMax = detailsController.getMomentDateWithGivenTime(timeMax) + .subtract(detailsController.uiOptions.time_interval, 'minutes') + .format('HH:mm'); + } + if (type === 'to' && timeMin && timeMax) { + timeMin = detailsController.getMomentDateWithGivenTime(timeMin) + .add(detailsController.uiOptions.time_interval, 'minutes') + .format('HH:mm'); + } + } + + timeObject.min = timeMin || '00:00'; + timeObject.max = timeMax || '00:00'; + timeObject.time = type === 'to' ? timeObject.max : timeObject.min; + timeObject.disabled = false; + } + + /** + * This method will be used on the view to return a list of available + * leave request day types (All day, Half-day AM, Half-day PM, Non working day, + * Weekend, Public holiday) for the given date (which is the date + * selected by the user via datepicker) + * + * If no date is passed, then no list is returned + * + * @param {Date} date + * @param {String} dayType - set to from if from date is selected else to + * @return {Promise} of array with day types + */ + function filterLeaveRequestDayTypes (date, dayType) { + if (!date) { + return $q.reject([]); + } + + date = detailsController.convertDateToServerFormat(date); + + return PublicHoliday.isPublicHoliday(date) + .then(function (result) { + if (result) { + return detailsController.requestDayTypes.filter(function (publicHoliday) { + return publicHoliday.name === 'public_holiday'; + }); + } + + return getDayTypesFromDate(date, detailsController.requestDayTypes) + .then(function (inCalendarList) { + return inCalendarList.length + ? inCalendarList + : detailsController.requestDayTypes.filter(function (dayType) { + return _.includes(['all_day', 'half_day_am', 'half_day_pm'], dayType.name); + }); + }); + }) + .then(function (dayTypes) { + setDayTypes(dayType, dayTypes); + + return dayTypes; + }); + } + + /** + * Gets list of day types if its found to be weekend or non working in calendar + * + * @param {Date} date to Checks + * @param {Array} listOfDayTypes array of day types + * @return {Array} non-empty if found else empty array + */ + function getDayTypesFromDate (date, listOfDayTypes) { + date = moment(date); + + return $q.all([ + detailsController.calendar.isNonWorkingDay(date), + detailsController.calendar.isWeekend(date) + ]).then(function (results) { + return results[0] ? 'non_working_day' : (results[1] ? 'weekend' : null); + }).then(function (nameFilter) { + return !nameFilter ? [] : listOfDayTypes.filter(function (day) { + return day.name === nameFilter; + }); + }); + } + + /** + * Calculates time difference in hours + * + * @param {String} timeFrom in HH:mm format + * @param {String} timeTo in HH:mm format + * @return {Number} amount of hours, eg. 7.5 + */ + function getTimeDifferenceInHours (timeFrom, timeTo) { + return moment.duration(timeTo) + .subtract(moment.duration(timeFrom)).asHours(); + } + /** * Initialize the controller * @@ -65,5 +183,280 @@ define([ function initChildController () { return $q.resolve(); } + + function initDayTypes () { + return loadDayTypesForDate(detailsController.uiOptions.fromDate, 'from') + .then(function () { + return loadDayTypesForDate(detailsController.uiOptions.toDate, 'to'); + }); + } + + /** + * Initialises a watcher for a custom deduction input of a specified date type + * + * @param {String} dateType from|to + */ + function initDeductionInputWatcher (dateType) { + $rootScope.$watch(function () { + return detailsController.uiOptions.times[dateType].amount; + }, function (amount, oldAmount) { + if (detailsController.isCalculationUnit('days') || +amount === +oldAmount) { + return; + } + + if (detailsController.isRole('staff')) { + detailsController.request.change_balance = true; + } + + setRequestHoursDeductions(); + // @NOTE `detailsController.` is needed for testing purposes + detailsController.performBalanceChangeCalculation(); + }); + } + + /** + * Initialises time for a given date type. + * In general cases simply extracts the time from the date string and + * sets the time to the correspondent times property. + * If the time is outside the allowed range (for example after work parrern change), + * then it sets the minimum allowed time for "from" time + * and the maximum allowed time for "to" time. + * + * @param {String} dateType from|to + */ + function initTime (dateType) { + var time = moment(detailsController.request[dateType + '_date']).format('HH:mm'); + var timeObject = detailsController.uiOptions.times[dateType]; + var isOutsideWorkPatternRange = + getTimeDifferenceInHours(timeObject.min, time) <= 0 || + getTimeDifferenceInHours(timeObject.max, time) >= 0; + + if (isOutsideWorkPatternRange) { + time = dateType === 'from' ? timeObject.min : timeObject.max; + } + + detailsController.uiOptions.times[dateType].time = time; + } + + /** + * Initialises and sets the "from" and "to" times + * + * @return {Promise} + */ + function initTimes () { + var dateTypes = detailsController.uiOptions.multipleDays ? ['from', 'to'] : ['from']; + var times = detailsController.uiOptions.times; + + if (!detailsController.isCalculationUnit('hours')) { + return; + } + + return $q.all(dateTypes.map(loadTimeRangesFromWorkPattern)) + .then(function () { + ['from', 'to'].forEach(function (dateType) { + initTime(dateType); + + setDeductionMaximumBoundary(dateType); + + times[dateType].amount = + Math.min(detailsController.request[dateType + '_date_amount'], times[dateType].maxAmount).toString(); + }); + + if (!detailsController.uiOptions.multipleDays) { + detailsController.updateEndTimeInputMinTime(detailsController.uiOptions.times.from.time); + } + }).then(setRequestHoursDeductions); + } + + /** + * Initialises watchers for time and deductions inputs + */ + function initWatchers () { + ['from', 'to'].forEach(function (dateType) { + initDeductionInputWatcher(dateType); + initTimeInputWatcher(dateType); + }); + } + + /** + * Initialises a watcher for a time input of a specified date type + * + * @param {String} dateType from|to + */ + function initTimeInputWatcher (dateType) { + $rootScope.$watch(function () { + return detailsController.uiOptions.times[dateType].time; + }, function (time, oldTime) { + if (detailsController.isCalculationUnit('days') || time === oldTime) { + return; + } + + detailsController.setRequestDateTimesAndDateTypes(); + + if (!time) { + return; + } + + setDeductionMaximumBoundary(dateType, true); + }); + } + + /** + * Loads absence types and calendar data on component initialization and + * when they need to be updated. + * + * @param {Date} date - the selected date + * @param {String} dayType - set to from if from date is selected else to + * @return {Promise} + */ + function loadDayTypesForDate (date, dateType) { + return filterLeaveRequestDayTypes(date, dateType) + .then(function () { + detailsController.loading[dateType + 'DayTypes'] = false; + }); + } + + function loadDayTypesTimeRangesAndSetDeductionBoundaries (dateType) { + return loadDayTypesForDate(detailsController.uiOptions[dateType + 'Date'], dateType) + .then(function () { + if (detailsController.isCalculationUnit('hours')) { + return loadTimeRangesFromWorkPattern(dateType) + .then(function () { + setDeductionMaximumBoundary(dateType, true); + }); + } + }); + } + + /** + * Loads time ranges from work pattern, + * sets time ranges for timepickers and maximum value for deduction. + * + * @param {String} dateType from|to + * @return {Promise} + */ + function loadTimeRangesFromWorkPattern (dateType) { + var date = detailsController.uiOptions[dateType + 'Date']; + var isSingleDayRequest = !detailsController.uiOptions.multipleDays; + + if (!date) { + return $q.resolve(); + } + + return detailsController.request.getWorkDayForDate(detailsController.convertDateToServerFormat(date)) + .then(function (workDay) { + workDays[dateType] = workDay; + + enableAndSetDataToTimeInput(dateType, workDay); + (isSingleDayRequest && dateType === 'from') && enableAndSetDataToTimeInput('to', workDay); + }) + .catch(function (err) { + workDays[dateType] = {}; + + return detailsController.handleError(err); + }) + .finally(function () { + isSingleDayRequest && (detailsController.uiOptions.times['to'].loading = false); + }); + } + + function resetUIInputsExtended (dateType) { + var timeObject = detailsController.uiOptions.times[dateType]; + + timeObject.time = ''; + timeObject.min = '00:00'; + timeObject.max = '00:00'; + timeObject.amount = '0'; + timeObject.maxAmount = '0'; + + setRequestHoursDeductions(); + } + + /** + * Sets the collection for given day types to sent list of day types, + * also initializes the day types + * + * @param {String} dateType from|to + * @param {Array} listOfDayTypes collection of available day types + */ + function setDayTypes (dateType, listOfDayTypes) { + // will create either of leaveRequestFromDayTypes or leaveRequestToDayTypes key + var keyForDayTypeCollection = 'request' + _.startCase(dateType) + 'DayTypes'; + + detailsController[keyForDayTypeCollection] = listOfDayTypes; + + if (detailsController.isMode('create')) { + detailsController.request[dateType + '_date_type'] = detailsController[keyForDayTypeCollection][0].value; + } + } + + /** + * Updates time ranges as per the work pattern for "from" date + * and updates the deduction fields boundaries + * + * @NOTE In case of a single day, also show "to" time loading + * + * @return {Promise} + */ + function setDaysSelectionModeExtended () { + if (!detailsController.isCalculationUnit('hours') || !detailsController.uiOptions.fromDate) { + return $q.resolve(); + } + + detailsController.disableAndShowLoadingTimeInput('from'); + (!detailsController.uiOptions.multipleDays) && detailsController.disableAndShowLoadingTimeInput('to'); + + return loadTimeRangesFromWorkPattern('from') + .then(function () { + setDeductionMaximumBoundary('from', true); + }); + } + + /** + * Sets deduction maximum and default amounts for a given day type + * + * @param {String} timeType from|to + * @param {Boolean} setDefaultValue if TRUE, then set the current value to maximum + */ + function setDeductionMaximumBoundary (timeType, setDefaultValue) { + var uiOptions = detailsController.uiOptions; + var dateType = uiOptions.multipleDays ? timeType : 'from'; + var timeObject = uiOptions.times[dateType]; + var timeFrom = uiOptions.multipleDays && dateType === 'to' ? timeObject.min : uiOptions.times.from.time; + var timeTo = uiOptions.multipleDays && dateType === 'from' ? timeObject.max : uiOptions.times.to.time; + var deduction = workDays[dateType].number_of_hours + ? getTimeDifferenceInHours(timeFrom, timeTo).toString() + : '0'; + + timeObject.maxAmount = deduction; + (setDefaultValue) && (timeObject.amount = timeObject.maxAmount); + } + + /** + * Sets deductions in hours from UI to detailsController.request + */ + function setRequestHoursDeductions () { + var times = detailsController.uiOptions.times; + + detailsController.request.from_date_amount = !isNaN(+times.from.amount) ? times.from.amount : null; + detailsController.request.to_date_amount = !isNaN(+times.to.amount) ? times.to.amount : null; + } + + /** + * Updates time ranges as per the work pattern for "from" date + * and updates the deduction fields boundaries + * + * @return {Promise} + */ + function updateFromTimeRangeAndDeductionBoundary () { + if (!detailsController.isCalculationUnit('hours')) { + return; + } + + return loadTimeRangesFromWorkPattern('from') + .then(function () { + setDeductionMaximumBoundary('from', true); + }); + } } }); From 88b1ae073827db0c56da41f984235ff7fe2a74de Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Thu, 15 Mar 2018 15:59:15 +0000 Subject: [PATCH 081/203] PCHR-3438: Augment TOIL instance and remove old code --- .../shared/instances/toil-request.instance.js | 29 ++----------------- .../instances/toil-request.instance.spec.js | 27 ++--------------- 2 files changed, 6 insertions(+), 50 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/instances/toil-request.instance.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/instances/toil-request.instance.js index ab817222b97..4cc83d29c92 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/instances/toil-request.instance.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/instances/toil-request.instance.js @@ -21,37 +21,14 @@ define([ */ defaultCustomData: function () { var toilCustomData = { - toilDurationHours: '0', - toilDurationMinutes: '0', + from_date_amount: 0, + to_date_amount: 0, request_type: 'toil' }; return _.assign({}, LeaveRequestInstance.defaultCustomData(), toilCustomData); }, - /** - * Sets the duration hours and minutes from toil_duration on instantiation. - * - * @param {Object} attributes that need to be transformed - * @return {Object} updated attributes object - */ - transformAttributes: function (attributes) { - var duration = Number(attributes.toil_duration); - if (duration) { - attributes.toilDurationHours = Math.floor(duration / 60).toString(); - attributes.toilDurationMinutes = (duration % 60).toString(); - } - - return attributes; - }, - - /** - * Update duration - */ - updateDuration: function () { - this.toil_duration = Number(this.toilDurationHours) * 60 + Number(this.toilDurationMinutes); - }, - /** * Override of parent method * @@ -59,7 +36,7 @@ define([ * @param {string} key - The property name */ toAPIFilter: function (result, __, key) { - if (!_.includes(['balance_change', 'dates', 'comments', 'files', 'toilDurationHours', 'toilDurationMinutes'], key)) { + if (!_.includes(['balance_change', 'dates', 'comments', 'files', 'toilDurationMinutes'], key)) { result[key] = this[key]; } } diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/instances/toil-request.instance.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/instances/toil-request.instance.spec.js index e2e247faa64..dd52a3e6240 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/instances/toil-request.instance.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/instances/toil-request.instance.spec.js @@ -48,9 +48,9 @@ define([ expect(instance).toBeDefined(); }); - it('default toil Duration value is set', function () { - expect(instance.toilDurationHours).toBe('0'); - expect(instance.toilDurationMinutes).toBe('0'); + it('default fields for backend are set', function () { + expect(instance.from_date_amount).toBe(0); + expect(instance.to_date_amount).toBe(0); }); it('initializes request type', function () { @@ -58,32 +58,11 @@ define([ }); }); - describe('updateDuration()', function () { - beforeEach(function () { - instance = TOILRequestInstance.init({}, false); - instance.toilDurationHours = 1; - instance.toilDurationMinutes = 1; - instance.updateDuration(); - }); - - it('updates durations in minutes', function () { - expect(instance.toil_duration).toEqual(61); - }); - }); - describe('edit toil', function () { beforeEach(function () { var toilRequest = requestMockData.findBy('request_type', 'toil'); instance = TOILRequestInstance.init(toilRequest); }); - - it('sets duration hours', function () { - expect(instance.toilDurationHours).toEqual('3'); - }); - - it('sets duration minutes', function () { - expect(instance.toilDurationMinutes).toEqual('1'); - }); }); }); }); From 05da16ee0a98bee7af618ba41df163a6526b2258 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Thu, 15 Mar 2018 16:02:03 +0000 Subject: [PATCH 082/203] PCHR-3438: Augment TOIL Modal --- .../request-modal-details-toil.controller.js | 171 ++++++++++++++++-- .../mocks/helpers/request-modal-helper.js | 25 ++- ...equest-popup-details-tab.component.spec.js | 5 +- ...uest-modal-details-toil.controller.spec.js | 125 ++++++++++--- .../hours-unit-multiple-days.html | 6 +- .../hours-unit-single-day.html | 4 +- .../details-tab/common.html | 2 +- .../leave-request-popup/details-tab/toil.html | 80 ++++---- 8 files changed, 327 insertions(+), 91 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js index 95e1e229e34..51cb46e944a 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js @@ -2,8 +2,9 @@ define([ 'common/lodash', + 'common/moment', 'leave-absences/shared/modules/controllers' -], function (_, controllers) { +], function (_, moment, controllers) { controllers.controller('RequestModalDetailsToilController', RequestModalDetailsToilController); RequestModalDetailsToilController.$inject = ['$log', '$q', '$rootScope', 'api.optionGroup', 'AbsenceType', 'detailsController']; @@ -12,25 +13,28 @@ define([ $log.debug('RequestModalDetailsToilController'); var initialRequestAttributes; + var skipSettingDefaultDuration = !detailsController.isMode('create'); var expirationConditions = { hasPreviousExpirationDate: null, hasExpirationFromAdminSettings: null }; detailsController.canDisplayToilExpirationField = false; - detailsController.calculateBalanceChange = calculateBalanceChange; detailsController.canCalculateChange = canCalculateChange; detailsController.canSubmit = canSubmit; detailsController.clearExpiryDate = clearExpiryDate; detailsController.initChildController = initChildController; - detailsController.onDateChangeExtended = tryToCalculateExpiryDate; - detailsController.setDaysSelectionModeExtended = tryToCalculateExpiryDate; + detailsController.initTimesExtended = initTimes; + detailsController.initWatchersExtended = initWatchers; + detailsController.onDateChangeExtended = onDateChangeHandler; + detailsController.setDaysSelectionModeExtended = onDaysSelectionModeHandler; detailsController.updateExpiryDate = updateExpiryDate; (function init () { - initAccrueValueWatcher(); setInitialRequestAttributes(); + setTimeInputsRanges(); + !detailsController.isMode('create') && initDuration(); })(); /** @@ -45,6 +49,21 @@ define([ return $q.resolve(detailsController.balance.change); } + /** + * Calculates the TOIL maximum duration and sets its default value + */ + function calculateDuration () { + if (!detailsController.request.from_date || !detailsController.request.to_date) { + detailsController.uiOptions.max_toil_duration_and_accrual = null; + detailsController.uiOptions.toil_duration_in_hours = null; + + return; + } + + detailsController.uiOptions.max_toil_duration_and_accrual = + moment.duration(moment(detailsController.request.to_date).diff(detailsController.request.from_date)).asHours(); + } + /** * Calculates the TOIL expiry date and updates the UI and the Request's * expiry date value. @@ -159,7 +178,7 @@ define([ if (!field.value) { return $q.reject([]); } else { - return $q.resolve(field.value); + return $q.resolve(moment(field.value).format('YYYY-MM-DD')); } } @@ -181,6 +200,15 @@ define([ ); } + /** + * Initialises duration by converting it from minutes to hours + * and setting to a separate variable in UI options + */ + function initDuration () { + detailsController.uiOptions.toil_duration_in_hours = + detailsController.request.toil_duration / 60; + } + /** * Initialises the expiration conditions for the current toil request * using the following rules: @@ -229,10 +257,6 @@ define([ * When accrue value changes it, if possible, calculates the balance change. */ function initAccrueValueWatcher () { - if (detailsController.isMode('view')) { - return; - } - $rootScope.$watch( function () { return detailsController.request.toil_to_accrue; @@ -244,6 +268,80 @@ define([ }); } + /** + * Initialises watcher for Duration value. + * When Duration value changes, it sets this value to the Accrual as well. + */ + function initDurationValueWatcher () { + $rootScope.$watch( + function () { + return detailsController.uiOptions.toil_duration_in_hours; + }, + function (oldValue, newValue) { + if (detailsController.isCalculationUnit('hours') && oldValue !== newValue) { + detailsController.request.toil_to_accrue = + detailsController.uiOptions.toil_duration_in_hours; + } + + detailsController.request.toil_duration = + detailsController.uiOptions.toil_duration_in_hours + ? detailsController.uiOptions.toil_duration_in_hours * 60 + : null; + }); + } + + /** + * Initialises and sets the "from" and "to" times + * + * @return {Promise} + */ + function initTimes () { + var times = detailsController.uiOptions.times; + + times.from.time = moment(detailsController.request.from_date).format('HH:mm'); + times.to.time = moment(detailsController.request.to_date).format('HH:mm'); + + if (!detailsController.uiOptions.multipleDays) { + detailsController.updateEndTimeInputMinTime(detailsController.uiOptions.times.from.time); + } + } + + /** + * Initialises watcher for times values. + * The values of time fields define the maximum and default Duration values. + */ + function initTimesWatcher () { + ['from', 'to'].forEach(function (dateType) { + $rootScope.$watch( + function () { + return detailsController.uiOptions.times[dateType].time; + }, + function (oldValue, newValue) { + if (oldValue === newValue) { + return; + } + + detailsController.setRequestDateTimesAndDateTypes(); + tryToCalculateExpiryDate(); + calculateDuration(); + setDefaultDuration(); + }); + }); + } + + /** + * Initialises watchers for Accruals and Duration values + */ + function initWatchers () { + if (detailsController.isMode('view')) { + return; + } + + initAccrueValueWatcher(); + initDurationValueWatcher(); + initTimesWatcher(); + } + /** * Initializes leave request toil amounts * @@ -256,11 +354,62 @@ define([ }); } + /** + * Handles the dates change + */ + function onDateChangeHandler () { + calculateDuration(); + setDefaultDuration(); + + return tryToCalculateExpiryDate(); + } + + /** + * Handles the days selection mode change + */ + function onDaysSelectionModeHandler () { + setTimeInputsRanges(); + + if (!detailsController.uiOptions.multipleDays) { + detailsController.updateEndTimeInputMinTime(detailsController.uiOptions.times.from.time); + } + + calculateDuration(); + !skipSettingDefaultDuration ? setDefaultDuration() : (skipSettingDefaultDuration = false); + + return tryToCalculateExpiryDate(); + } + + /** + * Sets default duration as a maximum allowed duration value + */ + function setDefaultDuration () { + detailsController.uiOptions.toil_duration_in_hours = + detailsController.uiOptions.max_toil_duration_and_accrual; + } + /** * Stores the initial request attributes to determine if there has been a change. */ function setInitialRequestAttributes () { - initialRequestAttributes = angular.copy(detailsController.request.attributes()); + initialRequestAttributes = _.cloneDeep(detailsController.request.attributes()); + } + + /** + * Sets ranges for both start and end times depending on the day selection mode + */ + function setTimeInputsRanges () { + if (detailsController.uiOptions.multipleDays) { + ['from', 'to'].forEach(function (dateType) { + detailsController.uiOptions.times[dateType].min = '00:00'; + detailsController.uiOptions.times[dateType].max = '23:45'; + }); + } else { + detailsController.uiOptions.times.from.min = '00:00'; + detailsController.uiOptions.times.from.max = '23:30'; + detailsController.uiOptions.times.to.min = '00:15'; + detailsController.uiOptions.times.to.max = '23:45'; + } } /** diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/helpers/request-modal-helper.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/helpers/request-modal-helper.js index 78acc4eedec..717fbab1df6 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/helpers/request-modal-helper.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/helpers/request-modal-helper.js @@ -1,4 +1,4 @@ -/* eslint-env amd */ +/* eslint-env amd, jasmine */ define([ 'common/lodash', @@ -87,7 +87,7 @@ define([ }, /** - * sets from and/or to dates + * Sets "from" and/or "to" dates * * @param {object} controller controller object * @param {String} from date set if passed @@ -107,6 +107,27 @@ define([ controller.dateChangeHandler('to'); $rootScope.$digest(); } + }, + + /** + * Sets "from" and/or "to" times + * + * @param {Object} controller - controller object + * @param {String} from - time in HH:mm format, optional + * @param {String} to - time in HH:mm format, optional + */ + setTestTimes: function (controller, from, to) { + var $rootScope = getDependency('$rootScope'); + + if (from) { + controller.uiOptions.times.from.time = from; + $rootScope.$digest(); + } + + if (to) { + controller.uiOptions.times.to.time = to; + $rootScope.$digest(); + } } }; diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-request-popup-details-tab.component.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-request-popup-details-tab.component.spec.js index 1634a170c64..bfd12d480bd 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-request-popup-details-tab.component.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-request-popup-details-tab.component.spec.js @@ -216,6 +216,7 @@ define([ controller.period = {}; requestModalHelper.setTestDates(controller, date2016); + fromDate = moment(controller.uiOptions.fromDate).format(sharedSettings.serverDateFormat); }); @@ -1254,9 +1255,9 @@ define([ expect(controller.request.contact_id).toEqual(CRM.vars.leaveAndAbsences.contactId.toString()); expect(controller.request.type_id).toEqual(leaveRequestAttributes.type_id); expect(controller.request.status_id).toEqual(waitingApprovalStatus.value); - expect(controller.request.from_date).toEqual(leaveRequestAttributes.from_date); + expect(controller.request.from_date).toEqual(moment(leaveRequestAttributes.from_date).format('YYYY-MM-DD')); expect(controller.request.from_date_type).toEqual(leaveRequestAttributes.from_date_type); - expect(controller.request.to_date).toEqual(leaveRequestAttributes.to_date); + expect(controller.request.to_date).toEqual(moment(leaveRequestAttributes.to_date).format('YYYY-MM-DD')); expect(controller.request.to_date_type).toEqual(leaveRequestAttributes.to_date_type); }); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js index 08c24b4c0e0..cb11f4100a8 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js @@ -27,6 +27,7 @@ define([ var date2016 = '01/12/2016'; var date2016To = '02/12/2016'; // Must be greater than `date2016` var date2017 = '01/02/2017'; + var date2017Server = '2017-01-02'; beforeEach(module('common.mocks', 'leave-absences.templates', 'leave-absences.mocks', 'manager-leave', function (_$provide_) { $provide = _$provide_; @@ -93,6 +94,11 @@ define([ expect(controller.uiOptions.multipleDays).toBe(true); }); + it('sets times bounaries to 00:00 - 23:45', function () { + expect(controller.uiOptions.times.from.min).toBe('00:00'); + expect(controller.uiOptions.times.from.max).toBe('23:45'); + }); + describe('when multiple/single days mode changes', function () { describe('when the balance can but fails to be calculated', function () { beforeEach(function () { @@ -129,18 +135,88 @@ define([ }); }); + describe('when both to and from dates and times are set', function () { + beforeEach(function () { + requestModalHelper.setTestDates(controller, '03/18/2018', '03/20/2018'); + requestModalHelper.setTestTimes(controller, '11:30', '16:15'); + }); + + it('sets the maximum duration and accrual values as a difference between to and from date/times in hours', function () { + expect(controller.uiOptions.max_toil_duration_and_accrual).toBe(12.5 + 24 + 16.25); + }); + + it('defaults the duration to its maximum', function () { + expect(controller.uiOptions.toil_duration_in_hours).toBe(controller.uiOptions.max_toil_duration_and_accrual); + }); + + it('converts duration into minutes and sets to request', function () { + expect(controller.request.toil_duration).toBe(controller.uiOptions.toil_duration_in_hours * 60); + }); + + describe('when single day mode selected', function () { + beforeEach(function () { + controller.uiOptions.multipleDays = false; + + controller.daysSelectionModeChangeHandler(); + $rootScope.$digest(); + }); + + it('updates the maximum duration and accrual value', function () { + expect(controller.uiOptions.max_toil_duration_and_accrual).toBe(4.75); + }); + }); + + describe('when from time is greater than to time and then single day mode selected', function () { + beforeEach(function () { + requestModalHelper.setTestTimes(controller, '19:30', '16:15'); + + controller.uiOptions.multipleDays = false; + + controller.daysSelectionModeChangeHandler(); + $rootScope.$digest(); + }); + + it('flushes maximum duration and accrual value', function () { + expect(controller.uiOptions.max_toil_duration_and_accrual).toBe(null); + }); + + it('flushes accrual value', function () { + expect(controller.uiOptions.toil_duration_in_hours).toBe(null); + expect(controller.request.toil_duration).toBe(null); + }); + }); + + describe('when the request is in hours', function () { + beforeEach(function () { + controller.selectedAbsenceType.calculation_unit_name = 'hours'; + }); + + afterEach(function () { + controller.selectedAbsenceType.calculation_unit_name = 'days'; + }); + + describe('when duration value has been customised', function () { + beforeEach(function () { + controller.uiOptions.toil_duration_in_hours = 10; + + $rootScope.$digest(); + }); + + it('sets the accrual value to the current value of duration', function () { + expect(controller.request.toil_to_accrue).toBe(controller.uiOptions.toil_duration_in_hours); + }); + }); + }); + }); + describe('create', function () { describe('with selected duration and dates', function () { describe('when multiple days request', function () { beforeEach(function () { - var toilAccrue = optionGroupMock.specificObject('hrleaveandabsences_toil_amounts', 'name', 'quarter_day'); - requestModalHelper.setTestDates(controller, date2016, date2016To); - controller.request.toilDurationHours = 1; - controller.request.updateDuration(); - controller.request.toil_to_accrue = toilAccrue.value; + requestModalHelper.setTestTimes(controller, '08:00', '10:00'); - $rootScope.$apply(); + $rootScope.$digest(); }); it('sets expiry date', function () { @@ -149,19 +225,7 @@ define([ it('calls calculateToilExpiryDate on AbsenceType', function () { expect(AbsenceTypeAPI.calculateToilExpiryDate.calls.mostRecent().args[0]).toEqual(controller.request.type_id); - expect(AbsenceTypeAPI.calculateToilExpiryDate.calls.mostRecent().args[1]).toEqual(controller.request.to_date); - }); - - describe('when user changes number of days selected', function () { - beforeEach(function () { - controller.daysSelectionModeChangeHandler(); - }); - - it('does not reset toil attributes', function () { - expect(controller.request.toilDurationHours).not.toEqual('0'); - expect(controller.request.toilDurationMinutes).toEqual('0'); - expect(controller.request.toil_to_accrue).not.toEqual(''); - }); + expect(AbsenceTypeAPI.calculateToilExpiryDate.calls.mostRecent().args[1]).toEqual(moment(controller.request.to_date).format('YYYY-MM-DD')); }); }); @@ -169,10 +233,11 @@ define([ beforeEach(function () { controller.uiOptions.multipleDays = false; requestModalHelper.setTestDates(controller, date2016); + requestModalHelper.setTestTimes(controller, '08:00', '10:00'); }); it('calls calculateToilExpiryDate on AbsenceType', function () { - expect(AbsenceTypeAPI.calculateToilExpiryDate.calls.mostRecent().args[1]).toEqual(controller.request.from_date); + expect(AbsenceTypeAPI.calculateToilExpiryDate.calls.mostRecent().args[1]).toEqual(moment(controller.request.from_date).format('YYYY-MM-DD')); }); }); }); @@ -184,6 +249,9 @@ define([ beforeEach(function () { toilRequest = TOILRequestInstance.init(leaveRequestData.findBy('request_type', 'toil')); toilRequest.contact_id = CRM.vars.leaveAndAbsences.contactId.toString(); + toilRequest.from_date = '2018-03-04 12:00'; + toilRequest.to_date = '2018-03-06 10:00'; + toilRequest.toil_duration = 120; compileComponent({ leaveType: 'toil', @@ -215,6 +283,19 @@ define([ it('shows balance', function () { expect(controller.uiOptions.showBalance).toBeTruthy(); }); + + it('sets times', function () { + expect(controller.uiOptions.times.from.time).toBe('12:00'); + expect(controller.uiOptions.times.to.time).toBe('10:00'); + }); + + it('sets maximum duration', function () { + expect(controller.uiOptions.max_toil_duration_and_accrual).toBe(12 + 24 + 10); + }); + + it('sets custom duration', function () { + expect(controller.uiOptions.toil_duration_in_hours).toBe(2); + }); }); }); @@ -376,7 +457,7 @@ define([ role: 'manager', request: toilRequest }); - controller.request.to_date = date2017; + controller.request.to_date = date2017Server; controller.onDateChangeExtended(); $rootScope.$digest(); }); @@ -394,7 +475,7 @@ define([ role: 'staff', request: toilRequest }); - controller.request.to_date = date2017; + controller.request.to_date = date2017Server; controller.onDateChangeExtended(); $rootScope.$digest(); }); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-multiple-days.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-multiple-days.html index bbe439c48ae..6483508db00 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-multiple-days.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-multiple-days.html @@ -19,7 +19,7 @@ ng-change="detailsTab.dateChangeHandler('from')"/> -
+
@@ -54,7 +54,7 @@
@@ -71,7 +71,7 @@ ng-change="detailsTab.dateChangeHandler('to')"/>
-
+
diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-single-day.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-single-day.html index c89cbcb6894..88250b7402b 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-single-day.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-single-day.html @@ -27,7 +27,7 @@
-
+
-
+
diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html index 47936040869..10f6a536d65 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html @@ -1,52 +1,36 @@
-
-
- -
-
- - -
+
+ @@ -77,8 +61,8 @@ time-amount-picker-disabled="detailsTab.isMode('view')" time-amount-picker-value="detailsTab.request.toil_to_accrue" time-amount-picker-min-amount="0" - time-amount-picker-max-amount="24" - time-amount-picker-interval="15" + time-amount-picker-max-amount="detailsTab.uiOptions.max_toil_duration_and_accrual" + time-amount-picker-interval="detailsTab.uiOptions.time_interval" >
From 90368172208a0bf30abf9c50e7323783ea9b5343 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Thu, 15 Mar 2018 17:59:04 +0000 Subject: [PATCH 083/203] PCHR-3438: Do not amend time if TOIL --- .../api/v3/LeaveRequest.php | 3 +- .../tests/phpunit/api/v3/LeaveRequestTest.php | 59 ++++++++++++++++++- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/api/v3/LeaveRequest.php b/uk.co.compucorp.civicrm.hrleaveandabsences/api/v3/LeaveRequest.php index 303e69388b6..e31a68e6630 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/api/v3/LeaveRequest.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/api/v3/LeaveRequest.php @@ -823,7 +823,8 @@ function _civicrm_api3_leave_request_set_time_for_leave_dates(&$params) { $absenceType = CRM_HRLeaveAndAbsences_BAO_AbsenceType::findById($params['type_id']); - if($absenceType->isCalculationUnitInHours()) { + if($absenceType->isCalculationUnitInHours() || + $params['request_type'] === CRM_HRLeaveAndAbsences_BAO_LeaveRequest::REQUEST_TYPE_TOIL) { return; } diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/api/v3/LeaveRequestTest.php b/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/api/v3/LeaveRequestTest.php index aab38d5e4ea..fa07f491122 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/api/v3/LeaveRequestTest.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/api/v3/LeaveRequestTest.php @@ -2149,7 +2149,8 @@ public function testCalculateBalanceChangeWithAllRequiredParameters() { 'from_date_type' => $fromType, 'to_date' => $toDate, 'to_date_type' => $toType, - 'type_id' => $absenceType->id + 'type_id' => $absenceType->id, + 'request_type' => LeaveRequest::REQUEST_TYPE_LEAVE ]); $this->assertEquals($expectedResultsBreakdown, $result['values']); } @@ -4373,6 +4374,61 @@ public function testTheTimeForFromAndToDateOfLeaveRequestIsAddedCorrectlyWhenLea $this->assertEquals($toDate->format('Y-m-d') ." 23:59:00", $leaveRequest->to_date); } + public function testTheTimeForFromAndToDateOfLeaveRequestStaysUntouchedWhenRequestIsTOIL() { + $absenceType = AbsenceTypeFabricator::fabricate([ + 'allow_accruals_request' => true, + 'max_leave_accrual' => 10, + // The calculation unit is in days since otherwise a check for + // calculation unit in days will take action and this test will be invalid + 'calculation_unit' => 1, + 'allow_accrue_in_the_past' => true + ]); + $expectedFromDate = '2016-01-08 01:23:45'; + $expectedToDate = '2016-01-10 12:34:56'; + $fromDate = new DateTime($expectedFromDate); + $toDate = new DateTime($expectedToDate); + $contactID = 1; + $this->registerCurrentLoggedInContactInSession($contactID); + + $period = AbsencePeriodFabricator::fabricate([ + 'start_date' => $fromDate->format('YmdHis'), + 'end_date' => $toDate->format('YmdHis'), + ]); + + $contract = HRJobContractFabricator::fabricate( + ['contact_id' => $contactID], + ['period_start_date' => $fromDate->format('Y-m-d')] + ); + + $periodEntitlement = LeavePeriodEntitlementFabricator::fabricate([ + 'type_id' => $absenceType->id, + 'contact_id' => $contactID, + 'period_id' => $period->id + ]); + + $entitlementBalanceChange = 3; + $this->createLeaveBalanceChange($periodEntitlement->id, $entitlementBalanceChange); + WorkPatternFabricator::fabricateWithA40HourWorkWeek(['is_default' => true]); + + $result = civicrm_api3('LeaveRequest', 'create', [ + 'contact_id' => $contract['contact_id'], + 'type_id' => $absenceType->id, + 'from_date' => $expectedFromDate, + 'from_date_type' => $this->leaveRequestDayTypes['all_day']['value'], + 'to_date' => $expectedToDate, + 'to_date_type' => $this->leaveRequestDayTypes['all_day']['value'], + 'status_id' => 3, + 'toil_duration' => 10, + 'toil_to_accrue' => 2, + 'request_type' => LeaveRequest::REQUEST_TYPE_TOIL, + 'sequential' => 1 + ]); + + $leaveRequest = LeaveRequest::findById($result['id']); + $this->assertEquals($expectedFromDate, $leaveRequest->from_date); + $this->assertEquals($expectedToDate, $leaveRequest->to_date); + } + public function testCreateReturnsFalseForFromEmailParameterWhenFromEmailIsNotConfigured() { $contactID = 1; $this->registerCurrentLoggedInContactInSession($contactID); @@ -4627,4 +4683,3 @@ public function testGetContactWorkDayForDateThrowsAnExceptionWhenThereIsNoWorkDa ); } } - From 8c4e5839ee2730c70c40217ddde8b1e9c21d431a Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Fri, 16 Mar 2018 10:21:14 +0000 Subject: [PATCH 084/203] PCHR-3438: Improve TOIL template layout --- .../hours-unit-multiple-days.html | 2 +- .../leave-request-popup/details-tab/toil.html | 23 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-multiple-days.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-multiple-days.html index 6483508db00..2250998c432 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-multiple-days.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-multiple-days.html @@ -2,7 +2,7 @@
diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html index 10f6a536d65..7c74783345e 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html @@ -14,23 +14,22 @@
-
- Customise deduction for - {{detailsTab.uiOptions.fromDate | formatDate}} - - (eg. exclude lunch time) +
+
-
+
- +
+ +
From a2768cb132bee598e627f9528ecb356aa6f3afa9 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Fri, 16 Mar 2018 10:44:18 +0000 Subject: [PATCH 085/203] PCHR-3438: Sort TOIL amounts --- .../request-modal-details-toil.controller.js | 2 +- .../test/mocks/data/option-group.data.js | 24 +++++++++---------- ...uest-modal-details-toil.controller.spec.js | 5 ++++ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js index 51cb46e944a..021ca32d01c 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js @@ -350,7 +350,7 @@ define([ function loadToilAmounts () { return OptionGroup.valuesOf('hrleaveandabsences_toil_amounts') .then(function (amounts) { - detailsController.toilAmounts = _.indexBy(amounts, 'value'); + detailsController.toilAmounts = _.sortBy(amounts, 'value'); }); } diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/data/option-group.data.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/data/option-group.data.js index fce76f3e0f2..aeebb0deed6 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/data/option-group.data.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/mocks/data/option-group.data.js @@ -681,6 +681,18 @@ define([ 'is_reserved': '1', 'is_active': '1' }, + { + 'id': '1147', + 'option_group_id': '146', + 'label': '1 3/4 Days', + 'value': '1.75', + 'name': 'one_and_three_quarters_days', + 'is_default': '0', + 'weight': '8', + 'is_optgroup': '0', + 'is_reserved': '1', + 'is_active': '1' + }, { 'id': '1141', 'option_group_id': '146', @@ -753,18 +765,6 @@ define([ 'is_reserved': '1', 'is_active': '1' }, - { - 'id': '1147', - 'option_group_id': '146', - 'label': '1 3/4 Days', - 'value': '1.75', - 'name': 'one_and_three_quarters_days', - 'is_default': '0', - 'weight': '8', - 'is_optgroup': '0', - 'is_reserved': '1', - 'is_active': '1' - }, { 'id': '1148', 'option_group_id': '146', diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js index cb11f4100a8..429e900675a 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js @@ -90,6 +90,11 @@ define([ expect(Object.keys(controller.toilAmounts).length).toBeGreaterThan(0); }); + fit('sorts toil amounts by value', function () { + expect(_.pluck(controller.toilAmounts, 'value')).toEqual( + _.pluck(controller.toilAmounts, 'value').sort()); + }); + it('defaults to a multiple day selection', function () { expect(controller.uiOptions.multipleDays).toBe(true); }); From c4aff32f6440e48f42abbc33ccd0bf194abc196e Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Fri, 16 Mar 2018 11:50:42 +0000 Subject: [PATCH 086/203] PCHR-3438: Fix loading UI and layout --- ...ave-request-popup-details-tab.component.js | 24 ++++--- ...equest-popup-details-tab.component.spec.js | 14 ++++ .../hours-unit-multiple-days.html | 70 +++++++++---------- 3 files changed, 65 insertions(+), 43 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-popup-details-tab.component.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-popup-details-tab.component.js index 9542d38f3a4..5efb55260cd 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-popup-details-tab.component.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-popup-details-tab.component.js @@ -260,14 +260,7 @@ define([ } }) .catch(handleError) - .finally(function () { - vm.loading[dateType + 'DayTypes'] = false; - - if (isCalculationUnit('hours')) { - vm.uiOptions.times.from.loading = false; - vm.uiOptions.times.to.loading = false; - } - }); + .finally(finishLoadingTimesAndDateTypes); } /** @@ -296,6 +289,7 @@ define([ return $q.resolve() .then(setRequestDateTimesAndDateTypes) .then(vm.setDaysSelectionModeExtended) + .then(finishLoadingTimesAndDateTypes) .then(!vm.uiOptions.multipleDays && performBalanceChangeCalculation); } @@ -312,6 +306,19 @@ define([ timeObject.disabled = true; } + /** + * Hides loading indicators for times and date types inputs + */ + function finishLoadingTimesAndDateTypes () { + ['from', 'to'].forEach(function (dateType) { + vm.loading[dateType + 'DayTypes'] = false; + + if (isCalculationUnit('hours')) { + vm.uiOptions.times[dateType].loading = false; + } + }); + } + /** * Gets absence period for the given date * @@ -746,6 +753,7 @@ define([ } }) .then(absenceTypeUnitChanged && setRequestDateTimesAndDateTypes) + .then(finishLoadingTimesAndDateTypes) .then(performBalanceChangeCalculation); } diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-request-popup-details-tab.component.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-request-popup-details-tab.component.spec.js index bfd12d480bd..29af9f096de 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-request-popup-details-tab.component.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-request-popup-details-tab.component.spec.js @@ -561,6 +561,20 @@ define([ expect(controller.uiOptions.multipleDays).toBeFalsy(); }); + describe('after changed to multiple days mode', function () { + beforeEach(function () { + controller.uiOptions.multipleDays = true; + + controller.daysSelectionModeChangeHandler(); + $rootScope.$digest(); + }); + + it('shows both "from" and "to" times', function () { + expect(controller.uiOptions.times.from.loading).toBe(false); + expect(controller.uiOptions.times.to.loading).toBe(false); + }); + }); + describe('after from date is selected', function () { var timeFromObject, request, workDayMock; diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-multiple-days.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-multiple-days.html index 2250998c432..e2b8a599428 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-multiple-days.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-multiple-days.html @@ -97,41 +97,41 @@
- -
-
-
- {{detailsTab.uiOptions.times.to.amount | timeUnitApplier : detailsTab.selectedAbsenceType.calculation_unit_name}} - for {{detailsTab.uiOptions.toDate | formatDate}} or - - set custom deduction -
+
+ +
+
+
+ {{detailsTab.uiOptions.times.to.amount | timeUnitApplier : detailsTab.selectedAbsenceType.calculation_unit_name}} + for {{detailsTab.uiOptions.toDate | formatDate}} or + + set custom deduction
-
-
- Customise deduction for - {{detailsTab.uiOptions.toDate | formatDate}} - - (eg. subtract break time) -
-
- - - - -
+
+
+
+ Customise deduction for + {{detailsTab.uiOptions.toDate | formatDate}} + + (eg. subtract break time) +
+
+ + + +
- -
+
+
From 06d0e0b1854d359717906efd0987b48d1628956f Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Fri, 16 Mar 2018 12:40:30 +0000 Subject: [PATCH 087/203] PCHR-3438: Fix JavaScript Error --- .../leave-request-popup-details-tab.component.js | 8 +------- .../request-modal-details-leave.controller.js | 4 ++-- ...request-modal-details-leave.controller.spec.js | 15 +++++++++++++++ .../request-modal-details-toil.controller.spec.js | 2 +- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-popup-details-tab.component.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-popup-details-tab.component.js index 5efb55260cd..e8ac4cae55c 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-popup-details-tab.component.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-popup-details-tab.component.js @@ -745,13 +745,7 @@ define([ return $q.resolve() .then(absenceTypeUnitChanged && setDaysSelectionMode) - .then(function () { - if (absenceTypeUnitChanged) { - return vm.onAbsenceTypeUpdateExtended - ? vm.onAbsenceTypeUpdateExtended() - : $q.resolve(); - } - }) + .then(absenceTypeUnitChanged && vm.onAbsenceTypeUpdateExtended) .then(absenceTypeUnitChanged && setRequestDateTimesAndDateTypes) .then(finishLoadingTimesAndDateTypes) .then(performBalanceChangeCalculation); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller.js index 813e6ea9634..baf7bed65dc 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller.js @@ -449,8 +449,8 @@ define([ * @return {Promise} */ function updateFromTimeRangeAndDeductionBoundary () { - if (!detailsController.isCalculationUnit('hours')) { - return; + if (!detailsController.isCalculationUnit('hours') || !detailsController.uiOptions.fromDate) { + return $q.resolve(); } return loadTimeRangesFromWorkPattern('from') diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-leave.controller.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-leave.controller.spec.js index a768c658240..60f438ac7a2 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-leave.controller.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-leave.controller.spec.js @@ -170,6 +170,21 @@ define([ expect(controller.canCalculateChange()).toBe(true); }); }); + + describe('when unit changed to hours by changing an absence type', function () { + beforeEach(function () { + controller.absenceTypes[1].calculation_unit_name = 'hours'; + controller.request.type_id = controller.absenceTypes[1].id; + + spyOn(controller.request, 'getWorkDayForDate'); + $rootScope.$broadcast('LeaveRequestPopup::absenceTypeChanged'); + $rootScope.$digest(); + }); + + it('does not yet fetch work pattern details for "from" date', function () { + expect(controller.request.getWorkDayForDate).not.toHaveBeenCalled(); + }); + }); }); describe('when unit is in hours', function () { diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js index 429e900675a..a46f23d5cba 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js @@ -90,7 +90,7 @@ define([ expect(Object.keys(controller.toilAmounts).length).toBeGreaterThan(0); }); - fit('sorts toil amounts by value', function () { + it('sorts toil amounts by value', function () { expect(_.pluck(controller.toilAmounts, 'value')).toEqual( _.pluck(controller.toilAmounts, 'value').sort()); }); From e806a436980fbedd7c89aaefba5fdd4f22c28efa Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Fri, 16 Mar 2018 13:23:47 +0000 Subject: [PATCH 088/203] PCHR-3438: Remove unneeded disabling property --- .../components/leave-request-popup-details-tab.component.js | 1 - .../sub-controllers/request-modal-details-leave.controller.js | 1 - .../by-unit-and-days-mode/hours-unit-multiple-days.html | 4 ++-- .../by-unit-and-days-mode/hours-unit-single-day.html | 4 ++-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-popup-details-tab.component.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-popup-details-tab.component.js index e8ac4cae55c..84ca7691fcb 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-popup-details-tab.component.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-popup-details-tab.component.js @@ -303,7 +303,6 @@ define([ var timeObject = vm.uiOptions.times[type]; timeObject.loading = true; - timeObject.disabled = true; } /** diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller.js index baf7bed65dc..1e392f1f313 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller.js @@ -95,7 +95,6 @@ define([ timeObject.min = timeMin || '00:00'; timeObject.max = timeMax || '00:00'; timeObject.time = type === 'to' ? timeObject.max : timeObject.min; - timeObject.disabled = false; } /** diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-multiple-days.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-multiple-days.html index e2b8a599428..518e7aed195 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-multiple-days.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/by-unit-and-days-mode/hours-unit-multiple-days.html @@ -29,7 +29,7 @@
- {{request.from_date | formatDate : null : request.request_type !== 'toil' ? unit : null}} - - - - {{request.to_date | formatDate : null : request.request_type !== 'toil' ? unit : null}} - - - - - {{request.to_date.slice(11, 16)}} - - {{vm.getLeaveStatusByValue(request.status_id)}} + - + {{request.to_date | formatDate : null : (request.request_type === 'toil' ? 'hours' : unit)}} + + + - + {{request.to_date.slice(11, 16)}} + diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/partials/staff-leave-report-requests-rows.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/partials/staff-leave-report-requests-rows.html index d45ffc17a79..7b6165c360e 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/partials/staff-leave-report-requests-rows.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/partials/staff-leave-report-requests-rows.html @@ -7,17 +7,8 @@ (expires {{request.toil_expiry_date | formatDate}}) - {{request.from_date | formatDate : null : request.request_type !== 'toil' ? unit : null}} - - - - {{request.to_date | formatDate : null : request.request_type !== 'toil' ? unit : null}} - - - - - {{request.to_date.slice(11, 16)}} - - {{report.leaveRequestStatuses[request.status_id].label}} From 2b4305306a63dc253092044cf5f06a2f802851e0 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Tue, 27 Mar 2018 10:06:00 +0100 Subject: [PATCH 093/203] PCHR-3494: Create a CRM service --- .../src/common/bundles/services.js | 1 + .../src/common/services/crm-ang.service.js | 29 +++++++++++++ .../test/services/crm-ang.service.spec.js | 43 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 org.civicrm.reqangular/src/common/services/crm-ang.service.js create mode 100644 org.civicrm.reqangular/test/services/crm-ang.service.spec.js diff --git a/org.civicrm.reqangular/src/common/bundles/services.js b/org.civicrm.reqangular/src/common/bundles/services.js index 97d9e1484c8..88c762c3e82 100644 --- a/org.civicrm.reqangular/src/common/bundles/services.js +++ b/org.civicrm.reqangular/src/common/bundles/services.js @@ -3,6 +3,7 @@ define([ 'common/services/before-hash-query-params.service', 'common/services/check-permissions', + 'common/services/crm-ang.service', 'common/services/detect-device.service', 'common/services/dom-event-trigger', 'common/services/file-mime-types', diff --git a/org.civicrm.reqangular/src/common/services/crm-ang.service.js b/org.civicrm.reqangular/src/common/services/crm-ang.service.js new file mode 100644 index 00000000000..ffe60898342 --- /dev/null +++ b/org.civicrm.reqangular/src/common/services/crm-ang.service.js @@ -0,0 +1,29 @@ +/* eslint-env amd */ + +(function (CRM) { + define([ + 'common/lodash', + 'common/modules/services' + ], function (_, services) { + 'use strict'; + + services.factory('crmAngService', function () { + return { + loadForm: loadForm + }; + }); + + /** + * Opens a CRM form with a provided url and options + * This is simply a wrapper to CRM.loadForm + * Reference: https://docs.civicrm.org/dev/en/latest/framework/ajax + * + * @param {String} url + * @param {Object} options + * @return {jQuery} + */ + function loadForm (url, options) { + return CRM.loadForm(url, options); + } + }); +}(CRM)); diff --git a/org.civicrm.reqangular/test/services/crm-ang.service.spec.js b/org.civicrm.reqangular/test/services/crm-ang.service.spec.js new file mode 100644 index 00000000000..a0bbd3aa6f4 --- /dev/null +++ b/org.civicrm.reqangular/test/services/crm-ang.service.spec.js @@ -0,0 +1,43 @@ +/* eslint-env amd, jasmine */ + +(function (CRM) { + define([ + 'common/angular', + 'common/angularMocks', + 'common/services/crm-ang.service' + ], function () { + 'use strict'; + + describe('crmAng', function () { + var crmAngService; + + beforeEach(module('common.services')); + beforeEach(inject(function (_crmAngService_) { + crmAngService = _crmAngService_; + })); + + describe('loadForm()', function () { + var result; + var url = '/some-url'; + var options = { optionKey: 'optionValue' }; + var originalResult = 'jQuery object'; + + beforeEach(function () { + CRM.loadForm = function () {}; + + spyOn(CRM, 'loadForm').and.returnValue(originalResult); + + result = crmAngService.loadForm(url, options); + }); + + it('calls CRM.loadForm with according parameters', function () { + expect(CRM.loadForm).toHaveBeenCalledWith(url, options); + }); + + it('returns the same as the original method', function () { + expect(result).toBe(originalResult); + }); + }); + }); + }); +})(CRM); From 82e8fad40844e45e4ce42c81bcb6297a40aebcc7 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Tue, 27 Mar 2018 10:06:31 +0100 Subject: [PATCH 094/203] PCHR-3494: Rename specs --- .../api/{contact_test.js => contact.spec.js} | 63 +++++++++---------- .../{job-role_test.js => job-role.spec.js} | 41 ++++++------ 2 files changed, 51 insertions(+), 53 deletions(-) rename org.civicrm.reqangular/test/services/api/{contact_test.js => contact.spec.js} (66%) rename org.civicrm.reqangular/test/services/api/{job-role_test.js => job-role.spec.js} (67%) diff --git a/org.civicrm.reqangular/test/services/api/contact_test.js b/org.civicrm.reqangular/test/services/api/contact.spec.js similarity index 66% rename from org.civicrm.reqangular/test/services/api/contact_test.js rename to org.civicrm.reqangular/test/services/api/contact.spec.js index ac75bdc08e3..7f9d1a2b062 100644 --- a/org.civicrm.reqangular/test/services/api/contact_test.js +++ b/org.civicrm.reqangular/test/services/api/contact.spec.js @@ -1,15 +1,15 @@ +/* eslint-env amd, jasmine */ + define([ + 'common/lodash', 'common/angularMocks', 'common/services/api/contact', 'common/mocks/services/api/contact-mock' -], function () { +], function (_) { 'use strict'; - describe("api.contact", function () { - var ContactAPI, - $rootScope, - ContactAPIMock, - $q; + describe('api.contact', function () { + var ContactAPI, $rootScope, ContactAPIMock, $q; beforeEach(module('common.apis', 'common.mocks')); @@ -20,18 +20,18 @@ define([ $q = _$q_; }])); - it("has expected interface", function () { - expect(Object.keys(ContactAPI)).toContain("all"); - expect(Object.keys(ContactAPI)).toContain("find"); - expect(Object.keys(ContactAPI)).toContain("leaveManagees"); + it('has expected interface', function () { + expect(Object.keys(ContactAPI)).toContain('all'); + expect(Object.keys(ContactAPI)).toContain('find'); + expect(Object.keys(ContactAPI)).toContain('leaveManagees'); }); - describe("all()", function () { - var contactApiPromise, - filters = {key: "filters"}, - pagination = {key: "pagination"}, - sort = "sort", - additionalParams = {key: "additionalParams"}; + describe('all()', function () { + var contactApiPromise; + var filters = { key: 'filters' }; + var pagination = { key: 'pagination' }; + var sort = 'sort'; + var additionalParams = { key: 'additionalParams' }; beforeEach(function () { spyOn(ContactAPI, 'getAll').and.returnValue($q.resolve(ContactAPIMock.mockedContacts())); @@ -42,21 +42,20 @@ define([ $rootScope.$apply(); }); - it("returns all the contact", function () { + it('returns all the contact', function () { contactApiPromise.then(function (result) { expect(result).toEqual(ContactAPIMock.mockedContacts()); }); }); - it("calls getAll method", function () { + it('calls getAll method', function () { expect(ContactAPI.getAll).toHaveBeenCalledWith('Contact', filters, pagination, sort, additionalParams); }); }); - describe("find()", function () { - var contactApiPromise, - contactId = '2', - contact; + describe('find()', function () { + var contactApiPromise, contact; + var contactId = '2'; beforeEach(function () { contact = ContactAPIMock.mockedContacts().list[0]; @@ -70,23 +69,23 @@ define([ $rootScope.$apply(); }); - it("returns a contact", function () { + it('returns a contact', function () { contactApiPromise.then(function (result) { expect(result).toEqual(contact); }); }); - it("calls sendGET method", function () { + it('calls sendGET method', function () { expect(ContactAPI.sendGET).toHaveBeenCalledWith('Contact', 'get', {id: '' + contactId}, false); }); }); - describe("leaveManagees()", function () { - var contactApiPromise, - managedBy = '101', - params = { - key: 'value' - }; + describe('leaveManagees()', function () { + var contactApiPromise; + var managedBy = '101'; + var params = { + key: 'value' + }; beforeEach(function () { spyOn(ContactAPI, 'sendGET').and.returnValue($q.resolve({ @@ -99,13 +98,13 @@ define([ $rootScope.$apply(); }); - it("returns the contacts", function () { + it('returns the contacts', function () { contactApiPromise.then(function (result) { expect(result).toEqual(ContactAPIMock.mockedContacts().list); }); }); - it("calls sendGET method", function () { + it('calls sendGET method', function () { expect(ContactAPI.sendGET).toHaveBeenCalledWith('Contact', 'getleavemanagees', _.assign(params, { managed_by: managedBy })); diff --git a/org.civicrm.reqangular/test/services/api/job-role_test.js b/org.civicrm.reqangular/test/services/api/job-role.spec.js similarity index 67% rename from org.civicrm.reqangular/test/services/api/job-role_test.js rename to org.civicrm.reqangular/test/services/api/job-role.spec.js index 19a56842676..0e639e3617f 100644 --- a/org.civicrm.reqangular/test/services/api/job-role_test.js +++ b/org.civicrm.reqangular/test/services/api/job-role.spec.js @@ -1,3 +1,5 @@ +/* eslint-env amd, jasmine */ + define([ 'common/angularMocks', 'common/services/api/job-role', @@ -5,11 +7,8 @@ define([ ], function () { 'use strict'; - describe("api.job-role", function () { - var JobRoleAPI, - $rootScope, - JobRoleAPIMock, - $q; + describe('api.job-role', function () { + var JobRoleAPI, $rootScope, JobRoleAPIMock, $q; beforeEach(module('common.apis', 'common.mocks')); @@ -20,17 +19,17 @@ define([ $q = _$q_; }])); - it("has expected interface", function () { - expect(Object.keys(JobRoleAPI)).toContain("all"); - expect(Object.keys(JobRoleAPI)).toContain("find"); + it('has expected interface', function () { + expect(Object.keys(JobRoleAPI)).toContain('all'); + expect(Object.keys(JobRoleAPI)).toContain('find'); }); - describe("all()", function () { - var jobRoleApiPromise, - filters = {key: "filters"}, - pagination = {key: "pagination"}, - sort = "sort", - additionalParams = {key: "additionalParams"}; + describe('all()', function () { + var jobRoleApiPromise; + var filters = { key: 'filters' }; + var pagination = { key: 'pagination' }; + var sort = 'sort'; + var additionalParams = { key: 'additionalParams' }; beforeEach(function () { spyOn(JobRoleAPI, 'getAll').and.returnValue($q.resolve(JobRoleAPIMock.mockedJobRoles)); @@ -41,20 +40,20 @@ define([ $rootScope.$apply(); }); - it("returns all the job roles", function () { + it('returns all the job roles', function () { jobRoleApiPromise.then(function (result) { expect(result).toEqual(JobRoleAPIMock.mockedJobRoles); }); }); - it("calls getAll method", function () { + it('calls getAll method', function () { expect(JobRoleAPI.getAll).toHaveBeenCalledWith('HrJobRoles', filters, pagination, sort, additionalParams); }); }); - describe("find()", function () { - var jobRoleApiPromise, - jobRoleID = '2'; + describe('find()', function () { + var jobRoleApiPromise; + var jobRoleID = '2'; beforeEach(function () { spyOn(JobRoleAPI, 'sendGET').and.returnValue($q.resolve({ @@ -67,13 +66,13 @@ define([ $rootScope.$apply(); }); - it("returns a job role", function () { + it('returns a job role', function () { jobRoleApiPromise.then(function (result) { expect(result).toEqual(JobRoleAPIMock.mockedJobRoles.list[0]); }); }); - it("calls sendGET method", function () { + it('calls sendGET method', function () { expect(JobRoleAPI.sendGET).toHaveBeenCalledWith('HRJobRole', 'get', {id: '' + jobRoleID}, false); }); }); From fa292cab4e7c311f954cd7ff5b5824e7f980e118 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Tue, 27 Mar 2018 10:07:11 +0100 Subject: [PATCH 095/203] PCHR-3494: Allow not to cache group options --- .../src/common/models/option-group.js | 46 ++++----- .../src/common/services/api/option-group.js | 17 ++-- .../test/models/option-group.spec.js | 42 +++++++- .../test/services/api/option-group.spec.js | 98 +++++++++++++++++++ 4 files changed, 168 insertions(+), 35 deletions(-) create mode 100644 org.civicrm.reqangular/test/services/api/option-group.spec.js diff --git a/org.civicrm.reqangular/src/common/models/option-group.js b/org.civicrm.reqangular/src/common/models/option-group.js index 83d98b8912d..0a503a14f7a 100644 --- a/org.civicrm.reqangular/src/common/models/option-group.js +++ b/org.civicrm.reqangular/src/common/models/option-group.js @@ -1,28 +1,30 @@ +/* eslint-env amd */ + define([ - 'common/modules/models', - 'common/models/model', - 'common/services/api/option-group' + 'common/modules/models', + 'common/models/model', + 'common/services/api/option-group' ], function (models) { - 'use strict'; - - models.factory('OptionGroup', [ - 'Model', 'api.optionGroup', - function (Model, optionGroupAPI) { + 'use strict'; - return Model.extend({ + models.factory('OptionGroup', [ + 'Model', 'api.optionGroup', + function (Model, optionGroupAPI) { + return Model.extend({ - /** - * Returns the values of a sigle or multiple option groups - * - * @param {string/array} names - * Bases on the type of the parameter, the method will return - * either an array of values (string) or an object (array) - * @return {Promise} - */ - valuesOf: function (names) { - return optionGroupAPI.valuesOf(names); - } - }); + /** + * Returns the values of a sigle or multiple option groups + * + * @param {String|Array} names + * Bases on the type of the parameter, the method will return + * either an array of values (string) or an object (array) + * @param {Boolean} cache optional parameter to cache the query or not + * @return {Promise} + */ + valuesOf: function (names, cache) { + return optionGroupAPI.valuesOf(names, cache); } - ]); + }); + } + ]); }); diff --git a/org.civicrm.reqangular/src/common/services/api/option-group.js b/org.civicrm.reqangular/src/common/services/api/option-group.js index ad95ed1f184..d24a372d476 100644 --- a/org.civicrm.reqangular/src/common/services/api/option-group.js +++ b/org.civicrm.reqangular/src/common/services/api/option-group.js @@ -52,16 +52,17 @@ define([ /** * Returns the values of the option groups with the given names * - * @param {string/array} groupNames + * @param {String|Array} groupNames * If the value is an array of names, the method will group * the values by option group names - * @param {object} params optional parameters for the query + * @param {Object} params optional parameters for the query + * @param {Boolean} cache optional parameter to cache the query or not * @return {Promise} * Resolves to an array with the values (if `groupNames` is a string) * or an object with keys as the group names and values as the * array of their option values (if `groupNames` is an array) */ - valuesOf: function (groupNames, params) { + valuesOf: function (groupNames, params, cache) { var multiple = _.isArray(groupNames); return this.sendGET('OptionValue', 'get', _.assign({ @@ -71,11 +72,11 @@ define([ 'option_group_id.name', 'option_group_id', 'id', 'name', 'label', 'value', 'weight', 'is_active', 'is_reserved' ] - }, params)) - .then(normalizeResponse) - .then(function (optionValues) { - return multiple ? valuesByGroup(optionValues) : optionValues; - }); + }, params), cache) + .then(normalizeResponse) + .then(function (optionValues) { + return multiple ? valuesByGroup(optionValues) : optionValues; + }); } }); }]); diff --git a/org.civicrm.reqangular/test/models/option-group.spec.js b/org.civicrm.reqangular/test/models/option-group.spec.js index 25ec5133891..d96201ab043 100644 --- a/org.civicrm.reqangular/test/models/option-group.spec.js +++ b/org.civicrm.reqangular/test/models/option-group.spec.js @@ -14,7 +14,7 @@ define([ module('common.models', 'common.mocks', function (_$provide_) { $provide = _$provide_; }); - // Override api.optionGroup with the mocked version + // Override api.optionGroup with the mocked version inject(['api.optionGroup.mock', function (_optionGroupAPIMock_) { $provide.value('api.optionGroup', _optionGroupAPIMock_); }]); @@ -35,12 +35,44 @@ define([ }); describe('valuesOf()', function () { - beforeEach(function () { - OptionGroup.valuesOf('hrjc_department'); + var optionGroupName = 'hrjc_department'; + + describe('when just a single option group name is passed', function () { + beforeEach(function () { + OptionGroup.valuesOf(optionGroupName); + }); + + it('calls the correct API method', function () { + expect(optionGroupAPI.valuesOf.calls.mostRecent().args[0]).toBe(optionGroupName); + }); + + it('caches requests by default', function () { + expect(optionGroupAPI.valuesOf.calls.mostRecent().args[1]).toBe(undefined); + }); }); - it('calls the correct API method', function () { - expect(optionGroupAPI.valuesOf).toHaveBeenCalled(); + describe('when several option group names are passed', function () { + var multipleOptionGroupNames = [optionGroupName, 'some_other_option']; + + beforeEach(function () { + OptionGroup.valuesOf(multipleOptionGroupNames); + }); + + it('passes the array of option group names to the API method', function () { + expect(optionGroupAPI.valuesOf.calls.mostRecent().args[0]).toBe(multipleOptionGroupNames); + }); + }); + + describe('when caching is disabled', function () { + var cache = false; + + beforeEach(function () { + OptionGroup.valuesOf(optionGroupName, cache); + }); + + it('does not cache requests', function () { + expect(optionGroupAPI.valuesOf.calls.mostRecent().args[1]).toBe(cache); + }); }); }); }); diff --git a/org.civicrm.reqangular/test/services/api/option-group.spec.js b/org.civicrm.reqangular/test/services/api/option-group.spec.js new file mode 100644 index 00000000000..6b097366fea --- /dev/null +++ b/org.civicrm.reqangular/test/services/api/option-group.spec.js @@ -0,0 +1,98 @@ +/* eslint-env amd, jasmine */ + +define([ + 'common/angularMocks', + 'common/models/option-group', + 'common/mocks/services/api/option-group-mock' +], function () { + 'use strict'; + + describe('api.option-group', function () { + var $q, methods, OptionGroupAPI; + + beforeEach(function () { + module('common.models', 'common.mocks'); + }); + + beforeEach(inject([ + 'api.optionGroup', + function (_optionGroupAPI_) { + OptionGroupAPI = _optionGroupAPI_; + } + ])); + + beforeEach(inject(function (_$q_) { + $q = _$q_; + methods = Object.keys(OptionGroupAPI); + })); + + it('has expected interface', function () { + expect(methods).toContain('valuesOf'); + }); + + describe('valuesOf()', function () { + var optionGroupName = 'hrjc_department'; + + beforeEach(function () { + spyOn(OptionGroupAPI, 'sendGET').and.returnValue($q.resolve()); + }); + + describe('when a single option name is passed without any additional parameters', function () { + beforeEach(function () { + OptionGroupAPI.valuesOf(optionGroupName); + }); + + it('calls sendGET with correct parameters', function () { + expect(OptionGroupAPI.sendGET).toHaveBeenCalledWith( + 'OptionValue', 'get', + { 'option_group_id.name': { IN: [ optionGroupName ] }, + is_active: '1', + return: [ 'option_group_id.name', 'option_group_id', 'id', 'name', + 'label', 'value', 'weight', 'is_active', 'is_reserved'] }, + undefined + ); + }); + }); + + describe('when multiple option names are passed', function () { + var anotherOptionGroupName = 'hrjc_level_type'; + + beforeEach(function () { + OptionGroupAPI.valuesOf([optionGroupName, anotherOptionGroupName]); + }); + + it('tells backend API to fetch multiple options', function () { + expect(OptionGroupAPI.sendGET.calls.mostRecent().args[2]['option_group_id.name']).toEqual( + { IN: [optionGroupName, anotherOptionGroupName] } + ); + }); + }); + + describe('when extra params are passed', function () { + var params = { paramKey: 'paramValue' }; + + beforeEach(function () { + OptionGroupAPI.valuesOf(optionGroupName, params); + }); + + it('passes extra parameters to sendGET', function () { + expect(OptionGroupAPI.sendGET.calls.mostRecent().args[2]).toEqual( + jasmine.objectContaining(params) + ); + }); + }); + + describe('when no caching is needed', function () { + var cache = false; + + beforeEach(function () { + OptionGroupAPI.valuesOf(optionGroupName, {}, cache); + }); + + it('tells sendGET to not cache the API call', function () { + expect(OptionGroupAPI.sendGET.calls.mostRecent().args[3]).toBe(cache); + }); + }); + }); + }); +}); From d8e9e8281a83dfcddff4c5aac3f256aaadafac2d Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Tue, 27 Mar 2018 10:07:46 +0100 Subject: [PATCH 096/203] PCHR-3494: Add a wrench that edits the option group --- .../request-modal-details-toil.controller.js | 22 ++++++++-- ...uest-modal-details-toil.controller.spec.js | 43 +++++++++++++++++-- .../leave-request-popup/details-tab/toil.html | 40 ++++++++++------- 3 files changed, 82 insertions(+), 23 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js index 021ca32d01c..36fd5d75a16 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js @@ -3,13 +3,16 @@ define([ 'common/lodash', 'common/moment', - 'leave-absences/shared/modules/controllers' + 'leave-absences/shared/modules/controllers', + 'common/services/crm-ang.service' ], function (_, moment, controllers) { controllers.controller('RequestModalDetailsToilController', RequestModalDetailsToilController); - RequestModalDetailsToilController.$inject = ['$log', '$q', '$rootScope', 'api.optionGroup', 'AbsenceType', 'detailsController']; + RequestModalDetailsToilController.$inject = ['$log', '$q', '$rootScope', + 'crmAngService', 'api.optionGroup', 'AbsenceType', 'detailsController']; - function RequestModalDetailsToilController ($log, $q, $rootScope, OptionGroup, AbsenceType, detailsController) { + function RequestModalDetailsToilController ($log, $q, $rootScope, + crmAngService, OptionGroup, AbsenceType, detailsController) { $log.debug('RequestModalDetailsToilController'); var initialRequestAttributes; @@ -28,6 +31,7 @@ define([ detailsController.initTimesExtended = initTimes; detailsController.initWatchersExtended = initWatchers; detailsController.onDateChangeExtended = onDateChangeHandler; + detailsController.openToilInDaysAccrualOptionsEditor = openToilInDaysAccrualOptionsEditor; detailsController.setDaysSelectionModeExtended = onDaysSelectionModeHandler; detailsController.updateExpiryDate = updateExpiryDate; @@ -348,7 +352,7 @@ define([ * @return {Promise} */ function loadToilAmounts () { - return OptionGroup.valuesOf('hrleaveandabsences_toil_amounts') + return OptionGroup.valuesOf('hrleaveandabsences_toil_amounts', {}, false) .then(function (amounts) { detailsController.toilAmounts = _.sortBy(amounts, 'value'); }); @@ -412,6 +416,16 @@ define([ } } + /** + * Opens the CRM modal that allows to edit TOIL in days amounts options + * and reloads these options in the Leave Request Modal + * if they are changed via the CRM modal + */ + function openToilInDaysAccrualOptionsEditor () { + crmAngService.loadForm('/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1') + .on('crmFormSuccess', loadToilAmounts); + } + /** * Calculates the expiry date if all conditions are met, otherwise it resolves * into an empty promise. diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js index a46f23d5cba..3f7320d3a1b 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js @@ -11,18 +11,20 @@ define([ 'leave-absences/mocks/helpers/helper', 'leave-absences/mocks/helpers/request-modal-helper', 'common/mocks/services/hr-settings-mock', + 'common/services/crm-ang.service', 'leave-absences/mocks/apis/absence-type-api-mock', 'leave-absences/mocks/apis/leave-request-api-mock', 'leave-absences/mocks/apis/option-group-api-mock', 'leave-absences/mocks/apis/public-holiday-api-mock', 'leave-absences/mocks/apis/work-pattern-api-mock', 'leave-absences/manager-leave/app' -], function (angular, _, moment, absencePeriodData, absenceTypeData, leaveRequestData, optionGroupMock, helper, requestModalHelper) { +], function (angular, _, moment, absencePeriodData, absenceTypeData, leaveRequestData, + optionGroupMock, helper, requestModalHelper) { 'use strict'; describe('RequestModalDetailsToilController', function () { - var $componentController, $provide, $q, $log, $rootScope, controller, leaveRequest, - AbsenceType, AbsenceTypeAPI, LeaveRequestInstance, TOILRequestInstance; + var $componentController, $provide, $q, $log, $rootScope, crmAngService, controller, + AbsenceType, AbsenceTypeAPI, leaveRequest, LeaveRequestInstance, TOILRequestInstance; var date2016 = '01/12/2016'; var date2016To = '02/12/2016'; // Must be greater than `date2016` @@ -47,12 +49,13 @@ define([ beforeEach(inject(function ( _$componentController_, _$q_, _$log_, _$rootScope_, _AbsenceType_, _AbsenceTypeAPI_, - _LeaveRequestInstance_, _TOILRequestInstance_) { + _crmAngService_, _LeaveRequestInstance_, _TOILRequestInstance_) { $componentController = _$componentController_; $log = _$log_; $q = _$q_; $rootScope = _$rootScope_; AbsenceType = _AbsenceType_; + crmAngService = _crmAngService_; AbsenceTypeAPI = _AbsenceTypeAPI_; LeaveRequestInstance = _LeaveRequestInstance_; TOILRequestInstance = _TOILRequestInstance_; @@ -61,6 +64,14 @@ define([ spyOn(AbsenceTypeAPI, 'calculateToilExpiryDate').and.callThrough(); spyOn(AbsenceType, 'canExpire').and.callThrough(); spyOn(AbsenceType, 'calculateToilExpiryDate').and.callThrough(); + + crmAngService.loadForm = function () { + return { + on: function (event, callback) { + callback(); + } + }; + }; })); describe('on initialize', function () { @@ -302,6 +313,30 @@ define([ expect(controller.uiOptions.toil_duration_in_hours).toBe(2); }); }); + + describe('when user opens toil accrual option group editor', function () { + beforeEach(function () { + // flushing TOIL accrual options + controller.toilAmounts = null; + + spyOn(crmAngService, 'loadForm').and.callThrough(); + controller.openToilInDaysAccrualOptionsEditor(); + }); + + it('calls the CRM.loadForm with according URL', function () { + expect(crmAngService.loadForm).toHaveBeenCalledWith('/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1'); + }); + + describe('when TOIL accruals are edited', function () { + beforeEach(function () { + $rootScope.$digest(); + }); + + it('reloads TOIL accrual values', function () { + expect(Object.keys(controller.toilAmounts).length).toBeGreaterThan(0); + }); + }); + }); }); describe('respond', function () { diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html index 7c74783345e..64910f6b201 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html @@ -39,24 +39,34 @@
-
-
- - +
+
+
+ + +
+
+ + + +
+
+
Date: Tue, 27 Mar 2018 10:35:57 +0100 Subject: [PATCH 097/203] PCHR-3494: Add dist files --- org.civicrm.reqangular/dist/reqangular.min.js | 8 ++++---- .../js/angular/dist/absence-tab.min.js | 6 +++--- .../js/angular/dist/admin-dashboard.min.js | 10 +++++----- .../js/angular/dist/manager-leave.min.js | 10 +++++----- .../js/angular/dist/my-leave.min.js | 8 ++++---- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/org.civicrm.reqangular/dist/reqangular.min.js b/org.civicrm.reqangular/dist/reqangular.min.js index 66611d6424e..29dbc56a43a 100644 --- a/org.civicrm.reqangular/dist/reqangular.min.js +++ b/org.civicrm.reqangular/dist/reqangular.min.js @@ -114,8 +114,8 @@ return e=os.day(e),e.setMonth(0,1),e},function(e,t){e.setFullYear(e.getFullYear( e.x=(e.x-l.x)*r[0],e.y=(l.y-e.y)*r[1]}:function(e){e.x=(e.x-d)/(p-d)*r[0],e.y=(1-(l.y?e.y/l.y:1))*r[1]}),s}var t=na.layout.hierarchy().sort(null).value(null),n=Ei,r=[1,1],i=!1;return e.separation=function(t){return arguments.length?(n=t,e):n},e.size=function(t){return arguments.length?(i=null==(r=t),e):i?null:r},e.nodeSize=function(t){return arguments.length?(i=null!=(r=t),e):i?r:null},Qr(e,t)},na.layout.treemap=function(){function e(e,t){for(var n,r,i=-1,o=e.length;++it?0:t),n.area=isNaN(r)||0>=r?0:r}function t(n){var o=n.children;if(o&&o.length){var a,s,l,u=f(n),c=[],d=o.slice(),h=1/0,m="slice"===p?u.dx:"dice"===p?u.dy:"slice-dice"===p?1&n.depth?u.dy:u.dx:Math.min(u.dx,u.dy);for(e(d,u.dx*u.dy/n.value),c.area=0;(l=d.length)>0;)c.push(a=d[l-1]),c.area+=a.area,"squarify"!==p||(s=r(c,m))<=h?(d.pop(),h=s):(c.area-=c.pop().area,i(c,m,u,!1),m=Math.min(u.dx,u.dy),c.length=c.area=0,h=1/0);c.length&&(i(c,m,u,!0),c.length=c.area=0),o.forEach(t)}}function n(t){var r=t.children;if(r&&r.length){var o,a=f(t),s=r.slice(),l=[];for(e(s,a.dx*a.dy/t.value),l.area=0;o=s.pop();)l.push(o),l.area+=o.area,null!=o.z&&(i(l,o.z?a.dx:a.dy,a,!s.length),l.length=l.area=0);r.forEach(n)}}function r(e,t){for(var n,r=e.area,i=0,o=1/0,a=-1,s=e.length;++an&&(o=n),n>i&&(i=n));return r*=r,t*=t,r?Math.max(t*i*h/r,r/(t*o*h)):1/0}function i(e,t,n,r){var i,o=-1,a=e.length,s=n.x,u=n.y,c=t?l(e.area/t):0;if(t==n.dx){for((r||c>n.dy)&&(c=n.dy);++on.dx)&&(c=n.dx);++on&&(t=1),1>n&&(e=0),function(){var n,r,i;do{n=2*Math.random()-1,r=2*Math.random()-1,i=n*n+r*r}while(!i||i>1);return e+t*n*Math.sqrt(-2*Math.log(i)/i)}},logNormal:function(){var e=na.random.normal.apply(na,arguments);return function(){return Math.exp(e())}},bates:function(e){var t=na.random.irwinHall(e);return function(){return t()/e}},irwinHall:function(e){return function(){for(var t=0,n=0;e>n;n++)t+=Math.random();return t}}},na.scale={};var ml={floor:y,ceil:y};na.scale.linear=function(){return Vi([0,1],[0,1],yr,!1)};var gl={s:1,g:1,p:1,r:1,e:1};na.scale.log=function(){return Ji(na.scale.linear().domain([0,1]),10,!0,[1,10])};var vl=na.format(".0e"),yl={floor:function(e){return-Math.ceil(-e)},ceil:function(e){return-Math.floor(-e)}};na.scale.pow=function(){return Qi(na.scale.linear(),1,[0,1])},na.scale.sqrt=function(){return na.scale.pow().exponent(.5)},na.scale.ordinal=function(){return eo([],{t:"range",a:[[]]})},na.scale.category10=function(){return na.scale.ordinal().range(bl)},na.scale.category20=function(){return na.scale.ordinal().range($l)},na.scale.category20b=function(){return na.scale.ordinal().range(wl)},na.scale.category20c=function(){return na.scale.ordinal().range(xl)};var bl=[2062260,16744206,2924588,14034728,9725885,9197131,14907330,8355711,12369186,1556175].map(be),$l=[2062260,11454440,16744206,16759672,2924588,10018698,14034728,16750742,9725885,12955861,9197131,12885140,14907330,16234194,8355711,13092807,12369186,14408589,1556175,10410725].map(be),wl=[3750777,5395619,7040719,10264286,6519097,9216594,11915115,13556636,9202993,12426809,15186514,15190932,8666169,11356490,14049643,15177372,8077683,10834324,13528509,14589654].map(be),xl=[3244733,7057110,10406625,13032431,15095053,16616764,16625259,16634018,3253076,7652470,10607003,13101504,7695281,10394312,12369372,14342891,6513507,9868950,12434877,14277081].map(be);na.scale.quantile=function(){return to([],[])},na.scale.quantize=function(){return no(0,1,[0,1])},na.scale.threshold=function(){return ro([.5],[0,1])},na.scale.identity=function(){return io([0,1])},na.svg={},na.svg.arc=function(){function e(){var e=Math.max(0,+n.apply(this,arguments)),u=Math.max(0,+r.apply(this,arguments)),c=a.apply(this,arguments)-Na,f=s.apply(this,arguments)-Na,d=Math.abs(f-c),p=c>f?0:1;if(e>u&&(h=u,u=e,e=h),d>=Oa)return t(u,p)+(e?t(e,1-p):"")+"Z";var h,m,g,v,y,b,$,w,x,C,k,E,S=0,_=0,M=[];if((v=(+l.apply(this,arguments)||0)/2)&&(g=o===Cl?Math.sqrt(e*e+u*u):+o.apply(this,arguments),p||(_*=-1),u&&(_=te(g/u*Math.sin(v))),e&&(S=te(g/e*Math.sin(v)))),u){y=u*Math.cos(c+_),b=u*Math.sin(c+_),$=u*Math.cos(f-_),w=u*Math.sin(f-_);var T=Math.abs(f-c-2*_)<=Da?0:1;if(_&&fo(y,b,$,w)===p^T){var D=(c+f)/2;y=u*Math.cos(D),b=u*Math.sin(D),$=w=null}}else y=b=0;if(e){x=e*Math.cos(f-S),C=e*Math.sin(f-S),k=e*Math.cos(c+S),E=e*Math.sin(c+S);var A=Math.abs(c-f+2*S)<=Da?0:1;if(S&&fo(x,C,k,E)===1-p^A){var O=(c+f)/2;x=e*Math.cos(O),C=e*Math.sin(O),k=E=null}}else x=C=0;if((h=Math.min(Math.abs(u-e)/2,+i.apply(this,arguments)))>.001){m=u>e^p?0:1;var N=null==k?[x,C]:null==$?[y,b]:Nn([y,b],[k,E],[$,w],[x,C]),R=y-N[0],I=b-N[1],P=$-N[0],F=w-N[1],j=1/Math.sin(Math.acos((R*P+I*F)/(Math.sqrt(R*R+I*I)*Math.sqrt(P*P+F*F)))/2),L=Math.sqrt(N[0]*N[0]+N[1]*N[1]);if(null!=$){var U=Math.min(h,(u-L)/(j+1)),H=po(null==k?[x,C]:[k,E],[y,b],u,U,p),q=po([$,w],[x,C],u,U,p);h===U?M.push("M",H[0],"A",U,",",U," 0 0,",m," ",H[1],"A",u,",",u," 0 ",1-p^fo(H[1][0],H[1][1],q[1][0],q[1][1]),",",p," ",q[1],"A",U,",",U," 0 0,",m," ",q[0]):M.push("M",H[0],"A",U,",",U," 0 1,",m," ",q[0])}else M.push("M",y,",",b);if(null!=k){var V=Math.min(h,(e-L)/(j-1)),z=po([y,b],[k,E],e,-V,p),B=po([x,C],null==$?[y,b]:[$,w],e,-V,p);h===V?M.push("L",B[0],"A",V,",",V," 0 0,",m," ",B[1],"A",e,",",e," 0 ",p^fo(B[1][0],B[1][1],z[1][0],z[1][1]),",",1-p," ",z[1],"A",V,",",V," 0 0,",m," ",z[0]):M.push("L",B[0],"A",V,",",V," 0 0,",m," ",z[0])}else M.push("L",x,",",C)}else M.push("M",y,",",b),null!=$&&M.push("A",u,",",u," 0 ",T,",",p," ",$,",",w),M.push("L",x,",",C),null!=k&&M.push("A",e,",",e," 0 ",A,",",1-p," ",k,",",E);return M.push("Z"),M.join("")}function t(e,t){return"M0,"+e+"A"+e+","+e+" 0 1,"+t+" 0,"+-e+"A"+e+","+e+" 0 1,"+t+" 0,"+e}var n=ao,r=so,i=oo,o=Cl,a=lo,s=uo,l=co;return e.innerRadius=function(t){return arguments.length?(n=Se(t),e):n},e.outerRadius=function(t){return arguments.length?(r=Se(t),e):r},e.cornerRadius=function(t){return arguments.length?(i=Se(t),e):i},e.padRadius=function(t){return arguments.length?(o=t==Cl?Cl:Se(t),e):o},e.startAngle=function(t){return arguments.length?(a=Se(t),e):a},e.endAngle=function(t){return arguments.length?(s=Se(t),e):s},e.padAngle=function(t){return arguments.length?(l=Se(t),e):l},e.centroid=function(){var e=(+n.apply(this,arguments)+ +r.apply(this,arguments))/2,t=(+a.apply(this,arguments)+ +s.apply(this,arguments))/2-Na;return[Math.cos(t)*e,Math.sin(t)*e]},e};var Cl="auto";na.svg.line=function(){return ho(y)};var kl=na.map({linear:mo,"linear-closed":go,step:vo,"step-before":yo,"step-after":bo,basis:Eo,"basis-open":So,"basis-closed":_o,bundle:Mo,cardinal:xo,"cardinal-open":$o,"cardinal-closed":wo,monotone:Ro});kl.forEach(function(e,t){t.key=e,t.closed=/-closed$/.test(e)});var El=[0,2/3,1/3,0],Sl=[0,1/3,2/3,0],_l=[0,1/6,2/3,1/6];na.svg.line.radial=function(){var e=ho(Io);return e.radius=e.x,delete e.x,e.angle=e.y,delete e.y,e},yo.reverse=bo,bo.reverse=yo,na.svg.area=function(){return Po(y)},na.svg.area.radial=function(){var e=Po(Io);return e.radius=e.x,delete e.x,e.innerRadius=e.x0,delete e.x0,e.outerRadius=e.x1,delete e.x1,e.angle=e.y,delete e.y,e.startAngle=e.y0,delete e.y0,e.endAngle=e.y1,delete e.y1,e},na.svg.chord=function(){function e(e,s){var l=t(this,o,e,s),u=t(this,a,e,s);return"M"+l.p0+r(l.r,l.p1,l.a1-l.a0)+(n(l,u)?i(l.r,l.p1,l.r,l.p0):i(l.r,l.p1,u.r,u.p0)+r(u.r,u.p1,u.a1-u.a0)+i(u.r,u.p1,l.r,l.p0))+"Z"}function t(e,t,n,r){var i=t.call(e,n,r),o=s.call(e,i,r),a=l.call(e,i,r)-Na,c=u.call(e,i,r)-Na;return{r:o,a0:a,a1:c,p0:[o*Math.cos(a),o*Math.sin(a)],p1:[o*Math.cos(c),o*Math.sin(c)]}}function n(e,t){return e.a0==t.a0&&e.a1==t.a1}function r(e,t,n){return"A"+e+","+e+" 0 "+ +(n>Da)+",1 "+t}function i(e,t,n,r){return"Q 0,0 "+r}var o=yn,a=bn,s=Fo,l=lo,u=uo;return e.radius=function(t){return arguments.length?(s=Se(t),e):s},e.source=function(t){return arguments.length?(o=Se(t),e):o},e.target=function(t){return arguments.length?(a=Se(t),e):a},e.startAngle=function(t){return arguments.length?(l=Se(t),e):l},e.endAngle=function(t){return arguments.length?(u=Se(t),e):u},e},na.svg.diagonal=function(){function e(e,i){var o=t.call(this,e,i),a=n.call(this,e,i),s=(o.y+a.y)/2,l=[o,{x:o.x,y:s},{x:a.x,y:s},a];return l=l.map(r),"M"+l[0]+"C"+l[1]+" "+l[2]+" "+l[3]}var t=yn,n=bn,r=jo;return e.source=function(n){return arguments.length?(t=Se(n),e):t},e.target=function(t){return arguments.length?(n=Se(t),e):n},e.projection=function(t){return arguments.length?(r=t,e):r},e},na.svg.diagonal.radial=function(){var e=na.svg.diagonal(),t=jo,n=e.projection;return e.projection=function(e){return arguments.length?n(Lo(t=e)):t},e},na.svg.symbol=function(){function e(e,r){return(Ml.get(t.call(this,e,r))||qo)(n.call(this,e,r))}var t=Ho,n=Uo;return e.type=function(n){return arguments.length?(t=Se(n),e):t},e.size=function(t){return arguments.length?(n=Se(t),e):n},e};var Ml=na.map({circle:qo,cross:function(e){var t=Math.sqrt(e/5)/2;return"M"+-3*t+","+-t+"H"+-t+"V"+-3*t+"H"+t+"V"+-t+"H"+3*t+"V"+t+"H"+t+"V"+3*t+"H"+-t+"V"+t+"H"+-3*t+"Z"},diamond:function(e){var t=Math.sqrt(e/(2*Dl)),n=t*Dl;return"M0,"+-t+"L"+n+",0 0,"+t+" "+-n+",0Z"},square:function(e){var t=Math.sqrt(e)/2;return"M"+-t+","+-t+"L"+t+","+-t+" "+t+","+t+" "+-t+","+t+"Z"},"triangle-down":function(e){var t=Math.sqrt(e/Tl),n=t*Tl/2;return"M0,"+n+"L"+t+","+-n+" "+-t+","+-n+"Z"},"triangle-up":function(e){var t=Math.sqrt(e/Tl),n=t*Tl/2;return"M0,"+-n+"L"+t+","+n+" "+-t+","+n+"Z"}});na.svg.symbolTypes=Ml.keys();var Tl=Math.sqrt(3),Dl=Math.tan(30*Ra);wa.transition=function(e){for(var t,n,r=Al||++Il,i=Wo(e),o=[],a=Ol||{time:Date.now(),ease:Er,delay:0,duration:250},s=-1,l=this.length;++so;o++){i.push(t=[]);for(var n=this[o],s=0,l=n.length;l>s;s++)(r=n[s])&&e.call(r,r.__data__,s,o)&&t.push(r)}return zo(i,this.namespace,this.id)},Rl.tween=function(e,t){var n=this.id,r=this.namespace;return arguments.length<2?this.node()[r][n].tween.get(e):V(this,null==t?function(t){t[r][n].tween.remove(e)}:function(i){i[r][n].tween.set(e,t)})},Rl.attr=function(e,t){function n(){this.removeAttribute(s)}function r(){this.removeAttributeNS(s.space,s.local)}function i(e){return null==e?n:(e+="",function(){var t,n=this.getAttribute(s);return n!==e&&(t=a(n,e),function(e){this.setAttribute(s,t(e))})})}function o(e){return null==e?r:(e+="",function(){var t,n=this.getAttributeNS(s.space,s.local);return n!==e&&(t=a(n,e),function(e){this.setAttributeNS(s.space,s.local,t(e))})})}if(arguments.length<2){for(t in e)this.attr(t,e[t]);return this}var a="transform"==e?Hr:yr,s=na.ns.qualify(e);return Bo(this,"attr."+e,t,s.local?o:i)},Rl.attrTween=function(e,t){function n(e,n){var r=t.call(this,e,n,this.getAttribute(i));return r&&function(e){this.setAttribute(i,r(e))}}function r(e,n){var r=t.call(this,e,n,this.getAttributeNS(i.space,i.local));return r&&function(e){this.setAttributeNS(i.space,i.local,r(e))}}var i=na.ns.qualify(e);return this.tween("attr."+e,i.local?r:n)},Rl.style=function(e,n,r){function i(){this.style.removeProperty(e)}function o(n){return null==n?i:(n+="",function(){var i,o=t(this).getComputedStyle(this,null).getPropertyValue(e);return o!==n&&(i=yr(o,n),function(t){this.style.setProperty(e,i(t),r)})})}var a=arguments.length;if(3>a){if("string"!=typeof e){2>a&&(n="");for(r in e)this.style(r,e[r],n);return this}r=""}return Bo(this,"style."+e,n,o)},Rl.styleTween=function(e,n,r){function i(i,o){var a=n.call(this,i,o,t(this).getComputedStyle(this,null).getPropertyValue(e));return a&&function(t){this.style.setProperty(e,a(t),r)}}return arguments.length<3&&(r=""),this.tween("style."+e,i)},Rl.text=function(e){return Bo(this,"text",e,Yo)},Rl.remove=function(){var e=this.namespace;return this.each("end.transition",function(){var t;this[e].count<2&&(t=this.parentNode)&&t.removeChild(this)})},Rl.ease=function(e){var t=this.id,n=this.namespace;return arguments.length<1?this.node()[n][t].ease:("function"!=typeof e&&(e=na.ease.apply(na,arguments)),V(this,function(r){r[n][t].ease=e}))},Rl.delay=function(e){var t=this.id,n=this.namespace;return arguments.length<1?this.node()[n][t].delay:V(this,"function"==typeof e?function(r,i,o){r[n][t].delay=+e.call(r,r.__data__,i,o)}:(e=+e,function(r){r[n][t].delay=e}))},Rl.duration=function(e){var t=this.id,n=this.namespace;return arguments.length<1?this.node()[n][t].duration:V(this,"function"==typeof e?function(r,i,o){r[n][t].duration=Math.max(1,e.call(r,r.__data__,i,o))}:(e=Math.max(1,e),function(r){r[n][t].duration=e}))},Rl.each=function(e,t){var n=this.id,r=this.namespace;if(arguments.length<2){var i=Ol,o=Al;try{Al=n,V(this,function(t,i,o){Ol=t[r][n],e.call(t,t.__data__,i,o)})}finally{Ol=i,Al=o}}else V(this,function(i){var o=i[r][n];(o.event||(o.event=na.dispatch("start","end","interrupt"))).on(e,t)});return this},Rl.transition=function(){for(var e,t,n,r,i=this.id,o=++Il,a=this.namespace,s=[],l=0,u=this.length;u>l;l++){s.push(e=[]);for(var t=this[l],c=0,f=t.length;f>c;c++)(n=t[c])&&(r=n[a][i],Go(n,c,a,o,{time:r.time,ease:r.ease,delay:r.delay+r.duration,duration:r.duration})),e.push(n)}return zo(s,a,o)},na.svg.axis=function(){function e(e){e.each(function(){var e,u=na.select(this),c=this.__chart__||n,f=this.__chart__=n.copy(),d=null==l?f.ticks?f.ticks.apply(f,s):f.domain():l,p=null==t?f.tickFormat?f.tickFormat.apply(f,s):y:t,h=u.selectAll(".tick").data(d,f),m=h.enter().insert("g",".domain").attr("class","tick").style("opacity",Ma),g=na.transition(h.exit()).style("opacity",Ma).remove(),v=na.transition(h.order()).style("opacity",1),b=Math.max(i,0)+a,$=ji(f),w=u.selectAll(".domain").data([0]),x=(w.enter().append("path").attr("class","domain"),na.transition(w));m.append("line"),m.append("text");var C,k,E,S,_=m.select("line"),M=v.select("line"),T=h.select("text").text(p),D=m.select("text"),A=v.select("text"),O="top"===r||"left"===r?-1:1;if("bottom"===r||"top"===r?(e=Ko,C="x",E="y",k="x2",S="y2",T.attr("dy",0>O?"0em":".71em").style("text-anchor","middle"),x.attr("d","M"+$[0]+","+O*o+"V0H"+$[1]+"V"+O*o)):(e=Zo,C="y",E="x",k="y2",S="x2",T.attr("dy",".32em").style("text-anchor",0>O?"end":"start"),x.attr("d","M"+O*o+","+$[0]+"H0V"+$[1]+"H"+O*o)),_.attr(S,O*i),D.attr(E,O*b),M.attr(k,0).attr(S,O*i),A.attr(C,0).attr(E,O*b),f.rangeBand){var N=f,R=N.rangeBand()/2;c=f=function(e){return N(e)+R}}else c.rangeBand?c=f:g.call(e,f,c);m.call(e,c,f),v.call(e,f,f)})}var t,n=na.scale.linear(),r=Pl,i=6,o=6,a=3,s=[10],l=null;return e.scale=function(t){return arguments.length?(n=t,e):n},e.orient=function(t){return arguments.length?(r=t in Fl?t+"":Pl,e):r},e.ticks=function(){return arguments.length?(s=arguments,e):s},e.tickValues=function(t){return arguments.length?(l=t,e):l},e.tickFormat=function(n){return arguments.length?(t=n,e):t},e.tickSize=function(t){var n=arguments.length;return n?(i=+t,o=+arguments[n-1],e):i},e.innerTickSize=function(t){return arguments.length?(i=+t,e):i},e.outerTickSize=function(t){return arguments.length?(o=+t,e):o},e.tickPadding=function(t){return arguments.length?(a=+t,e):a},e.tickSubdivide=function(){return arguments.length&&e},e};var Pl="bottom",Fl={top:1,right:1,bottom:1,left:1};na.svg.brush=function(){function e(t){t.each(function(){var t=na.select(this).style("pointer-events","all").style("-webkit-tap-highlight-color","rgba(0,0,0,0)").on("mousedown.brush",o).on("touchstart.brush",o),a=t.selectAll(".background").data([0]);a.enter().append("rect").attr("class","background").style("visibility","hidden").style("cursor","crosshair"),t.selectAll(".extent").data([0]).enter().append("rect").attr("class","extent").style("cursor","move");var s=t.selectAll(".resize").data(m,y);s.exit().remove(),s.enter().append("g").attr("class",function(e){return"resize "+e}).style("cursor",function(e){return jl[e]}).append("rect").attr("x",function(e){return/[ew]$/.test(e)?-3:null}).attr("y",function(e){return/^[ns]/.test(e)?-3:null}).attr("width",6).attr("height",6).style("visibility","hidden"),s.style("display",e.empty()?"none":null);var l,f=na.transition(t),d=na.transition(a);u&&(l=ji(u),d.attr("x",l[0]).attr("width",l[1]-l[0]),r(f)),c&&(l=ji(c),d.attr("y",l[0]).attr("height",l[1]-l[0]),i(f)),n(f)})}function n(e){e.selectAll(".resize").attr("transform",function(e){return"translate("+f[+/e$/.test(e)]+","+d[+/^s/.test(e)]+")"})}function r(e){e.select(".extent").attr("x",f[0]),e.selectAll(".extent,.n>rect,.s>rect").attr("width",f[1]-f[0])}function i(e){e.select(".extent").attr("y",d[0]),e.selectAll(".extent,.e>rect,.w>rect").attr("height",d[1]-d[0])}function o(){function o(){32==na.event.keyCode&&(T||(b=null,A[0]-=f[1],A[1]-=d[1],T=2),k())}function m(){32==na.event.keyCode&&2==T&&(A[0]+=f[1],A[1]+=d[1],T=0,k())}function g(){var e=na.mouse(w),t=!1;$&&(e[0]+=$[0],e[1]+=$[1]),T||(na.event.altKey?(b||(b=[(f[0]+f[1])/2,(d[0]+d[1])/2]),A[0]=f[+(e[0]c?(i=r,r=c):i=c),m[0]!=r||m[1]!=i?(n?s=null:a=null,m[0]=r,m[1]=i,!0):void 0}function y(){g(),E.style("pointer-events","all").selectAll(".resize").style("display",e.empty()?"none":null),na.select("body").style("cursor",null),O.on("mousemove.brush",null).on("mouseup.brush",null).on("touchmove.brush",null).on("touchend.brush",null).on("keydown.brush",null).on("keyup.brush",null),D(),C({type:"brushend"})}var b,$,w=this,x=na.select(na.event.target),C=l.of(w,arguments),E=na.select(w),S=x.datum(),_=!/^(n|s)$/.test(S)&&u,M=!/^(e|w)$/.test(S)&&c,T=x.classed("extent"),D=K(w),A=na.mouse(w),O=na.select(t(w)).on("keydown.brush",o).on("keyup.brush",m);if(na.event.changedTouches?O.on("touchmove.brush",g).on("touchend.brush",y):O.on("mousemove.brush",g).on("mouseup.brush",y),E.interrupt().selectAll("*").interrupt(),T)A[0]=f[0]-A[0],A[1]=d[0]-A[1];else if(S){var N=+/w$/.test(S),R=+/^n/.test(S);$=[f[1-N]-A[0],d[1-R]-A[1]],A[0]=f[N],A[1]=d[R]}else na.event.altKey&&(b=A.slice());E.style("pointer-events","none").selectAll(".resize").style("display",null),na.select("body").style("cursor",x.style("cursor")),C({type:"brushstart"}),g()}var a,s,l=S(e,"brushstart","brush","brushend"),u=null,c=null,f=[0,0],d=[0,0],p=!0,h=!0,m=Ll[0];return e.event=function(e){e.each(function(){var e=l.of(this,arguments),t={x:f,y:d,i:a,j:s},n=this.__chart__||t;this.__chart__=t,Al?na.select(this).transition().each("start.brush",function(){a=n.i,s=n.j,f=n.x,d=n.y,e({type:"brushstart"})}).tween("brush:brush",function(){var n=br(f,t.x),r=br(d,t.y);return a=s=null,function(i){f=t.x=n(i),d=t.y=r(i),e({type:"brush",mode:"resize"})}}).each("end.brush",function(){a=t.i,s=t.j,e({type:"brush",mode:"resize"}),e({type:"brushend"})}):(e({type:"brushstart"}),e({type:"brush",mode:"resize"}),e({type:"brushend"}))})},e.x=function(t){return arguments.length?(u=t,m=Ll[!u<<1|!c],e):u},e.y=function(t){return arguments.length?(c=t,m=Ll[!u<<1|!c],e):c},e.clamp=function(t){return arguments.length?(u&&c?(p=!!t[0],h=!!t[1]):u?p=!!t:c&&(h=!!t),e):u&&c?[p,h]:u?p:c?h:null},e.extent=function(t){var n,r,i,o,l;return arguments.length?(u&&(n=t[0],r=t[1],c&&(n=n[0],r=r[0]),a=[n,r],u.invert&&(n=u(n),r=u(r)),n>r&&(l=n,n=r,r=l),(n!=f[0]||r!=f[1])&&(f=[n,r])),c&&(i=t[0],o=t[1],u&&(i=i[1],o=o[1]),s=[i,o],c.invert&&(i=c(i),o=c(o)),i>o&&(l=i,i=o,o=l),(i!=d[0]||o!=d[1])&&(d=[i,o])),e):(u&&(a?(n=a[0],r=a[1]):(n=f[0],r=f[1],u.invert&&(n=u.invert(n),r=u.invert(r)),n>r&&(l=n,n=r,r=l))),c&&(s?(i=s[0],o=s[1]):(i=d[0],o=d[1],c.invert&&(i=c.invert(i),o=c.invert(o)),i>o&&(l=i,i=o,o=l))),u&&c?[[n,i],[r,o]]:u?[n,r]:c&&[i,o])},e.clear=function(){return e.empty()||(f=[0,0],d=[0,0],a=s=null),e},e.empty=function(){return!!u&&f[0]==f[1]||!!c&&d[0]==d[1]},na.rebind(e,l,"on")};var jl={n:"ns-resize",e:"ew-resize",s:"ns-resize",w:"ew-resize",nw:"nwse-resize",ne:"nesw-resize",se:"nwse-resize",sw:"nesw-resize"},Ll=[["n","e","s","w","nw","ne","se","sw"],["e","w"],["n","s"],[]],Ul=os.format=fs.timeFormat,Hl=Ul.utc,ql=Hl("%Y-%m-%dT%H:%M:%S.%LZ");Ul.iso=Date.prototype.toISOString&&+new Date("2000-01-01T00:00:00.000Z")?Jo:ql,Jo.parse=function(e){var t=new Date(e);return isNaN(t)?null:t},Jo.toString=ql.toString,os.second=Le(function(e){return new as(1e3*Math.floor(e/1e3))},function(e,t){e.setTime(e.getTime()+1e3*Math.floor(t))},function(e){return e.getSeconds()}),os.seconds=os.second.range,os.seconds.utc=os.second.utc.range,os.minute=Le(function(e){return new as(6e4*Math.floor(e/6e4))},function(e,t){e.setTime(e.getTime()+6e4*Math.floor(t))},function(e){return e.getMinutes()}),os.minutes=os.minute.range,os.minutes.utc=os.minute.utc.range,os.hour=Le(function(e){var t=e.getTimezoneOffset()/60;return new as(36e5*(Math.floor(e/36e5-t)+t))},function(e,t){e.setTime(e.getTime()+36e5*Math.floor(t))},function(e){return e.getHours()}),os.hours=os.hour.range,os.hours.utc=os.hour.utc.range,os.month=Le(function(e){return e=os.day(e),e.setDate(1),e},function(e,t){e.setMonth(e.getMonth()+t)},function(e){return e.getMonth()}),os.months=os.month.range,os.months.utc=os.month.utc.range;var Vl=[1e3,5e3,15e3,3e4,6e4,3e5,9e5,18e5,36e5,108e5,216e5,432e5,864e5,1728e5,6048e5,2592e6,7776e6,31536e6],zl=[[os.second,1],[os.second,5],[os.second,15],[os.second,30],[os.minute,1],[os.minute,5],[os.minute,15],[os.minute,30],[os.hour,1],[os.hour,3],[os.hour,6],[os.hour,12],[os.day,1],[os.day,2],[os.week,1],[os.month,1],[os.month,3],[os.year,1]],Bl=Ul.multi([[".%L",function(e){return e.getMilliseconds()}],[":%S",function(e){return e.getSeconds()}],["%I:%M",function(e){return e.getMinutes()}],["%I %p",function(e){return e.getHours()}],["%a %d",function(e){return e.getDay()&&1!=e.getDate()}],["%b %d",function(e){return 1!=e.getDate()}],["%B",function(e){return e.getMonth()}],["%Y",Mt]]),Yl={range:function(e,t,n){return na.range(Math.ceil(e/n)*n,+t,n).map(Xo)},floor:y,ceil:y};zl.year=os.year,os.scale=function(){return Qo(na.scale.linear(),zl,Bl)};var Wl=zl.map(function(e){return[e[0].utc,e[1]]}),Gl=Hl.multi([[".%L",function(e){return e.getUTCMilliseconds()}],[":%S",function(e){return e.getUTCSeconds()}],["%I:%M",function(e){return e.getUTCMinutes()}],["%I %p",function(e){return e.getUTCHours()}],["%a %d",function(e){return e.getUTCDay()&&1!=e.getUTCDate()}],["%b %d",function(e){return 1!=e.getUTCDate()}],["%B",function(e){return e.getUTCMonth()}],["%Y",Mt]]);Wl.year=os.year.utc,os.scale.utc=function(){return Qo(na.scale.linear(),Wl,Gl)},na.text=_e(function(e){return e.responseText}),na.json=function(e,t){return Me(e,"application/json",ea,t)},na.html=function(e,t){return Me(e,"text/html",ta,t)},na.xml=_e(function(e){return e.responseXML}),"function"==typeof define&&define.amd?define("common/d3",na):"object"==typeof module&&module.exports&&(module.exports=na),this.d3=na}(),function(){function e(e,t){if(e!==t){var n=null===e,r=e===$,i=e===e,o=null===t,a=t===$,s=t===t;if(e>t&&!o||!i||n&&!a&&s||r&&s)return 1;if(e=e&&9<=e&&13>=e||32==e||160==e||5760==e||6158==e||8192<=e&&(8202>=e||8232==e||8233==e||8239==e||8287==e||12288==e||65279==e)}function m(e,t){for(var n=-1,r=e.length,i=-1,o=[];++n=I&&gi&&ci?new Ue(t):null,u=t.length;l&&(a=He,s=!1,t=l);e:for(;++oa(t,l,0)&&i.push(l);return i}function st(e,t){var n=!0;return Ri(e,function(e,r,i){return n=!!t(e,r,i)}),n}function lt(e,t,n,r){var i=r,o=i;return Ri(e,function(e,a,s){a=+t(e,a,s),(n(a,i)||a===r&&a===o)&&(i=a,o=e)}),o}function ut(e,t){var n=[];return Ri(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}function ct(e,t,n,r){var i;return n(e,function(e,n,o){return t(e,n,o)?(i=r?n:e,!1):void 0}),i}function ft(e,t,n,r){r||(r=[]);for(var i=-1,o=e.length;++it&&(t=-t>i?0:i+t),n=n===$||n>i?i:+n||0,0>n&&(n+=i),i=t>n?0:n-t>>>0,t>>>=0,n=Ur(i);++r=u)break e;o=r[o],i*="asc"===o||!0===o?1:-1;break e}i=t.b-n.b}return i})}function Ot(e,t){var n=0;return Ri(e,function(e,r,i){n+=+t(e,r,i)||0}),n}function Nt(e,t){var r=-1,i=xn(),o=e.length,a=i===n,s=a&&o>=I,l=s&&gi&&ci?new Ue(void 0):null,u=[];l?(i=He,a=!1):(s=!1,l=t?[]:u);e:for(;++ri(l,f,0)&&((t||s)&&l.push(f),u.push(c))}return u}function Rt(e,t){for(var n=-1,r=t.length,i=Ur(r);++n>>1,a=e[o];(n?a<=t:ai?$:o,i=1);++r=I)return t.plant(r).value();for(var i=0,e=n?o[i].apply(this,e):r;++iarguments.length;return"function"==typeof r&&o===$&&Mo(n)?e(n,r,i,a):_t(n,$n(r,o,4),i,a,t)}}function fn(e,t,n,r,i,o,a,s,l,u){function c(){for(var b=arguments.length,w=b,k=Ur(b);w--;)k[w]=arguments[w];if(r&&(k=Ht(k,r,i)),o&&(k=qt(k,o,a)),h||v){var w=c.placeholder,E=m(k,w),b=b-E.length;if(bt?0:t)):[]}function zn(e,t,n){var r=e?e.length:0;return r?((n?An(e,t,n):null==t)&&(t=1),t=r-(+t||0),Mt(e,0,0>t?0:t)):[]}function Bn(e){return e?e[0]:$}function Yn(e,t,r){var i=e?e.length:0;if(!i)return-1;if("number"==typeof r)r=0>r?wi(i+r,0):r;else if(r)return r=Ft(e,t),rn?wi(i+n,0):n||0,"string"==typeof e||!Mo(e)&&wr(e)?n<=i&&-1t?0:+t||0,r);++n=e&&(t=$),n}}function lr(e,t,n){function r(t,n){n&&ai(n),l=d=p=$,t&&(h=ho(),u=e.apply(f,s),d||l||(s=f=$))}function i(){var e=t-(ho()-c);0>=e||e>t?r(p,l):d=fi(i,e)}function o(){r(g,d)}function a(){if(s=arguments,c=ho(),f=this,p=g&&(d||!v),!1===m)var n=v&&!d;else{l||v||(h=c);var r=m-(c-h),a=0>=r||r>m;a?(l&&(l=ai(l)),h=c,u=e.apply(f,s)):l||(l=fi(o,r))}return a&&d?d=ai(d):d||t===m||(d=fi(i,t)),n&&(a=!0,u=e.apply(f,s)),!a||d||l||(s=f=$),u}var s,l,u,c,f,d,p,h=0,m=!1,g=!0;if("function"!=typeof e)throw new Kr(j);if(t=0>t?0:+t||0,!0===n)var v=!0,g=!1;else gr(n)&&(v=!!n.leading,m="maxWait"in n&&wi(+n.maxWait||0,t),g="trailing"in n?!!n.trailing:g);return a.cancel=function(){d&&ai(d),l&&ai(l),h=0,l=d=p=$},a}function ur(e,t){function n(){var r=arguments,i=t?t.apply(this,r):r[0],o=n.cache;return o.has(i)?o.get(i):(r=e.apply(this,r),n.cache=o.set(i,r),r)}if("function"!=typeof e||t&&"function"!=typeof t)throw new Kr(j);return n.cache=new ur.Cache,n}function cr(e,t){if("function"!=typeof e)throw new Kr(j);return t=wi(t===$?e.length-1:+t||0,0),function(){for(var n=arguments,r=-1,i=wi(n.length-t,0),o=Ur(i);++rt}function dr(e){return p(e)&&Tn(e)&&ei.call(e,"callee")&&!ui.call(e,"callee")}function pr(e,t,n,r){return r=(n="function"==typeof n?Lt(n,r,3):$)?n(e,t):$,r===$?vt(e,t,n):!!r}function hr(e){return p(e)&&"string"==typeof e.message&&ni.call(e)==z}function mr(e){return gr(e)&&ni.call(e)==B}function gr(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function vr(e){return null!=e&&(mr(e)?ii.test(Xr.call(e)):p(e)&&Se.test(e))}function yr(e){return"number"==typeof e||p(e)&&ni.call(e)==Y}function br(e){var t;if(!p(e)||ni.call(e)!=W||dr(e)||!(ei.call(e,"constructor")||"function"!=typeof(t=e.constructor)||t instanceof t))return!1;var n;return dt(e,function(e,t){n=t}),n===$||ei.call(e,n)}function $r(e){return gr(e)&&ni.call(e)==G}function wr(e){return"string"==typeof e||p(e)&&ni.call(e)==K}function xr(e){return p(e)&&Rn(e.length)&&!!Ne[ni.call(e)]}function Cr(e,t){return e(t=+t)||!e||!bi(t))return n;do{t%2&&(n+=e),t=vi(t/2),e+=e}while(t);return n}function Or(e,t,n){var r=e;return(e=i(e))?(n?An(r,t,n):null==t)?e.slice(g(e),v(e)+1):(t+="",e.slice(o(e,t),a(e,t)+1)):e}function Nr(e,t,n){return n&&An(e,t,n)&&(t=$),e=i(e),e.match(t||Ae)||[]}function Rr(e,t,n){return n&&An(e,t,n)&&(t=$),p(e)?Pr(e):rt(e,t)}function Ir(e){return e}function Pr(e){return $t(it(e,!0))}function Fr(e,t,n){if(null==n){var r=gr(t),i=r?Lo(t):$;((i=i&&i.length?mt(t,i):$)?i.length:r)||(i=!1,n=t,t=e,e=this)}i||(i=mt(t,Lo(t)));var o=!0,r=-1,a=mr(e),s=i.length;!1===n?o=!1:gr(n)&&"chain"in n&&(o=n.chain);for(;++r=N)return n}else e=0;return ji(n,r)}}(),qi=cr(function(e,t){return p(e)&&Tn(e)?at(e,ft(t,!1,!0)):[]}),Vi=en(),zi=en(!0),Bi=cr(function(e){for(var t=e.length,r=t,i=Ur(c),o=xn(),a=o===n,s=[];r--;){var l=e[r]=Tn(l=e[r])?l:[];i[r]=a&&120<=l.length&&gi&&ci?new Ue(r&&l):null}var a=e[0],u=-1,c=a?a.length:0,f=i[0];e:for(;++u(f?He(f,l):o(s,l,0))){for(r=t;--r;){var d=i[r];if(0>(d?He(d,l):o(e[r],l,0)))continue e}f&&f.push(l),s.push(l)}return s}),Yi=cr(function(t,n){n=ft(n);var r=tt(t,n);return Et(t,n.sort(e)),r}),Wi=mn(),Gi=mn(!0),Ki=cr(function(e){return Nt(ft(e,!1,!0))}),Zi=cr(function(e,t){return Tn(e)?at(e,t):[]}),Ji=cr(Zn),Qi=cr(function(e){var t=e.length,n=2--e?t.apply(this,arguments):void 0}},Ie.ary=function(e,t,n){return n&&An(e,t,n)&&(t=$),t=e&&null==t?e.length:wi(+t||0,0),gn(e,T,$,$,$,$,t)},Ie.assign=Do,Ie.at=eo,Ie.before=sr,Ie.bind=mo,Ie.bindAll=go,Ie.bindKey=vo,Ie.callback=Rr,Ie.chain=Xn,Ie.chunk=function(e,t,n){t=(n?An(e,t,n):null==t)?1:wi(vi(t)||1,1),n=0;for(var r=e?e.length:0,i=-1,o=Ur(mi(r/t));nn&&(n=-n>i?0:i+n),r=r===$||r>i?i:+r||0,0>r&&(r+=i),i=n>r?0:r>>>0,n>>>=0;nt?0:t)):[]},Ie.takeRight=function(e,t,n){var r=e?e.length:0;return r?((n?An(e,t,n):null==t)&&(t=1),t=r-(+t||0),Mt(e,0>t?0:t)):[]},Ie.takeRightWhile=function(e,t,n){return e&&e.length?It(e,$n(t,n,3),!1,!0):[]},Ie.takeWhile=function(e,t,n){return e&&e.length?It(e,$n(t,n,3)):[]},Ie.tap=function(e,t,n){return t.call(n,e),e},Ie.throttle=function(e,t,n){var r=!0,i=!0;if("function"!=typeof e)throw new Kr(j);return!1===n?r=!1:gr(n)&&(r="leading"in n?!!n.leading:r,i="trailing"in n?!!n.trailing:i),lr(e,t,{leading:r,maxWait:+t,trailing:i})},Ie.thru=er,Ie.times=function(e,t,n){if(1>(e=vi(e))||!bi(e))return[];var r=-1,i=Ur(xi(e,4294967295));for(t=Lt(t,n,1);++rr?i[r]=t(r):t(r);return i},Ie.toArray=kr,Ie.toPlainObject=Er,Ie.transform=function(e,t,n,r){var i=Mo(e)||xr(e);return t=$n(t,r,4),null==n&&(i||gr(e)?(r=e.constructor,n=i?Mo(e)?new r:[]:Ni(mr(r)?r.prototype:$)):n={}),(i?Ve:pt)(e,function(e,r,i){return t(n,e,r,i)}),n},Ie.union=Ki,Ie.uniq=Kn,Ie.unzip=Zn,Ie.unzipWith=Jn,Ie.values=Tr,Ie.valuesIn=function(e){return Rt(e,_r(e))},Ie.where=function(e,t){return nr(e,$t(t))},Ie.without=Zi,Ie.wrap=function(e,t){return t=null==t?Ir:t,gn(t,_,$,[e],[])},Ie.xor=function(){for(var e=-1,t=arguments.length;++en?0:+n||0,r),0<=(n-=t.length)&&e.indexOf(t,n)==n},Ie.escape=function(e){return(e=i(e))&&de.test(e)?e.replace(ce,u):e},Ie.escapeRegExp=function(e){return(e=i(e))&&$e.test(e)?e.replace(be,c):e||"(?:)"},Ie.every=tr,Ie.find=no,Ie.findIndex=Vi,Ie.findKey=No,Ie.findLast=ro,Ie.findLastIndex=zi,Ie.findLastKey=Ro,Ie.findWhere=function(e,t){return no(e,$t(t))},Ie.first=Bn,Ie.floor=ea,Ie.get=function(e,t,n){return e=null==e?$:gt(e,Hn(t),t+""),e===$?n:e},Ie.gt=fr,Ie.gte=function(e,t){return e>=t},Ie.has=function(e,t){if(null==e)return!1;var n=ei.call(e,t);if(!n&&!On(t)){if(t=Hn(t),null==(e=1==t.length?e:gt(e,Mt(t,0,-1))))return!1;t=Wn(t),n=ei.call(e,t)}return n||Rn(e.length)&&Dn(t,e.length)&&(Mo(e)||dr(e))},Ie.identity=Ir,Ie.includes=rr,Ie.indexOf=Yn,Ie.inRange=function(e,t,n){return t=+t||0,n===$?(n=t,t=0):n=+n||0,e>=xi(t,n)&&en?wi(r+n,0):xi(n||0,r-1))+1;else if(n)return i=Ft(e,t,!0)-1,e=e[i],(t===t?t===e:e!==e)?i:-1;if(t!==t)return d(e,i,!0);for(;i--;)if(e[i]===t)return i;return-1},Ie.lt=Cr,Ie.lte=function(e,t){return e<=t},Ie.max=ta,Ie.min=na,Ie.noConflict=function(){return Ye._=ri,this},Ie.noop=jr,Ie.now=ho,Ie.pad=function(e,t,n){e=i(e),t=+t;var r=e.length;return rn?0:+n||0,e.length), e.lastIndexOf(t,n)==n},Ie.sum=function(e,t,n){if(n&&An(e,t,n)&&(t=$),t=$n(t,n,3),1==t.length){e=Mo(e)?e:Ln(e),n=e.length;for(var r=0;n--;)r+=+t(e[n])||0;e=r}else e=Ot(e,t);return e},Ie.template=function(e,t,n){var r=Ie.templateSettings;n&&An(e,t,n)&&(t=n=$),e=i(e),t=Xe(et({},n||t),r,Qe),n=Xe(et({},t.imports),r.imports,Qe);var o,a,s=Lo(n),l=Rt(n,s),u=0;n=t.interpolate||Te;var c="__p+='";n=Wr((t.escape||Te).source+"|"+n.source+"|"+(n===me?Ce:Te).source+"|"+(t.evaluate||Te).source+"|$","g");var d="sourceURL"in t?"//# sourceURL="+t.sourceURL+"\n":"";if(e.replace(n,function(t,n,r,i,s,l){return r||(r=i),c+=e.slice(u,l).replace(De,f),n&&(o=!0,c+="'+__e("+n+")+'"),s&&(a=!0,c+="';"+s+";\n__p+='"),r&&(c+="'+((__t=("+r+"))==null?'':__t)+'"),u=l+t.length,t}),c+="';",(t=t.variable)||(c="with(obj){"+c+"}"),c=(a?c.replace(ae,""):c).replace(se,"$1").replace(le,"$1;"),c="function("+(t||"obj")+"){"+(t?"":"obj||(obj={});")+"var __t,__p=''"+(o?",__e=_.escape":"")+(a?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+c+"return __p}",t=Zo(function(){return Vr(s,d+"return "+c).apply($,l)}),t.source=c,hr(t))throw t;return t},Ie.trim=Or,Ie.trimLeft=function(e,t,n){var r=e;return(e=i(e))?e.slice((n?An(r,t,n):null==t)?g(e):o(e,t+"")):e},Ie.trimRight=function(e,t,n){var r=e;return(e=i(e))?(n?An(r,t,n):null==t)?e.slice(0,v(e)+1):e.slice(0,a(e,t+"")+1):e},Ie.trunc=function(e,t,n){n&&An(e,t,n)&&(t=$);var r=A;if(n=O,null!=t)if(gr(t)){var o="separator"in t?t.separator:o,r="length"in t?+t.length||0:r;n="omission"in t?i(t.omission):n}else r=+t||0;if(e=i(e),r>=e.length)return e;if(1>(r-=n.length))return n;if(t=e.slice(0,r),null==o)return t+n;if($r(o)){if(e.slice(r).search(o)){var a,s=e.slice(0,r);for(o.global||(o=Wr(o.source,(ke.exec(o)||"")+"g")),o.lastIndex=0;e=o.exec(s);)a=e.index;t=t.slice(0,null==a?r:a)}}else e.indexOf(o,r)!=r&&-1<(o=t.lastIndexOf(o))&&(t=t.slice(0,o));return t+n},Ie.unescape=function(e){return(e=i(e))&&fe.test(e)?e.replace(ue,y):e},Ie.uniqueId=function(e){var t=++ti;return i(e)+t},Ie.words=Nr,Ie.all=tr,Ie.any=ar,Ie.contains=rr,Ie.eq=pr,Ie.detect=no,Ie.foldl=co,Ie.foldr=fo,Ie.head=Bn,Ie.include=rr,Ie.inject=co,Fr(Ie,function(){var e={};return pt(Ie,function(t,n){Ie.prototype[n]||(e[n]=t)}),e}(),!1),Ie.sample=or,Ie.prototype.sample=function(e){return this.__chain__||null!=e?this.thru(function(t){return or(t,e)}):or(this.value())},Ie.VERSION=w,Ve("bind bindKey curry curryRight partial partialRight".split(" "),function(e){Ie[e].placeholder=Ie}),Ve(["drop","take"],function(e,t){je.prototype[e]=function(n){var r=this.__filtered__;if(r&&!t)return new je(this);n=null==n?1:wi(vi(n)||0,0);var i=this.clone();return r?i.__takeCount__=xi(i.__takeCount__,n):i.__views__.push({size:n,type:e+(0>i.__dir__?"Right":"")}),i},je.prototype[e+"Right"]=function(t){return this.reverse()[e](t).reverse()}}),Ve(["filter","map","takeWhile"],function(e,t){var n=t+1,r=n!=F;je.prototype[e]=function(e,t){var i=this.clone();return i.__iteratees__.push({iteratee:$n(e,t,1),type:n}),i.__filtered__=i.__filtered__||r,i}}),Ve(["first","last"],function(e,t){var n="take"+(t?"Right":"");je.prototype[e]=function(){return this[n](1).value()[0]}}),Ve(["initial","rest"],function(e,t){var n="drop"+(t?"":"Right");je.prototype[e]=function(){return this.__filtered__?new je(this):this[n](1)}}),Ve(["pluck","where"],function(e,t){var n=t?"filter":"map",r=t?$t:Lr;je.prototype[e]=function(e){return this[n](r(e))}}),je.prototype.compact=function(){return this.filter(Ir)},je.prototype.reject=function(e,t){return e=$n(e,t,1),this.filter(function(t){return!e(t)})},je.prototype.slice=function(e,t){e=null==e?0:+e||0;var n=this;return n.__filtered__&&(0t)?new je(n):(0>e?n=n.takeRight(-e):e&&(n=n.drop(e)),t!==$&&(t=+t||0,n=0>t?n.dropRight(-t):n.take(t-e)),n)},je.prototype.takeRightWhile=function(e,t){return this.reverse().takeWhile(e,t).reverse()},je.prototype.toArray=function(){return this.take(_i)},pt(je.prototype,function(e,t){var n=/^(?:filter|map|reject)|While$/.test(t),r=/^(?:first|last)$/.test(t),i=Ie[r?"take"+("last"==t?"Right":""):t];i&&(Ie.prototype[t]=function(){function t(e){return r&&a?i(e,1)[0]:i.apply($,Ke([e],o))}var o=r?[1]:arguments,a=this.__chain__,s=this.__wrapped__,l=!!this.__actions__.length,u=s instanceof je,c=o[0],f=u||Mo(s);return f&&n&&"function"==typeof c&&1!=c.length&&(u=f=!1),c={func:er,args:[t],thisArg:$},l=u&&!l,r&&!a?l?(s=s.clone(),s.__actions__.push(c),e.call(s)):i.call($,this.value())[0]:!r&&f?(s=l?s:new je(this),s=e.apply(s,o),s.__actions__.push(c),new Fe(s,a)):this.thru(t)})}),Ve("join pop push replace shift sort splice split unshift".split(" "),function(e){var t=(/^(?:replace|split)$/.test(e)?Qr:Zr)[e],n=/^(?:push|sort|unshift)$/.test(e)?"tap":"thru",r=/^(?:join|pop|replace|shift)$/.test(e);Ie.prototype[e]=function(){var e=arguments;return r&&!this.__chain__?t.apply(this.value(),e):this[n](function(n){return t.apply(n,e)})}}),pt(je.prototype,function(e,t){var n=Ie[t];if(n){var r=n.name+"";(Oi[r]||(Oi[r]=[])).push({name:t,func:n})}}),Oi[fn($,C).name]=[{name:"wrapper",func:$}],je.prototype.clone=function(){var e=new je(this.__wrapped__);return e.__actions__=qe(this.__actions__),e.__dir__=this.__dir__,e.__filtered__=this.__filtered__,e.__iteratees__=qe(this.__iteratees__),e.__takeCount__=this.__takeCount__,e.__views__=qe(this.__views__),e},je.prototype.reverse=function(){if(this.__filtered__){var e=new je(this);e.__dir__=-1,e.__filtered__=!0}else e=this.clone(),e.__dir__*=-1;return e},je.prototype.value=function(){var e,t=this.__wrapped__.value(),n=this.__dir__,r=Mo(t),i=0>n,o=r?t.length:0;e=o;for(var a=this.__views__,s=0,l=-1,u=a.length;++l"'`]/g,fe=RegExp(ue.source),de=RegExp(ce.source),pe=/<%-([\s\S]+?)%>/g,he=/<%([\s\S]+?)%>/g,me=/<%=([\s\S]+?)%>/g,ge=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/,ve=/^\w*$/,ye=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g,be=/^[:!,]|[\\^$.*+?()[\]{}|\/]|(^[0-9a-fA-Fnrtuvx])|([\n\r\u2028\u2029])/g,$e=RegExp(be.source),we=/[\u0300-\u036f\ufe20-\ufe23]/g,xe=/\\(\\)?/g,Ce=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,ke=/\w*$/,Ee=/^0[xX]/,Se=/^\[object .+?Constructor\]$/,_e=/^\d+$/,Me=/[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g,Te=/($^)/,De=/['\n\r\u2028\u2029\\]/g,Ae=RegExp("[A-Z\\xc0-\\xd6\\xd8-\\xde]+(?=[A-Z\\xc0-\\xd6\\xd8-\\xde][a-z\\xdf-\\xf6\\xf8-\\xff]+)|[A-Z\\xc0-\\xd6\\xd8-\\xde]?[a-z\\xdf-\\xf6\\xf8-\\xff]+|[A-Z\\xc0-\\xd6\\xd8-\\xde]+|[0-9]+","g"),Oe="Array ArrayBuffer Date Error Float32Array Float64Array Function Int8Array Int16Array Int32Array Math Number Object RegExp Set String _ clearTimeout isFinite parseFloat parseInt setTimeout TypeError Uint8Array Uint8ClampedArray Uint16Array Uint32Array WeakMap".split(" "),Ne={};Ne[J]=Ne[Q]=Ne[X]=Ne[ee]=Ne[te]=Ne[ne]=Ne[re]=Ne[ie]=Ne[oe]=!0,Ne[U]=Ne[H]=Ne[Z]=Ne[q]=Ne[V]=Ne[z]=Ne[B]=Ne["[object Map]"]=Ne[Y]=Ne[W]=Ne[G]=Ne["[object Set]"]=Ne[K]=Ne["[object WeakMap]"]=!1;var Re={};Re[U]=Re[H]=Re[Z]=Re[q]=Re[V]=Re[J]=Re[Q]=Re[X]=Re[ee]=Re[te]=Re[Y]=Re[W]=Re[G]=Re[K]=Re[ne]=Re[re]=Re[ie]=Re[oe]=!0,Re[z]=Re[B]=Re["[object Map]"]=Re["[object Set]"]=Re["[object WeakMap]"]=!1;var Ie={"À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","Ç":"C","ç":"c","Ð":"D","ð":"d","È":"E","É":"E","Ê":"E","Ë":"E","è":"e","é":"e","ê":"e","ë":"e","Ì":"I","Í":"I","Î":"I","Ï":"I","ì":"i","í":"i","î":"i","ï":"i","Ñ":"N","ñ":"n","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","Ù":"U","Ú":"U","Û":"U","Ü":"U","ù":"u","ú":"u","û":"u","ü":"u","Ý":"Y","ý":"y","ÿ":"y","Æ":"Ae","æ":"ae","Þ":"Th","þ":"th","ß":"ss"},Pe={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},Fe={"&":"&","<":"<",">":">",""":'"',"'":"'","`":"`"},je={function:!0,object:!0},Le={0:"x30",1:"x31",2:"x32",3:"x33",4:"x34",5:"x35",6:"x36",7:"x37",8:"x38",9:"x39",A:"x41",B:"x42",C:"x43",D:"x44",E:"x45",F:"x46",a:"x61",b:"x62",c:"x63",d:"x64",e:"x65",f:"x66",n:"x6e",r:"x72",t:"x74",u:"x75",v:"x76",x:"x78"},Ue={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},He=je[typeof exports]&&exports&&!exports.nodeType&&exports,qe=je[typeof module]&&module&&!module.nodeType&&module,Ve=je[typeof self]&&self&&self.Object&&self,ze=je[typeof window]&&window&&window.Object&&window,Be=qe&&qe.exports===He&&He,Ye=He&&qe&&"object"==typeof global&&global&&global.Object&&global||ze!==(this&&this.window)&&ze||Ve||this,We=b();"function"==typeof define&&"object"==typeof define.amd&&define.amd?(Ye._=We,define("common/lodash",[],function(){return We})):He&&qe?Be?(qe.exports=We)._=We:He._=We:Ye._=We}.call(this),function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define("common/moment",t):e.moment=t()}(this,function(){"use strict";function e(){return Yn.apply(null,arguments)}function t(e){return"[object Array]"===Object.prototype.toString.call(e)}function n(e){return e instanceof Date||"[object Date]"===Object.prototype.toString.call(e)}function r(e,t){var n,r=[];for(n=0;n0)for(n in Gn)r=Gn[n],i=t[r],f(i)||(e[r]=i);return e}function p(t){d(this,t),this._d=new Date(null!=t._d?t._d.getTime():NaN),!1===Kn&&(Kn=!0,e.updateOffset(this),Kn=!1)}function h(e){return e instanceof p||null!=e&&null!=e._isAMomentObject}function m(e){return 0>e?Math.ceil(e):Math.floor(e)}function g(e){var t=+e,n=0;return 0!==t&&isFinite(t)&&(n=m(t)),n}function v(e,t,n){var r,i=Math.min(e.length,t.length),o=Math.abs(e.length-t.length),a=0;for(r=0;i>r;r++)(n&&e[r]!==t[r]||!n&&g(e[r])!==g(t[r]))&&a++;return a+o}function y(){}function b(e){return e?e.toLowerCase().replace("_","-"):e}function $(e){for(var t,n,r,i,o=0;o0;){if(r=w(i.slice(0,t).join("-")))return r;if(n&&n.length>=t&&v(i,n,!0)>=t-1)break;t--}o++}return null}function w(e){var t=null;if(!Zn[e]&&"undefined"!=typeof module&&module&&module.exports)try{t=Wn._abbr,require("./locale/"+e),x(t)}catch(e){}return Zn[e]}function x(e,t){var n;return e&&(n=f(t)?k(e):C(e,t))&&(Wn=n),Wn._abbr}function C(e,t){return null!==t?(t.abbr=e,Zn[e]=Zn[e]||new y,Zn[e].set(t),x(e),Zn[e]):(delete Zn[e],null)}function k(e){var n;if(e&&e._locale&&e._locale._abbr&&(e=e._locale._abbr),!e)return Wn;if(!t(e)){if(n=w(e))return n;e=[e]}return $(e)}function E(e,t){var n=e.toLowerCase();Jn[n]=Jn[n+"s"]=Jn[t]=e}function S(e){return"string"==typeof e?Jn[e]||Jn[e.toLowerCase()]:void 0}function _(e){var t,n,r={};for(n in e)i(e,n)&&(t=S(n))&&(r[t]=e[n]);return r}function M(e){return e instanceof Function||"[object Function]"===Object.prototype.toString.call(e)}function T(t,n){return function(r){return null!=r?(A(this,t,r),e.updateOffset(this,n),this):D(this,t)}}function D(e,t){return e.isValid()?e._d["get"+(e._isUTC?"UTC":"")+t]():NaN}function A(e,t,n){e.isValid()&&e._d["set"+(e._isUTC?"UTC":"")+t](n)}function O(e,t){var n;if("object"==typeof e)for(n in e)this.set(n,e[n]);else if(e=S(e),M(this[e]))return this[e](t);return this}function N(e,t,n){var r=""+Math.abs(e),i=t-r.length;return(e>=0?n?"+":"":"-")+Math.pow(10,Math.max(0,i)).toString().substr(1)+r}function R(e,t,n,r){var i=r;"string"==typeof r&&(i=function(){return this[r]()}),e&&(tr[e]=i),t&&(tr[t[0]]=function(){return N(i.apply(this,arguments),t[1],t[2])}),n&&(tr[n]=function(){return this.localeData().ordinal(i.apply(this,arguments),e)})}function I(e){return e.match(/\[[\s\S]/)?e.replace(/^\[|\]$/g,""):e.replace(/\\/g,"")}function P(e){var t,n,r=e.match(Qn);for(t=0,n=r.length;n>t;t++)tr[r[t]]?r[t]=tr[r[t]]:r[t]=I(r[t]);return function(i){var o="";for(t=0;n>t;t++)o+=r[t]instanceof Function?r[t].call(i,e):r[t];return o}}function F(e,t){return e.isValid()?(t=j(t,e.localeData()),er[t]=er[t]||P(t),er[t](e)):e.localeData().invalidDate()}function j(e,t){function n(e){return t.longDateFormat(e)||e}var r=5;for(Xn.lastIndex=0;r>=0&&Xn.test(e);)e=e.replace(Xn,n),Xn.lastIndex=0,r-=1;return e}function L(e,t,n){br[e]=M(t)?t:function(e,r){return e&&n?n:t}}function U(e,t){return i(br,e)?br[e](t._strict,t._locale):new RegExp(H(e))}function H(e){return q(e.replace("\\","").replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g,function(e,t,n,r,i){return t||n||r||i}))}function q(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}function V(e,t){var n,r=t;for("string"==typeof e&&(e=[e]),"number"==typeof t&&(r=function(e,n){n[t]=g(e)}),n=0;nr;r++){if(i=a([2e3,r]),n&&!this._longMonthsParse[r]&&(this._longMonthsParse[r]=new RegExp("^"+this.months(i,"").replace(".","")+"$","i"),this._shortMonthsParse[r]=new RegExp("^"+this.monthsShort(i,"").replace(".","")+"$","i")),n||this._monthsParse[r]||(o="^"+this.months(i,"")+"|^"+this.monthsShort(i,""),this._monthsParse[r]=new RegExp(o.replace(".",""),"i")),n&&"MMMM"===t&&this._longMonthsParse[r].test(e))return r;if(n&&"MMM"===t&&this._shortMonthsParse[r].test(e))return r;if(!n&&this._monthsParse[r].test(e))return r}}function Z(e,t){var n;return e.isValid()?"string"==typeof t&&"number"!=typeof(t=e.localeData().monthsParse(t))?e:(n=Math.min(e.date(),Y(e.year(),t)),e._d["set"+(e._isUTC?"UTC":"")+"Month"](t,n),e):e}function J(t){return null!=t?(Z(this,t),e.updateOffset(this,!0),this):D(this,"Month")}function Q(){return Y(this.year(),this.month())}function X(e){return this._monthsParseExact?(i(this,"_monthsRegex")||te.call(this),e?this._monthsShortStrictRegex:this._monthsShortRegex):this._monthsShortStrictRegex&&e?this._monthsShortStrictRegex:this._monthsShortRegex}function ee(e){return this._monthsParseExact?(i(this,"_monthsRegex")||te.call(this),e?this._monthsStrictRegex:this._monthsRegex):this._monthsStrictRegex&&e?this._monthsStrictRegex:this._monthsRegex}function te(){function e(e,t){return t.length-e.length}var t,n,r=[],i=[],o=[];for(t=0;12>t;t++)n=a([2e3,t]),r.push(this.monthsShort(n,"")),i.push(this.months(n,"")),o.push(this.months(n,"")),o.push(this.monthsShort(n,""));for(r.sort(e),i.sort(e),o.sort(e),t=0;12>t;t++)r[t]=q(r[t]),i[t]=q(i[t]),o[t]=q(o[t]);this._monthsRegex=new RegExp("^("+o.join("|")+")","i"),this._monthsShortRegex=this._monthsRegex,this._monthsStrictRegex=new RegExp("^("+i.join("|")+")$","i"),this._monthsShortStrictRegex=new RegExp("^("+r.join("|")+")$","i")}function ne(e){var t,n=e._a;return n&&-2===l(e).overflow&&(t=n[xr]<0||n[xr]>11?xr:n[Cr]<1||n[Cr]>Y(n[wr],n[xr])?Cr:n[kr]<0||n[kr]>24||24===n[kr]&&(0!==n[Er]||0!==n[Sr]||0!==n[_r])?kr:n[Er]<0||n[Er]>59?Er:n[Sr]<0||n[Sr]>59?Sr:n[_r]<0||n[_r]>999?_r:-1,l(e)._overflowDayOfYear&&(wr>t||t>Cr)&&(t=Cr),l(e)._overflowWeeks&&-1===t&&(t=Mr),l(e)._overflowWeekday&&-1===t&&(t=Tr),l(e).overflow=t),e}function re(t){!1===e.suppressDeprecationWarnings&&"undefined"!=typeof console&&console.warn&&console.warn("Deprecation warning: "+t)}function ie(e,t){var n=!0;return o(function(){return n&&(re(e+"\nArguments: "+Array.prototype.slice.call(arguments).join(", ")+"\n"+(new Error).stack),n=!1),t.apply(this,arguments)},t)}function oe(e,t){Ir[e]||(re(t),Ir[e]=!0)}function ae(e){var t,n,r,i,o,a,s=e._i,u=Pr.exec(s)||Fr.exec(s);if(u){for(l(e).iso=!0,t=0,n=Lr.length;n>t;t++)if(Lr[t][1].exec(u[1])){i=Lr[t][0],r=!1!==Lr[t][2];break}if(null==i)return void(e._isValid=!1);if(u[3]){for(t=0,n=Ur.length;n>t;t++)if(Ur[t][1].exec(u[3])){o=(u[2]||" ")+Ur[t][0];break}if(null==o)return void(e._isValid=!1)}if(!r&&null!=o)return void(e._isValid=!1);if(u[4]){if(!jr.exec(u[4]))return void(e._isValid=!1);a="Z"}e._f=i+(o||"")+(a||""),we(e)}else e._isValid=!1}function se(t){var n=Hr.exec(t._i);return null!==n?void(t._d=new Date(+n[1])):(ae(t),void(!1===t._isValid&&(delete t._isValid,e.createFromInputFallback(t))))}function le(e,t,n,r,i,o,a){var s=new Date(e,t,n,r,i,o,a);return 100>e&&e>=0&&isFinite(s.getFullYear())&&s.setFullYear(e),s}function ue(e){var t=new Date(Date.UTC.apply(null,arguments));return 100>e&&e>=0&&isFinite(t.getUTCFullYear())&&t.setUTCFullYear(e),t}function ce(e){return fe(e)?366:365}function fe(e){return e%4==0&&e%100!=0||e%400==0}function de(){return fe(this.year())}function pe(e,t,n){var r=7+t-n;return-(7+ue(e,0,r).getUTCDay()-t)%7+r-1}function he(e,t,n,r,i){var o,a,s=(7+n-r)%7,l=pe(e,r,i),u=1+7*(t-1)+s+l;return 0>=u?(o=e-1,a=ce(o)+u):u>ce(e)?(o=e+1,a=u-ce(e)):(o=e,a=u),{year:o,dayOfYear:a}}function me(e,t,n){var r,i,o=pe(e.year(),t,n),a=Math.floor((e.dayOfYear()-o-1)/7)+1;return 1>a?(i=e.year()-1,r=a+ge(i,t,n)):a>ge(e.year(),t,n)?(r=a-ge(e.year(),t,n),i=e.year()+1):(i=e.year(),r=a),{week:r,year:i}}function ge(e,t,n){var r=pe(e,t,n),i=pe(e+1,t,n);return(ce(e)-r+i)/7}function ve(e,t,n){return null!=e?e:null!=t?t:n}function ye(t){var n=new Date(e.now());return t._useUTC?[n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate()]:[n.getFullYear(),n.getMonth(),n.getDate()]}function be(e){var t,n,r,i,o=[];if(!e._d){for(r=ye(e),e._w&&null==e._a[Cr]&&null==e._a[xr]&&$e(e),e._dayOfYear&&(i=ve(e._a[wr],r[wr]),e._dayOfYear>ce(i)&&(l(e)._overflowDayOfYear=!0),n=ue(i,0,e._dayOfYear),e._a[xr]=n.getUTCMonth(),e._a[Cr]=n.getUTCDate()),t=0;3>t&&null==e._a[t];++t)e._a[t]=o[t]=r[t];for(;7>t;t++)e._a[t]=o[t]=null==e._a[t]?2===t?1:0:e._a[t];24===e._a[kr]&&0===e._a[Er]&&0===e._a[Sr]&&0===e._a[_r]&&(e._nextDay=!0,e._a[kr]=0),e._d=(e._useUTC?ue:le).apply(null,o),null!=e._tzm&&e._d.setUTCMinutes(e._d.getUTCMinutes()-e._tzm),e._nextDay&&(e._a[kr]=24)}}function $e(e){var t,n,r,i,o,a,s,u;t=e._w,null!=t.GG||null!=t.W||null!=t.E?(o=1,a=4,n=ve(t.GG,e._a[wr],me(Te(),1,4).year),r=ve(t.W,1),(1>(i=ve(t.E,1))||i>7)&&(u=!0)):(o=e._locale._week.dow,a=e._locale._week.doy,n=ve(t.gg,e._a[wr],me(Te(),o,a).year),r=ve(t.w,1),null!=t.d?(0>(i=t.d)||i>6)&&(u=!0):null!=t.e?(i=t.e+o,(t.e<0||t.e>6)&&(u=!0)):i=o),1>r||r>ge(n,o,a)?l(e)._overflowWeeks=!0:null!=u?l(e)._overflowWeekday=!0:(s=he(n,r,i,o,a),e._a[wr]=s.year,e._dayOfYear=s.dayOfYear)}function we(t){if(t._f===e.ISO_8601)return void ae(t);t._a=[],l(t).empty=!0;var n,r,i,o,a,s=""+t._i,u=s.length,c=0;for(i=j(t._f,t._locale).match(Qn)||[],n=0;n0&&l(t).unusedInput.push(a),s=s.slice(s.indexOf(r)+r.length),c+=r.length),tr[o]?(r?l(t).empty=!1:l(t).unusedTokens.push(o),B(o,r,t)):t._strict&&!r&&l(t).unusedTokens.push(o);l(t).charsLeftOver=u-c,s.length>0&&l(t).unusedInput.push(s),!0===l(t).bigHour&&t._a[kr]<=12&&t._a[kr]>0&&(l(t).bigHour=void 0),t._a[kr]=xe(t._locale,t._a[kr],t._meridiem),be(t),ne(t)}function xe(e,t,n){var r;return null==n?t:null!=e.meridiemHour?e.meridiemHour(t,n):null!=e.isPM?(r=e.isPM(n),r&&12>t&&(t+=12),r||12!==t||(t=0),t):t}function Ce(e){var t,n,r,i,a;if(0===e._f.length)return l(e).invalidFormat=!0,void(e._d=new Date(NaN));for(i=0;ia)&&(r=a,n=t));o(e,n||t)}function ke(e){if(!e._d){var t=_(e._i);e._a=r([t.year,t.month,t.day||t.date,t.hour,t.minute,t.second,t.millisecond],function(e){return e&&parseInt(e,10)}),be(e)}}function Ee(e){var t=new p(ne(Se(e)));return t._nextDay&&(t.add(1,"d"),t._nextDay=void 0),t}function Se(e){var r=e._i,i=e._f;return e._locale=e._locale||k(e._l),null===r||void 0===i&&""===r?c({nullInput:!0}):("string"==typeof r&&(e._i=r=e._locale.preparse(r)),h(r)?new p(ne(r)):(t(i)?Ce(e):i?we(e):n(r)?e._d=r:_e(e),u(e)||(e._d=null),e))}function _e(i){var o=i._i;void 0===o?i._d=new Date(e.now()):n(o)?i._d=new Date(+o):"string"==typeof o?se(i):t(o)?(i._a=r(o.slice(0),function(e){return parseInt(e,10)}),be(i)):"object"==typeof o?ke(i):"number"==typeof o?i._d=new Date(o):e.createFromInputFallback(i)}function Me(e,t,n,r,i){var o={};return"boolean"==typeof n&&(r=n,n=void 0),o._isAMomentObject=!0,o._useUTC=o._isUTC=i,o._l=n,o._i=e,o._f=t,o._strict=r,Ee(o)}function Te(e,t,n,r){return Me(e,t,n,r,!1)}function De(e,n){var r,i;if(1===n.length&&t(n[0])&&(n=n[0]),!n.length)return Te();for(r=n[0],i=1;ie&&(e=-e,n="-"),n+N(~~(e/60),2)+t+N(~~e%60,2)})}function Pe(e,t){var n=(t||"").match(e)||[],r=n[n.length-1]||[],i=(r+"").match(Yr)||["-",0,0],o=60*i[1]+g(i[2]);return"+"===i[0]?o:-o}function Fe(t,r){var i,o;return r._isUTC?(i=r.clone(),o=(h(t)||n(t)?+t:+Te(t))-+i,i._d.setTime(+i._d+o),e.updateOffset(i,!1),i):Te(t).local()}function je(e){return 15*-Math.round(e._d.getTimezoneOffset()/15)}function Le(t,n){var r,i=this._offset||0;return this.isValid()?null!=t?("string"==typeof t?t=Pe(gr,t):Math.abs(t)<16&&(t*=60),!this._isUTC&&n&&(r=je(this)),this._offset=t,this._isUTC=!0,null!=r&&this.add(r,"m"),i!==t&&(!n||this._changeInProgress?tt(this,Ze(t-i,"m"),1,!1):this._changeInProgress||(this._changeInProgress=!0,e.updateOffset(this,!0),this._changeInProgress=null)),this):this._isUTC?i:je(this):null!=t?this:NaN}function Ue(e,t){return null!=e?("string"!=typeof e&&(e=-e),this.utcOffset(e,t),this):-this.utcOffset()}function He(e){return this.utcOffset(0,e)}function qe(e){return this._isUTC&&(this.utcOffset(0,e),this._isUTC=!1,e&&this.subtract(je(this),"m")),this}function Ve(){return this._tzm?this.utcOffset(this._tzm):"string"==typeof this._i&&this.utcOffset(Pe(mr,this._i)),this}function ze(e){return!!this.isValid()&&(e=e?Te(e).utcOffset():0,(this.utcOffset()-e)%60==0)}function Be(){return this.utcOffset()>this.clone().month(0).utcOffset()||this.utcOffset()>this.clone().month(5).utcOffset()}function Ye(){if(!f(this._isDSTShifted))return this._isDSTShifted;var e={};if(d(e,this),e=Se(e),e._a){var t=e._isUTC?a(e._a):Te(e._a);this._isDSTShifted=this.isValid()&&v(e._a,t.toArray())>0}else this._isDSTShifted=!1;return this._isDSTShifted}function We(){return!!this.isValid()&&!this._isUTC}function Ge(){return!!this.isValid()&&this._isUTC}function Ke(){return!!this.isValid()&&(this._isUTC&&0===this._offset)}function Ze(e,t){var n,r,o,a=e,s=null;return Re(e)?a={ms:e._milliseconds,d:e._days,M:e._months}:"number"==typeof e?(a={},t?a[t]=e:a.milliseconds=e):(s=Wr.exec(e))?(n="-"===s[1]?-1:1,a={y:0,d:g(s[Cr])*n,h:g(s[kr])*n,m:g(s[Er])*n,s:g(s[Sr])*n,ms:g(s[_r])*n}):(s=Gr.exec(e))?(n="-"===s[1]?-1:1,a={y:Je(s[2],n),M:Je(s[3],n),d:Je(s[4],n),h:Je(s[5],n),m:Je(s[6],n),s:Je(s[7],n),w:Je(s[8],n)}):null==a?a={}:"object"==typeof a&&("from"in a||"to"in a)&&(o=Xe(Te(a.from),Te(a.to)),a={},a.ms=o.milliseconds,a.M=o.months),r=new Ne(a),Re(e)&&i(e,"_locale")&&(r._locale=e._locale),r}function Je(e,t){var n=e&&parseFloat(e.replace(",","."));return(isNaN(n)?0:n)*t}function Qe(e,t){var n={milliseconds:0,months:0};return n.months=t.month()-e.month()+12*(t.year()-e.year()),e.clone().add(n.months,"M").isAfter(t)&&--n.months,n.milliseconds=+t-+e.clone().add(n.months,"M"),n}function Xe(e,t){var n;return e.isValid()&&t.isValid()?(t=Fe(t,e),e.isBefore(t)?n=Qe(e,t):(n=Qe(t,e),n.milliseconds=-n.milliseconds,n.months=-n.months),n):{milliseconds:0,months:0}}function et(e,t){return function(n,r){var i,o;return null===r||isNaN(+r)||(oe(t,"moment()."+t+"(period, number) is deprecated. Please use moment()."+t+"(number, period)."),o=n,n=r,r=o),n="string"==typeof n?+n:n,i=Ze(n,r),tt(this,i,e),this}}function tt(t,n,r,i){var o=n._milliseconds,a=n._days,s=n._months;t.isValid()&&(i=null==i||i,o&&t._d.setTime(+t._d+o*r),a&&A(t,"Date",D(t,"Date")+a*r),s&&Z(t,D(t,"Month")+s*r),i&&e.updateOffset(t,a||s))}function nt(e,t){var n=e||Te(),r=Fe(n,this).startOf("day"),i=this.diff(r,"days",!0),o=-6>i?"sameElse":-1>i?"lastWeek":0>i?"lastDay":1>i?"sameDay":2>i?"nextDay":7>i?"nextWeek":"sameElse",a=t&&(M(t[o])?t[o]():t[o]);return this.format(a||this.localeData().calendar(o,this,Te(n)))}function rt(){return new p(this)}function it(e,t){var n=h(e)?e:Te(e);return!(!this.isValid()||!n.isValid())&&(t=S(f(t)?"millisecond":t),"millisecond"===t?+this>+n:+n<+this.clone().startOf(t))}function ot(e,t){var n=h(e)?e:Te(e);return!(!this.isValid()||!n.isValid())&&(t=S(f(t)?"millisecond":t),"millisecond"===t?+n>+this:+this.clone().endOf(t)<+n)}function at(e,t,n){return this.isAfter(e,n)&&this.isBefore(t,n)}function st(e,t){var n,r=h(e)?e:Te(e);return!(!this.isValid()||!r.isValid())&&(t=S(t||"millisecond"),"millisecond"===t?+this==+r:(n=+r,+this.clone().startOf(t)<=n&&n<=+this.clone().endOf(t)))}function lt(e,t){return this.isSame(e,t)||this.isAfter(e,t)}function ut(e,t){return this.isSame(e,t)||this.isBefore(e,t)}function ct(e,t,n){var r,i,o,a;return this.isValid()?(r=Fe(e,this),r.isValid()?(i=6e4*(r.utcOffset()-this.utcOffset()),t=S(t),"year"===t||"month"===t||"quarter"===t?(a=ft(this,r),"quarter"===t?a/=3:"year"===t&&(a/=12)):(o=this-r,a="second"===t?o/1e3:"minute"===t?o/6e4:"hour"===t?o/36e5:"day"===t?(o-i)/864e5:"week"===t?(o-i)/6048e5:o),n?a:m(a)):NaN):NaN}function ft(e,t){var n,r,i=12*(t.year()-e.year())+(t.month()-e.month()),o=e.clone().add(i,"months");return 0>t-o?(n=e.clone().add(i-1,"months"),r=(t-o)/(o-n)):(n=e.clone().add(i+1,"months"),r=(t-o)/(n-o)),-(i+r)}function dt(){return this.clone().locale("en").format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ")}function pt(){var e=this.clone().utc();return 0o&&(t=o),Lt.call(this,e,t,n,r,i))}function Lt(e,t,n,r,i){var o=he(e,t,n,r,i),a=ue(o.year,0,o.dayOfYear);return this.year(a.getUTCFullYear()),this.month(a.getUTCMonth()), -this.date(a.getUTCDate()),this}function Ut(e){return null==e?Math.ceil((this.month()+1)/3):this.month(3*(e-1)+this.month()%3)}function Ht(e){return me(e,this._week.dow,this._week.doy).week}function qt(){return this._week.dow}function Vt(){return this._week.doy}function zt(e){var t=this.localeData().week(this);return null==e?t:this.add(7*(e-t),"d")}function Bt(e){var t=me(this,1,4).week;return null==e?t:this.add(7*(e-t),"d")}function Yt(e,t){return"string"!=typeof e?e:isNaN(e)?(e=t.weekdaysParse(e),"number"==typeof e?e:null):parseInt(e,10)}function Wt(e,n){return t(this._weekdays)?this._weekdays[e.day()]:this._weekdays[this._weekdays.isFormat.test(n)?"format":"standalone"][e.day()]}function Gt(e){return this._weekdaysShort[e.day()]}function Kt(e){return this._weekdaysMin[e.day()]}function Zt(e,t,n){var r,i,o;for(this._weekdaysParse||(this._weekdaysParse=[],this._minWeekdaysParse=[],this._shortWeekdaysParse=[],this._fullWeekdaysParse=[]),r=0;7>r;r++){if(i=Te([2e3,1]).day(r),n&&!this._fullWeekdaysParse[r]&&(this._fullWeekdaysParse[r]=new RegExp("^"+this.weekdays(i,"").replace(".",".?")+"$","i"),this._shortWeekdaysParse[r]=new RegExp("^"+this.weekdaysShort(i,"").replace(".",".?")+"$","i"),this._minWeekdaysParse[r]=new RegExp("^"+this.weekdaysMin(i,"").replace(".",".?")+"$","i")),this._weekdaysParse[r]||(o="^"+this.weekdays(i,"")+"|^"+this.weekdaysShort(i,"")+"|^"+this.weekdaysMin(i,""),this._weekdaysParse[r]=new RegExp(o.replace(".",""),"i")),n&&"dddd"===t&&this._fullWeekdaysParse[r].test(e))return r;if(n&&"ddd"===t&&this._shortWeekdaysParse[r].test(e))return r;if(n&&"dd"===t&&this._minWeekdaysParse[r].test(e))return r;if(!n&&this._weekdaysParse[r].test(e))return r}}function Jt(e){if(!this.isValid())return null!=e?this:NaN;var t=this._isUTC?this._d.getUTCDay():this._d.getDay();return null!=e?(e=Yt(e,this.localeData()),this.add(e-t,"d")):t}function Qt(e){if(!this.isValid())return null!=e?this:NaN;var t=(this.day()+7-this.localeData()._week.dow)%7;return null==e?t:this.add(e-t,"d")}function Xt(e){return this.isValid()?null==e?this.day()||7:this.day(this.day()%7?e:e-7):null!=e?this:NaN}function en(e){var t=Math.round((this.clone().startOf("day")-this.clone().startOf("year"))/864e5)+1;return null==e?t:this.add(e-t,"d")}function tn(){return this.hours()%12||12}function nn(e,t){R(e,0,0,function(){return this.localeData().meridiem(this.hours(),this.minutes(),t)})}function rn(e,t){return t._meridiemParse}function on(e){return"p"===(e+"").toLowerCase().charAt(0)}function an(e,t,n){return e>11?n?"pm":"PM":n?"am":"AM"}function sn(e,t){t[_r]=g(1e3*("0."+e))}function ln(){return this._isUTC?"UTC":""}function un(){return this._isUTC?"Coordinated Universal Time":""}function cn(e){return Te(1e3*e)}function fn(){return Te.apply(null,arguments).parseZone()}function dn(e,t,n){var r=this._calendar[e];return M(r)?r.call(t,n):r}function pn(e){var t=this._longDateFormat[e],n=this._longDateFormat[e.toUpperCase()];return t||!n?t:(this._longDateFormat[e]=n.replace(/MMMM|MM|DD|dddd/g,function(e){return e.slice(1)}),this._longDateFormat[e])}function hn(){return this._invalidDate}function mn(e){return this._ordinal.replace("%d",e)}function gn(e){return e}function vn(e,t,n,r){var i=this._relativeTime[n];return M(i)?i(e,t,n,r):i.replace(/%d/i,e)}function yn(e,t){var n=this._relativeTime[e>0?"future":"past"];return M(n)?n(t):n.replace(/%s/i,t)}function bn(e){var t,n;for(n in e)t=e[n],M(t)?this[n]=t:this["_"+n]=t;this._ordinalParseLenient=new RegExp(this._ordinalParse.source+"|"+/\d{1,2}/.source)}function $n(e,t,n,r){var i=k(),o=a().set(r,t);return i[n](o,e)}function wn(e,t,n,r,i){if("number"==typeof e&&(t=e,e=void 0),e=e||"",null!=t)return $n(e,t,n,i);var o,a=[];for(o=0;r>o;o++)a[o]=$n(e,o,n,i);return a}function xn(e,t){return wn(e,t,"months",12,"month")}function Cn(e,t){return wn(e,t,"monthsShort",12,"month")}function kn(e,t){return wn(e,t,"weekdays",7,"day")}function En(e,t){return wn(e,t,"weekdaysShort",7,"day")}function Sn(e,t){return wn(e,t,"weekdaysMin",7,"day")}function _n(){var e=this._data;return this._milliseconds=gi(this._milliseconds),this._days=gi(this._days),this._months=gi(this._months),e.milliseconds=gi(e.milliseconds),e.seconds=gi(e.seconds),e.minutes=gi(e.minutes),e.hours=gi(e.hours),e.months=gi(e.months),e.years=gi(e.years),this}function Mn(e,t,n,r){var i=Ze(t,n);return e._milliseconds+=r*i._milliseconds,e._days+=r*i._days,e._months+=r*i._months,e._bubble()}function Tn(e,t){return Mn(this,e,t,1)}function Dn(e,t){return Mn(this,e,t,-1)}function An(e){return 0>e?Math.floor(e):Math.ceil(e)}function On(){var e,t,n,r,i,o=this._milliseconds,a=this._days,s=this._months,l=this._data;return o>=0&&a>=0&&s>=0||0>=o&&0>=a&&0>=s||(o+=864e5*An(Rn(s)+a),a=0,s=0),l.milliseconds=o%1e3,e=m(o/1e3),l.seconds=e%60,t=m(e/60),l.minutes=t%60,n=m(t/60),l.hours=n%24,a+=m(n/24),i=m(Nn(a)),s+=i,a-=An(Rn(i)),r=m(s/12),s%=12,l.days=a,l.months=s,l.years=r,this}function Nn(e){return 4800*e/146097}function Rn(e){return 146097*e/4800}function In(e){var t,n,r=this._milliseconds;if("month"===(e=S(e))||"year"===e)return t=this._days+r/864e5,n=this._months+Nn(t),"month"===e?n:n/12;switch(t=this._days+Math.round(Rn(this._months)),e){case"week":return t/7+r/6048e5;case"day":return t+r/864e5;case"hour":return 24*t+r/36e5;case"minute":return 1440*t+r/6e4;case"second":return 86400*t+r/1e3;case"millisecond":return Math.floor(864e5*t)+r;default:throw new Error("Unknown unit "+e)}}function Pn(){return this._milliseconds+864e5*this._days+this._months%12*2592e6+31536e6*g(this._months/12)}function Fn(e){return function(){return this.as(e)}}function jn(e){return e=S(e),this[e+"s"]()}function Ln(e){return function(){return this._data[e]}}function Un(){return m(this.days()/7)}function Hn(e,t,n,r,i){return i.relativeTime(t||1,!!n,e,r)}function qn(e,t,n){var r=Ze(e).abs(),i=Oi(r.as("s")),o=Oi(r.as("m")),a=Oi(r.as("h")),s=Oi(r.as("d")),l=Oi(r.as("M")),u=Oi(r.as("y")),c=i=o&&["m"]||o=a&&["h"]||a=s&&["d"]||s=l&&["M"]||l=u&&["y"]||["yy",u];return c[2]=t,c[3]=+e>0,c[4]=n,Hn.apply(null,c)}function Vn(e,t){return void 0!==Ni[e]&&(void 0===t?Ni[e]:(Ni[e]=t,!0))}function zn(e){var t=this.localeData(),n=qn(this,!e,t);return e&&(n=t.pastFuture(+this,n)),t.postformat(n)}function Bn(){var e,t,n,r=Ri(this._milliseconds)/1e3,i=Ri(this._days),o=Ri(this._months);e=m(r/60),t=m(e/60),r%=60,e%=60,n=m(o/12),o%=12;var a=n,s=o,l=i,u=t,c=e,f=r,d=this.asSeconds();return d?(0>d?"-":"")+"P"+(a?a+"Y":"")+(s?s+"M":"")+(l?l+"D":"")+(u||c||f?"T":"")+(u?u+"H":"")+(c?c+"M":"")+(f?f+"S":""):"P0D"}var Yn,Wn,Gn=e.momentProperties=[],Kn=!1,Zn={},Jn={},Qn=/(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,Xn=/(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g,er={},tr={},nr=/\d/,rr=/\d\d/,ir=/\d{3}/,or=/\d{4}/,ar=/[+-]?\d{6}/,sr=/\d\d?/,lr=/\d\d\d\d?/,ur=/\d\d\d\d\d\d?/,cr=/\d{1,3}/,fr=/\d{1,4}/,dr=/[+-]?\d{1,6}/,pr=/\d+/,hr=/[+-]?\d+/,mr=/Z|[+-]\d\d:?\d\d/gi,gr=/Z|[+-]\d\d(?::?\d\d)?/gi,vr=/[+-]?\d+(\.\d{1,3})?/,yr=/[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i,br={},$r={},wr=0,xr=1,Cr=2,kr=3,Er=4,Sr=5,_r=6,Mr=7,Tr=8;R("M",["MM",2],"Mo",function(){return this.month()+1}),R("MMM",0,0,function(e){return this.localeData().monthsShort(this,e)}),R("MMMM",0,0,function(e){return this.localeData().months(this,e)}),E("month","M"),L("M",sr),L("MM",sr,rr),L("MMM",function(e,t){return t.monthsShortRegex(e)}),L("MMMM",function(e,t){return t.monthsRegex(e)}),V(["M","MM"],function(e,t){t[xr]=g(e)-1}),V(["MMM","MMMM"],function(e,t,n,r){var i=n._locale.monthsParse(e,r,n._strict);null!=i?t[xr]=i:l(n).invalidMonth=e});var Dr=/D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?/,Ar="January_February_March_April_May_June_July_August_September_October_November_December".split("_"),Or="Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),Nr=yr,Rr=yr,Ir={};e.suppressDeprecationWarnings=!1;var Pr=/^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/,Fr=/^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/,jr=/Z|[+-]\d\d(?::?\d\d)?/,Lr=[["YYYYYY-MM-DD",/[+-]\d{6}-\d\d-\d\d/],["YYYY-MM-DD",/\d{4}-\d\d-\d\d/],["GGGG-[W]WW-E",/\d{4}-W\d\d-\d/],["GGGG-[W]WW",/\d{4}-W\d\d/,!1],["YYYY-DDD",/\d{4}-\d{3}/],["YYYY-MM",/\d{4}-\d\d/,!1],["YYYYYYMMDD",/[+-]\d{10}/],["YYYYMMDD",/\d{8}/],["GGGG[W]WWE",/\d{4}W\d{3}/],["GGGG[W]WW",/\d{4}W\d{2}/,!1],["YYYYDDD",/\d{7}/]],Ur=[["HH:mm:ss.SSSS",/\d\d:\d\d:\d\d\.\d+/],["HH:mm:ss,SSSS",/\d\d:\d\d:\d\d,\d+/],["HH:mm:ss",/\d\d:\d\d:\d\d/],["HH:mm",/\d\d:\d\d/],["HHmmss.SSSS",/\d\d\d\d\d\d\.\d+/],["HHmmss,SSSS",/\d\d\d\d\d\d,\d+/],["HHmmss",/\d\d\d\d\d\d/],["HHmm",/\d\d\d\d/],["HH",/\d\d/]],Hr=/^\/?Date\((\-?\d+)/i;e.createFromInputFallback=ie("moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to https://github.com/moment/moment/issues/1407 for more info.",function(e){e._d=new Date(e._i+(e._useUTC?" UTC":""))}),R("Y",0,0,function(){var e=this.year();return 9999>=e?""+e:"+"+e}),R(0,["YY",2],0,function(){return this.year()%100}),R(0,["YYYY",4],0,"year"),R(0,["YYYYY",5],0,"year"),R(0,["YYYYYY",6,!0],0,"year"),E("year","y"),L("Y",hr),L("YY",sr,rr),L("YYYY",fr,or),L("YYYYY",dr,ar),L("YYYYYY",dr,ar),V(["YYYYY","YYYYYY"],wr),V("YYYY",function(t,n){n[wr]=2===t.length?e.parseTwoDigitYear(t):g(t)}),V("YY",function(t,n){n[wr]=e.parseTwoDigitYear(t)}),V("Y",function(e,t){t[wr]=parseInt(e,10)}),e.parseTwoDigitYear=function(e){return g(e)+(g(e)>68?1900:2e3)};var qr=T("FullYear",!1);e.ISO_8601=function(){};var Vr=ie("moment().min is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548",function(){var e=Te.apply(null,arguments);return this.isValid()&&e.isValid()?this>e?this:e:c()}),zr=ie("moment().max is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548",function(){var e=Te.apply(null,arguments);return this.isValid()&&e.isValid()?e>this?this:e:c()}),Br=function(){return Date.now?Date.now():+new Date};Ie("Z",":"),Ie("ZZ",""),L("Z",gr),L("ZZ",gr),V(["Z","ZZ"],function(e,t,n){n._useUTC=!0,n._tzm=Pe(gr,e)});var Yr=/([\+\-]|\d\d)/gi;e.updateOffset=function(){};var Wr=/(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/,Gr=/^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/;Ze.fn=Ne.prototype;var Kr=et(1,"add"),Zr=et(-1,"subtract");e.defaultFormat="YYYY-MM-DDTHH:mm:ssZ";var Jr=ie("moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.",function(e){return void 0===e?this.localeData():this.locale(e)});R(0,["gg",2],0,function(){return this.weekYear()%100}),R(0,["GG",2],0,function(){return this.isoWeekYear()%100}),Nt("gggg","weekYear"),Nt("ggggg","weekYear"),Nt("GGGG","isoWeekYear"),Nt("GGGGG","isoWeekYear"),E("weekYear","gg"),E("isoWeekYear","GG"),L("G",hr),L("g",hr),L("GG",sr,rr),L("gg",sr,rr),L("GGGG",fr,or),L("gggg",fr,or),L("GGGGG",dr,ar),L("ggggg",dr,ar),z(["gggg","ggggg","GGGG","GGGGG"],function(e,t,n,r){t[r.substr(0,2)]=g(e)}),z(["gg","GG"],function(t,n,r,i){n[i]=e.parseTwoDigitYear(t)}),R("Q",0,"Qo","quarter"),E("quarter","Q"),L("Q",nr),V("Q",function(e,t){t[xr]=3*(g(e)-1)}),R("w",["ww",2],"wo","week"),R("W",["WW",2],"Wo","isoWeek"),E("week","w"),E("isoWeek","W"),L("w",sr),L("ww",sr,rr),L("W",sr),L("WW",sr,rr),z(["w","ww","W","WW"],function(e,t,n,r){t[r.substr(0,1)]=g(e)});var Qr={dow:0,doy:6};R("D",["DD",2],"Do","date"),E("date","D"),L("D",sr),L("DD",sr,rr),L("Do",function(e,t){return e?t._ordinalParse:t._ordinalParseLenient}),V(["D","DD"],Cr),V("Do",function(e,t){t[Cr]=g(e.match(sr)[0],10)});var Xr=T("Date",!0);R("d",0,"do","day"),R("dd",0,0,function(e){return this.localeData().weekdaysMin(this,e)}),R("ddd",0,0,function(e){return this.localeData().weekdaysShort(this,e)}),R("dddd",0,0,function(e){return this.localeData().weekdays(this,e)}),R("e",0,0,"weekday"),R("E",0,0,"isoWeekday"),E("day","d"),E("weekday","e"),E("isoWeekday","E"),L("d",sr),L("e",sr),L("E",sr),L("dd",yr),L("ddd",yr),L("dddd",yr),z(["dd","ddd","dddd"],function(e,t,n,r){var i=n._locale.weekdaysParse(e,r,n._strict);null!=i?t.d=i:l(n).invalidWeekday=e}),z(["d","e","E"],function(e,t,n,r){t[r]=g(e)});var ei="Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),ti="Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),ni="Su_Mo_Tu_We_Th_Fr_Sa".split("_");R("DDD",["DDDD",3],"DDDo","dayOfYear"),E("dayOfYear","DDD"),L("DDD",cr),L("DDDD",ir),V(["DDD","DDDD"],function(e,t,n){n._dayOfYear=g(e)}),R("H",["HH",2],0,"hour"),R("h",["hh",2],0,tn),R("hmm",0,0,function(){return""+tn.apply(this)+N(this.minutes(),2)}),R("hmmss",0,0,function(){return""+tn.apply(this)+N(this.minutes(),2)+N(this.seconds(),2)}),R("Hmm",0,0,function(){return""+this.hours()+N(this.minutes(),2)}),R("Hmmss",0,0,function(){return""+this.hours()+N(this.minutes(),2)+N(this.seconds(),2)}),nn("a",!0),nn("A",!1),E("hour","h"),L("a",rn),L("A",rn),L("H",sr),L("h",sr),L("HH",sr,rr),L("hh",sr,rr),L("hmm",lr),L("hmmss",ur),L("Hmm",lr),L("Hmmss",ur),V(["H","HH"],kr),V(["a","A"],function(e,t,n){n._isPm=n._locale.isPM(e),n._meridiem=e}),V(["h","hh"],function(e,t,n){t[kr]=g(e),l(n).bigHour=!0}),V("hmm",function(e,t,n){var r=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r)),l(n).bigHour=!0}),V("hmmss",function(e,t,n){var r=e.length-4,i=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r,2)),t[Sr]=g(e.substr(i)),l(n).bigHour=!0}),V("Hmm",function(e,t,n){var r=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r))}),V("Hmmss",function(e,t,n){var r=e.length-4,i=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r,2)),t[Sr]=g(e.substr(i))});var ri=/[ap]\.?m?\.?/i,ii=T("Hours",!0);R("m",["mm",2],0,"minute"),E("minute","m"),L("m",sr),L("mm",sr,rr),V(["m","mm"],Er);var oi=T("Minutes",!1);R("s",["ss",2],0,"second"),E("second","s"),L("s",sr),L("ss",sr,rr),V(["s","ss"],Sr);var ai=T("Seconds",!1);R("S",0,0,function(){return~~(this.millisecond()/100)}),R(0,["SS",2],0,function(){return~~(this.millisecond()/10)}),R(0,["SSS",3],0,"millisecond"),R(0,["SSSS",4],0,function(){return 10*this.millisecond()}),R(0,["SSSSS",5],0,function(){return 100*this.millisecond()}),R(0,["SSSSSS",6],0,function(){return 1e3*this.millisecond()}),R(0,["SSSSSSS",7],0,function(){return 1e4*this.millisecond()}),R(0,["SSSSSSSS",8],0,function(){return 1e5*this.millisecond()}),R(0,["SSSSSSSSS",9],0,function(){return 1e6*this.millisecond()}),E("millisecond","ms"),L("S",cr,nr),L("SS",cr,rr),L("SSS",cr,ir);var si;for(si="SSSS";si.length<=9;si+="S")L(si,pr);for(si="S";si.length<=9;si+="S")V(si,sn);var li=T("Milliseconds",!1);R("z",0,0,"zoneAbbr"),R("zz",0,0,"zoneName");var ui=p.prototype;ui.add=Kr,ui.calendar=nt,ui.clone=rt,ui.diff=ct,ui.endOf=xt,ui.format=ht,ui.from=mt,ui.fromNow=gt,ui.to=vt,ui.toNow=yt,ui.get=O,ui.invalidAt=At,ui.isAfter=it,ui.isBefore=ot,ui.isBetween=at,ui.isSame=st,ui.isSameOrAfter=lt,ui.isSameOrBefore=ut,ui.isValid=Tt,ui.lang=Jr,ui.locale=bt,ui.localeData=$t,ui.max=zr,ui.min=Vr,ui.parsingFlags=Dt,ui.set=O,ui.startOf=wt,ui.subtract=Zr,ui.toArray=St,ui.toObject=_t,ui.toDate=Et,ui.toISOString=pt,ui.toJSON=Mt,ui.toString=dt,ui.unix=kt,ui.valueOf=Ct,ui.creationData=Ot,ui.year=qr,ui.isLeapYear=de,ui.weekYear=Rt,ui.isoWeekYear=It,ui.quarter=ui.quarters=Ut,ui.month=J,ui.daysInMonth=Q,ui.week=ui.weeks=zt,ui.isoWeek=ui.isoWeeks=Bt,ui.weeksInYear=Ft,ui.isoWeeksInYear=Pt,ui.date=Xr,ui.day=ui.days=Jt,ui.weekday=Qt,ui.isoWeekday=Xt,ui.dayOfYear=en,ui.hour=ui.hours=ii,ui.minute=ui.minutes=oi,ui.second=ui.seconds=ai,ui.millisecond=ui.milliseconds=li,ui.utcOffset=Le,ui.utc=He,ui.local=qe,ui.parseZone=Ve,ui.hasAlignedHourOffset=ze,ui.isDST=Be,ui.isDSTShifted=Ye,ui.isLocal=We,ui.isUtcOffset=Ge,ui.isUtc=Ke,ui.isUTC=Ke,ui.zoneAbbr=ln,ui.zoneName=un,ui.dates=ie("dates accessor is deprecated. Use date instead.",Xr),ui.months=ie("months accessor is deprecated. Use month instead",J),ui.years=ie("years accessor is deprecated. Use year instead",qr),ui.zone=ie("moment().zone is deprecated, use moment().utcOffset instead. https://github.com/moment/moment/issues/1779",Ue);var ci=ui,fi={sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"},di={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},pi=/\d{1,2}/,hi={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},mi=y.prototype;mi._calendar=fi,mi.calendar=dn,mi._longDateFormat=di,mi.longDateFormat=pn,mi._invalidDate="Invalid date",mi.invalidDate=hn,mi._ordinal="%d",mi.ordinal=mn,mi._ordinalParse=pi,mi.preparse=gn,mi.postformat=gn,mi._relativeTime=hi,mi.relativeTime=vn,mi.pastFuture=yn,mi.set=bn,mi.months=W,mi._months=Ar,mi.monthsShort=G,mi._monthsShort=Or,mi.monthsParse=K,mi._monthsRegex=Rr,mi.monthsRegex=ee,mi._monthsShortRegex=Nr,mi.monthsShortRegex=X,mi.week=Ht,mi._week=Qr,mi.firstDayOfYear=Vt,mi.firstDayOfWeek=qt,mi.weekdays=Wt,mi._weekdays=ei,mi.weekdaysMin=Kt,mi._weekdaysMin=ni,mi.weekdaysShort=Gt,mi._weekdaysShort=ti,mi.weekdaysParse=Zt,mi.isPM=on,mi._meridiemParse=ri,mi.meridiem=an,x("en",{ordinalParse:/\d{1,2}(th|st|nd|rd)/,ordinal:function(e){var t=e%10;return e+(1===g(e%100/10)?"th":1===t?"st":2===t?"nd":3===t?"rd":"th")}}),e.lang=ie("moment.lang is deprecated. Use moment.locale instead.",x),e.langData=ie("moment.langData is deprecated. Use moment.localeData instead.",k);var gi=Math.abs,vi=Fn("ms"),yi=Fn("s"),bi=Fn("m"),$i=Fn("h"),wi=Fn("d"),xi=Fn("w"),Ci=Fn("M"),ki=Fn("y"),Ei=Ln("milliseconds"),Si=Ln("seconds"),_i=Ln("minutes"),Mi=Ln("hours"),Ti=Ln("days"),Di=Ln("months"),Ai=Ln("years"),Oi=Math.round,Ni={s:45,m:45,h:22,d:26,M:11},Ri=Math.abs,Ii=Ne.prototype;return Ii.abs=_n,Ii.add=Tn,Ii.subtract=Dn,Ii.as=In,Ii.asMilliseconds=vi,Ii.asSeconds=yi,Ii.asMinutes=bi,Ii.asHours=$i,Ii.asDays=wi,Ii.asWeeks=xi,Ii.asMonths=Ci,Ii.asYears=ki,Ii.valueOf=Pn,Ii._bubble=On,Ii.get=jn,Ii.milliseconds=Ei,Ii.seconds=Si,Ii.minutes=_i,Ii.hours=Mi,Ii.days=Ti,Ii.weeks=Un,Ii.months=Di,Ii.years=Ai,Ii.humanize=zn,Ii.toISOString=Bn,Ii.toString=Bn,Ii.toJSON=Bn,Ii.locale=bt,Ii.localeData=$t,Ii.toIsoString=ie("toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)",Bn),Ii.lang=Jr,R("X",0,0,"unix"),R("x",0,0,"valueOf"),L("x",hr),L("X",vr),V("X",function(e,t,n){n._d=new Date(1e3*parseFloat(e,10))}),V("x",function(e,t,n){n._d=new Date(g(e))}),e.version="2.11.1",function(e){Yn=e}(Te),e.fn=ci,e.min=Ae,e.max=Oe,e.now=Br,e.utc=a,e.unix=cn,e.months=xn,e.isDate=n,e.locale=x,e.invalid=c,e.duration=Ze,e.isMoment=h,e.weekdays=kn,e.parseZone=fn,e.localeData=k,e.isDuration=Re,e.monthsShort=Cn,e.weekdaysMin=Sn,e.defineLocale=C,e.weekdaysShort=En,e.normalizeUnits=S,e.relativeTimeThreshold=Vn,e.prototype=ci,e}),define("common/bundles/vendors",["common/require","common/angular","common/angularAnimate","common/angularBootstrap","common/angular-file-upload","common/angularMocks","common/angularResource","common/angularRoute","common/angularXeditable","common/text-angular","common/ui-select","common/d3","common/lodash","common/moment"],function(){}),define("common/modules/apis",["common/angular"],function(e){"use strict";return e.module("common.apis",[])}),define("common/services/api",["common/angular","common/lodash","common/modules/apis"],function(e,t,n){"use strict";n.factory("api",["$log","$http","$httpParamSerializer","$q","$timeout",function(n,r,i,o,a){function s(e){return e.data.is_error?(n.error(e.data),o.reject(e.data.error_message)):e.data}function l(e){var n={options:{limit:0}};return JSON.stringify(t.merge(n,e||{}))}n.debug("api");return{extend:function(t){return e.extend(Object.create(this),t)},getAll:function(e,r,i,a,s,l,u){return n.debug("api.all"),r=r||{},l=l||"get",o.all([function(){var n=t.assign({},r,s||{},{options:t.assign({},r.options,{sort:a||"id DESC"})});return i&&(n.options.offset=(i.page-1)*i.size,n.options.limit=i.size),this.sendGET(e,l,n,u)}.bind(this)(),function(){if(!i)return o.resolve();var n=t.assign({},r,{return:"id"});return n=t.omit(n,function(e,n){return t.startsWith(n,"api.")}),this.sendGET(e,l,n,u)}.bind(this)()]).then(function(e){var n=e[0],r=i?e[1]:n;return{list:n.values,total:r.count,allIds:t.compact(r.values.map(function(e){return e.id})).join(",")}})},mockGET:function(e,t){var n=o.defer();return a(function(){n.resolve(e)},t||0),n.promise},mockPOST:function(e,t){return this.mockGET.apply(this,arguments)},sendGET:function(e,t,n,i){return r({method:"GET",url:"/civicrm/ajax/rest",cache:void 0===i||!!i,responseType:"json",params:{sequential:1,json:l(n),entity:e,action:t}}).then(s)},sendPOST:function(e,t,o){return n.debug("api.sendPOST"),r({method:"POST",url:"/civicrm/ajax/rest",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},responseType:"json",data:{json:l(o),sequential:1,entity:e,action:t},transformRequest:i}).then(s)}}}])}),define("common/services/api/appraisal",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.appraisal",["$log","api",function(e,t){return e.debug("api.appraisal"),t.extend({all:function(t,n,r){return e.debug("api.appraisal.api"),this.getAll("Appraisal",t,n,r)},create:function(t){return e.debug("api.appraisal.create"),this.sendPOST("Appraisal","create",t).then(function(e){return e.values[0]})},find:function(t){return e.debug("api.appraisal.find"),this.sendGET("Appraisal","get",{id:""+t},!1).then(function(e){return e.values[0]})}})}])}),define("common/services/api/option-group",["common/lodash","common/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("api.optionGroup",["$log","api",function(t,n){function r(t){return t.values.map(function(t){var n=e.clone(t);return n.option_group_name=n["option_group_id.name"],delete n["option_group_id.name"],n})}function i(t){return e.transform(t,function(e,t){var n=t.option_group_name;e[n]=e[n]||[],e[n].push(t)})}return t.debug("api.optionGroup"),n.extend({valuesOf:function(t,n){var o=e.isArray(t);return this.sendGET("OptionValue","get",e.assign({"option_group_id.name":{IN:o?t:[t]},is_active:"1",return:["option_group_id.name","option_group_id","id","name","label","value","weight","is_active","is_reserved"]},n)).then(r).then(function(e){return o?i(e):e})}})}])}),define("common/services/api/appraisal-cycle",["common/lodash","common/modules/apis","common/services/api","common/services/api/option-group"],function(e,t){"use strict";t.factory("api.appraisal-cycle",["$q","$log","api","api.optionGroup",function(t,n,r,i){return n.debug("api.appraisal-cycle"),r.extend({all:function(e,t,r){return n.debug("api.appraisal-cycle.all"),this.getAll("AppraisalCycle",e,t,r,{"api.AppraisalCycle.getappraisalsperstep":{}})},create:function(t){return n.debug("api.appraisal-cycle.create"),this.sendPOST("AppraisalCycle","create",e.assign(t,{"api.AppraisalCycle.getappraisalsperstep":{}})).then(function(e){return e.values[0]})},find:function(e){n.debug("api.appraisal-cycle.find");var t={id:""+e,"api.AppraisalCycle.getappraisalsperstep":{}};return this.sendGET("AppraisalCycle","get",t,!1).then(function(e){return e.values[0]})},grades:function(){return n.debug("grades"),this.mockGET([{label:1,value:17},{label:2,value:74},{label:3,value:90},{label:4,value:30}])},statuses:function(){return n.debug("api.appraisal-cycle.statuses"),i.valuesOf("appraisal_status")},statusOverview:function(e){return n.debug("api.appraisal-cycle.statusOverview"),this.sendGET("AppraisalCycle","getstatusoverview",e).then(function(e){return e.values})},update:function(t){return n.debug("api.appraisal-cycle.update"),this.sendPOST("AppraisalCycle","create",e.assign(t,{"api.AppraisalCycle.getappraisalsperstep":{}})).then(function(e){return e.values[0]})},total:function(e){return n.debug("api.appraisal-cycle.total"),this.sendGET("AppraisalCycle","getcount",e||{}).then(function(e){return e.result})},types:function(){return n.debug("api.appraisal-cycle.types"),i.valuesOf("appraisal_cycle_type")}})}])}),define("common/services/api/contact-job-role-api.api",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("ContactJobRoleAPI",["$log","api",function(e,t){return e.debug("ContactJobRoleAPI"),t.extend({all:function(t,n,r,i){return e.debug("ContactJobRoleAPI.all()"),this.getAll("ContactHrJobRoles",t,n,r,i)}})}])}),define("common/bundles/apis",["common/services/api/appraisal","common/services/api/appraisal-cycle","common/services/api/contact-job-role-api.api","common/services/api/option-group"],function(){}),define("common/modules/services",["common/angular","common/angular-file-upload"],function(e){"use strict";return e.module("common.services",["angularFileUpload"])}),define("common/services/before-hash-query-params.service",["common/lodash","common/modules/services"],function(e,t){"use strict";t.factory("beforeHashQueryParams",["$log","$window",function(t,n){function r(e){var t=e||n.location.href,r=o(t);return-1===r.indexOf("?")?{}:i(a(r))}function i(t){return t.length?e.transform(t,function(e,t){var n=t.split("=");n[0]&&(e[n[0]]=n[1]?decodeURI(n[1]):null)},{}):{}}function o(e){var t=e.indexOf("#");return e.substring(0,-1!==t?t:e.length)}function a(e){var t=e.indexOf("?");return e.substr(t+1).split("&")}return t.debug("Service: beforeHashQueryParams"),{parse:r}}])}),function(e){define("common/services/check-permissions",["common/lodash","common/modules/services"],function(t,n){"use strict";n.factory("checkPermissions",["$q",function(n){return function(r){return r=t.isArray(r)?r:[r],n.resolve(r.every(function(t){return e.checkPerm(t)}))}}])})}(CRM),define("common/services/detect-device.service",["common/modules/services"],function(e){"use strict";e.factory("detectDevice",[function(){return{isMobile:function(){return document.getElementsByTagName("body")[0].classList.contains("mobile")}}}])}),define("common/services/dom-event-trigger",["common/modules/services"],function(e){"use strict";!function(t){e.factory("DOMEventTrigger",function(){return function(e,n){t(document).trigger(e,n)}})}(CRM.$)}),define("common/services/file-mime-types",["common/lodash","common/modules/services"],function(e,t){"use strict";t.factory("fileMimeTypes",["$q",function(e){var t={txt:"plain",png:"png",jpeg:"jpeg",bmp:"bmp",gif:"gif",pdf:"pdf",doc:"msword",docx:"vnd.openxmlformats-officedocument.wordprocessingml.document",xls:"vnd.ms-excel",xlsx:"vnd.openxmlformats-officedocument.spreadsheetml.sheet",ppt:"vnd.ms-powerpoint",pptx:"vnd.openxmlformats-officedocument.presentationml.presentation"};return{getMimeTypeFor:function(n){return e.resolve(t[n])}}}])}),define("common/services/file-upload",["common/modules/services","common/lodash","common/angular-file-upload"],function(e,t){"use strict";e.factory("FileUpload",["$q","$log","FileUploader",function(e,n,r){function i(e){throw new Error(e+" missing from parameter")}function o(e,t,r,i){n.error(" ===== Item Error: "+r+" ======"),n.error(" ===== - item ======"),n.error(e),n.error(" ===== - response ======"),n.error(t),n.error(" ===== - headers ======"),n.error(i)}function a(e){return t.defaults(e,{allowedMimeTypes:{txt:"plain",png:"png",jpeg:"jpeg",bmp:"bmp",gif:"gif",pdf:"pdf"},url:"/civicrm/ajax/attachment",queueLimit:1})}return{uploader:function(n){var s,l,u,c=[];return n?(n=a(n),s=new r({url:n.url,queueLimit:+n.queueLimit,onCompleteItem:function(e,t){c.push(t)},onCompleteAll:function(){u.resolve(c)},onErrorItem:function(e){o.apply(null,arguments),u.reject("Could not upload file: "+e.file.name)},formData:[{entity_table:n.entityTable||i("entityTable"),crm_attachment_token:n.crmAttachmentToken||i("crmAttachmentToken")}],filters:[{name:"fileFormatFilter",fn:function(e){var r=e.type.slice(e.type.lastIndexOf("/")+1);return t.includes(t.values(n.allowedMimeTypes),r)}}]}),s.uploadAll=function(){return l=s.uploadAll,function(n){return u=e.defer(),s.onBeforeUploadItem=function(e){t.each(n,function(n,r){var i={};i[t.snakeCase(r)]=n,e.formData.push(i)})},l.apply(s),u.promise}}(),s):i("custom settings")}}}])}),define("common/services/file.service",["common/modules/services"],function(e){"use strict";e.factory("fileService",["$http","$window","$log",function(e,t,n){return n.debug("Service: fileService"),{openFile:function(n){return e.get(n.url,{responseType:"arraybuffer"}).success(function(e){var r=new Blob([e],{type:n.fileType});t.navigator.msSaveOrOpenBlob?t.navigator.msSaveOrOpenBlob(r,n.name):t.open(URL.createObjectURL(r),"_blank")})}}}])}),define("common/services/hr-settings",["common/modules/services"],function(e){"use strict";e.factory("HR_settings",function(){return{DATE_FORMAT:null}})}),function(e){define("common/services/notification.service",["common/lodash","common/modules/services"],function(t,n){"use strict";n.factory("notificationService",function(){return t(["alert","success","info","error"]).map(function(t){return[t,function(n,r,i){return e.alert(r,n,t,i)}]}).zipObject().value()})})}(CRM),define("common/services/pub-sub",["common/modules/services"],function(e){"use strict";var t=Object.create(null);e.factory("pubSub",["$rootScope",function(e){return{subscribe:function(n,r){var i;return t[n]=t[n]||[],r.$rootScope=e,i=t[n].push(r)-1,{remove:function(){delete t[n][i]}}},publish:function(e,n){t[e]&&(n=void 0!=n?n:{},t[e].forEach(function(e){e.$rootScope.$applyAsync(function(){e(n)})}))}}}])}),define("common/bundles/services",["common/services/before-hash-query-params.service","common/services/check-permissions","common/services/detect-device.service","common/services/dom-event-trigger","common/services/file-mime-types","common/services/file-upload","common/services/file.service","common/services/hr-settings","common/services/notification.service","common/services/pub-sub"],function(){}),define("common/modules/components",["common/angular"],function(e){return e.module("common.components",[])}),define("common/components/heatmap.component",["common/lodash","common/moment","common/modules/components"],function(e,t,n){function r(){function n(e){e.values&&(u(),l(),c())}function r(){return Object.values(d.values).filter(function(e){return!1!==e})}function i(e,t){return e.reduce(function(e,n){return Math.abs(n.value-t)');r(n,t),e.after(n)}function r(e,n){function r(){n.isOpen=!0,n.$apply()}t.isMobile()||(e.on("click",r),n.$on("$destroy",function(){e.off("click",r)}))}var i=e[0],o=i.compile;return i.compile=function(){var e=o.apply(this,arguments);return function(t,i,o){e.apply(this,arguments),n(i,t),r(i,t)}},e}]}),define("common/decorators/uib-datepicker-mobile-version.decorator",["common/moment","common/services/detect-device.service"],function(e){"use strict";return["$delegate","detectDevice",function(t,n){function r(t){return t?e(t).format("Y-MM-DD"):""}var i=t[0],o=i.compile;return i.require=["ngModel","uibDatepickerPopup"],i.compile=function(){var e=o.apply(this,arguments);return function(t,i,o,a){n.isMobile()?(i.prop("type","date"),o.ngReadonly=!1,a[0].$formatters.push(function(e){return r(e)}),t.$watch("datepickerOptions.minDate",function(e){o.$set("min",r(e))}),t.$watch("datepickerOptions.maxDate",function(e){o.$set("max",r(e))})):e.apply(this,arguments)}},t}]}),define("common/decorators/xeditable-disable-calendar-icon.decorator",[],function(){"use strict";return["$delegate",function(e){var t=e[0],n=t.compile;return t.compile=function(){var e=n.apply(this,arguments);return function(t,n,r){e.apply(this,arguments),r.eShowCalendarButton=!1}},e}]}),define("common/decorators/ui-bootstrap/uib-tabset",[],function(){"use strict";return["$delegate",function(e){return e[0].bindToController.customHeaderClass="@",e}]}),define("common/decorators/ui-bootstrap/uib-modal.decorator",["common/angular"],function(e){"use strict";return["$delegate","$document",function(t,n){function r(){var t,r=[{item:e.element(n[0].body),styles:[{name:"overflow",old:null,new:"hidden"},{name:"height",old:null,new:"100%"},{name:"width",old:null,new:"100%"}]},{item:e.element(n[0].getElementsByTagName("html")[0]),styles:[{name:"overflow",old:null,new:"hidden"},{name:"height",old:null,new:"100%"},{name:"width",old:null,new:"100%"}]}];return r.forEach(function(e){e.styles.forEach(function(t){t.old=e.item.css(t.name),e.item.css(t.name,t.new)})}),t=i.apply(this,arguments),t.closed.then(function(){r.forEach(function(e){e.styles.forEach(function(t){e.item.css(t.name,t.old)})})}),t}var i=t.open;return t.open=r,t}]}),define("common/modules/templates",["common/angular"],function(e){"use strict";return e.module("common.templates",[]).run(["$templateCache",function(e){e.put("dialog.html",'\n\n\n'),e.put("help-text.html",'\n'),e.put("loading.html",'
\n
\n
\n
\n'),e.put("time-amount-picker.html",'
\n
\n \n \n
\n h\n
\n \n \n
\n m\n
\n'),e.put("timepicker-select.html",'\n\n'),e.put("civihr-ui-select/choices.tpl.html",'
    \n
  • \n
    \n
      \n
    • \n
      \n
    • \n
    \n
  • \n
\n'),e.put("civihr-ui-select/match-multiple.tpl.html",'\n
  • \n \n \n
  • \n
    \n'),e.put("civihr-ui-select/match.tpl.html",'\n {{$select.contactList ? \'-select-\' : $select.placeholder}}\n \n \n \n\n'),e.put("civihr-ui-select/select-contacts-multiple.tpl.html",'
    \n
    \n
      \n \n
    • \n \n
    • \n
    \n\n \n\n \n
    \n
    \n'),e.put("civihr-ui-select/select-contacts.tpl.html",'
    \n
    \n \n
    \n'),e.put("civihr-ui-select/select-multiple.tpl.html",'
    \n
    \n
      \n \n
    • \n \n
    • \n
    \n \n
    \n
    \n'),e.put("civihr-ui-select/select.tpl.html",'
    \n
    \n \n
    \n'),e.put("components/heatmap.html",'
      \n
    • \n {{day.name.short}}\n
    • \n
    \n'),e.put("contact-actions/contact-actions.html",'
    \n \n \n
    \n'),e.put("contact-actions/modals/form.html",'
    \n \n \n \n
    \n')}])}),define("common/modules/controllers",["common/angular","common/angularBootstrap","common/modules/apis"],function(e){"use strict";return e.module("common.controllers",["ui.bootstrap","common.apis"])}),define("common/modules/directives",["common/angular","common/decorators/ui-select-focus.decorator","common/decorators/uib-datepicker-calendar-icon.decorator","common/decorators/uib-datepicker-mobile-version.decorator","common/decorators/xeditable-disable-calendar-icon.decorator","common/decorators/ui-bootstrap/uib-tabset","common/decorators/ui-bootstrap/uib-modal.decorator","common/angularBootstrap","common/angularXeditable","common/ui-select","common/modules/templates","common/modules/controllers","common/modules/services","common/modules/apis"],function(e,t,n,r,i,o,a){"use strict";return e.module("common.directives",["common.templates","common.controllers","ui.select","ui.bootstrap","xeditable"]).config(["$provide",function(e){e.decorator("uibDatepickerPopupDirective",r),e.decorator("uibDatepickerPopupDirective",n),e.decorator("uibTabsetDirective",o),e.decorator("$uibModal",a),e.decorator("editableBsdateDirective",i),e.decorator("uiSelectDirective",t)}]).run(["$templateCache",function(e){var t="uib/template/tabs/tabset.html",n=jQuery(e.get(t));n.find("ul").addClass("{{tabset.customHeaderClass}}"),e.put(t,n.wrap("
    ").parent().html())}])}),define("common/services/api/contact-actions",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.contactActions",["$q","api",function(e,t){function n(e,n){return t.sendGET(e,"getoptions",{field:n,context:"search"}).then(function(e){return e.values})}function r(e){return t.sendGET("UFField","get",{uf_group_id:e,is_active:!0}).then(function(e){return e.values})}function i(n,r){return e(function(e,i){if(r.contact_type=n,r.email)return t.sendGET("CustomField","get",{return:["id"],custom_group_id:"Emergency_Contacts",name:"email"}).then(function(t){r["custom_"+t.id]=r.email,delete r.email,e()});e()}).then(function(){return t.sendPOST("Contact","create",r).then(function(e){return e.values[0]})})}return t.extend({getOptions:{forContactType:function(){return n.call(this,"Contact","contact_type")},forGroup:function(){return n.call(this,"GroupContact","group_id")},forTag:function(){return n.call(this,"EntityTag","tag_id")},forStateProvince:function(){return n.call(this,"Address","state_province_id")},forCountry:function(){return n.call(this,"Address","country_id")},forGender:function(){return n.call(this,"Contact","gender_id")},forDeceased:function(){return n.call(this,"Contact","is_deceased")}},save:{newIndividual:function(e){return i.call(this,"Individual",e)},newOrganization:function(e){return i.call(this,"Organization",e)},newHousehold:function(e){return i.call(this,"Household",e)}},getFormFields:{forNewIndividual:function(){return r.call(this,"new_individual")},forNewOrganization:function(){return r.call(this,"new_organization")},forNewHousehold:function(){return r.call(this,"new_household")}}})}])}),define("common/controllers/contact-actions/modal-ctrl",[],function(){"use strict";return function(e,t){this.errorMsg="",this.loading=!0,this.formFields=[],this.init=function(e){e().then(function(e){this.loading=!1,this.formFields=e}.bind(this)).catch(function(){this.loading=!1,this.errorMsg="Error while loading form fields"}.bind(this))},this.cancel=function(){t.dismiss("cancel")},this.save=function(n,r){this.loading=!0,n(this.formFields.reduce(function(e,t){return e[t.field_name]=t.value,e},{})).then(function(n){this.loading=!1,e.$broadcast(r,n),t.dismiss("cancel")}.bind(this)).catch(function(){this.loading=!1,this.errorMsg="Error while saving data"}.bind(this))}}}),define("common/controllers/contact-actions/new-individual-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Individual",i.init(r.getFormFields.forNewIndividual),i.submit=function(){i.save(r.save.newIndividual,"newIndividualCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewIndividualModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/new-household-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Household",i.init(r.getFormFields.forNewHousehold),i.submit=function(){i.save(r.save.newHousehold,"newHouseholdCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewHouseholdModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/new-organization-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Organization",i.init(r.getFormFields.forNewOrganization),i.submit=function(){i.save(r.save.newOrganization,"newOrganizationCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewOrganizationModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/contact-actions-ctrl",["common/modules/controllers","common/services/api/contact-actions","common/controllers/contact-actions/new-individual-ctrl","common/controllers/contact-actions/new-household-ctrl","common/controllers/contact-actions/new-organization-ctrl"],function(e){"use strict";e.controller("ContactActionsCtrl",["$scope","$rootElement","$uibModal","api.contactActions",function(e,t,n,r){var i=this;e.$watch(function(){return i.refineSearch.selected},function(t,n){t!==n&&e.$emit("contactRefineSearch",{field:t.field?t.field.label:null,option:t.option?t.option.value:null})},!0),i.refineSearch={selected:{field:null,option:null},availableFields:[{label:"Contact Type",getOptions:r.getOptions.forContactType},{label:"Group",getOptions:r.getOptions.forGroup},{label:"Tag",getOptions:r.getOptions.forTag},{label:"State / Province",getOptions:r.getOptions.forStateProvince},{label:"Country",getOptions:r.getOptions.forCountry},{label:"Gender",getOptions:r.getOptions.forGender},{label:"Deceased",getOptions:r.getOptions.forDeceased}],availableOptions:{refresh:function(){i.refineSearch.selected.field?(this.options=null,i.refineSearch.selected.field.getOptions().then(function(e){this.options=e}.bind(this))):this.options=[]},options:[]}},i.showNewIndividualModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewIndividualModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})},i.showNewHouseholdModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewHouseholdModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})},i.showNewOrganizationModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewOrganizationModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})}}])}),define("common/directives/prevent-animations",["common/modules/directives"],function(e){"use strict";e.directive("preventAnimations",["$animate",function(e){return{restrict:"A",link:function(t,n,r){e.enabled(n,!1)}}}])}),define("common/directives/loading",["common/modules/directives","common/directives/prevent-animations"],function(e){"use strict";e.directive("crmLoading",["$templateCache",function(e){return{scope:{show:"="},restrict:"E",replace:!0,transclude:!0,template:e.get("loading.html")}}])}),define("common/directives/contact-actions/contact-actions",["common/modules/directives","common/controllers/contact-actions/contact-actions-ctrl","common/directives/loading"],function(e){"use strict";e.directive("contactActions",[function(){return{restrict:"E",templateUrl:"contact-actions/contact-actions.html",controller:"ContactActionsCtrl",controllerAs:"$ctrl",link:function(e,t,n){e.$ctrl.refineSearchVisible=t.parent().parent()[0].hasAttribute("refine-search")}}}])}),define("common/directives/help-text.directive",["common/lodash","common/moment","common/modules/directives","common/services/notification.service"],function(e,t,n){function r(e,t){function n(){var n=e.getHelpText();t.info(e.title||r,n)}var r="Help";this.displayHelpText=n}function i(e,t,n){function r(){return t.find(".help-text").html()}e.getHelpText=r}n.directive("helpText",["$templateCache",function(e){return{restrict:"E",scope:{title:"@?"},transclude:!0,controller:r,controllerAs:"helpText",template:e.get("help-text.html"),link:i}}]),r.$inject=["$scope","notificationService"]}),define("common/directives/scroll-shadows.directive",["common/angular","common/modules/directives"],function(e,t){"use strict";function n(t,n,r){function i(){u(),a(),l(),s()}function o(){var e=f.width(),t=p+"__shadows--show-left",n=p+"__shadows--show-right",r=d.scrollLeft(),i=d.width();if(e<=i)return void d.removeClass(t+" "+n);d[r>0?"addClass":"removeClass"](t),d[r
    ').parent(),d=f.wrap('
    ').parent(),d.wrap('
    ')}var f,d,p="chr_scroll-shadows";!function(){c(),i(),o()}()}t.directive("scrollShadows",[function(){return{restrict:"A",controller:n}}]),n.$inject=["$element","$scope","$window"]}),define("common/directives/timepicker-select.directive",["common/moment","common/modules/directives"],function(e,t){"use strict";function n(t){function n(){var n=+t.timepickerSelectInterval||1,i=e.duration(t.timepickerSelectTimeFrom||"00:00"),o=e.duration(t.timepickerSelectTimeTo||"23:59");for(r.options=[];i.asMinutes()<=o.asMinutes();){var a=e.utc(i.asMilliseconds());r.options.push(a.format("HH:mm")),i.add(n,"minutes")}}var r=this;r.placeholder=t.timepickerSelectPlaceholder,r.options=[],t.$watchGroup(["timepickerSelectTimeFrom","timepickerSelectTimeTo","timepickerSelectInterval"],function(){n()})}t.directive("timepickerSelect",["$templateCache",function(e){return{scope:{timepickerSelectPlaceholder:"@",timepickerSelectTimeFrom:"<",timepickerSelectTimeTo:"<",timepickerSelectInterval:"<"},restrict:"A",controllerAs:"selector",controller:["$scope",n],template:e.get("timepicker-select.html")}}]),n.$inject=["$scope"]}),define("common/directives/time-amount-picker.directive",["common/lodash","common/modules/directives"],function(e,t){"use strict";function n(t){function n(){var e=Math.floor(c);for(d.hoursOptions=[];e<=f;)d.hoursOptions.push(e),e++}function r(){var e,t,n,r=0;for(d.minutesOptions=[];r<60;)t=+d.selectedHours===Math.floor(c)&&rf%1*60,e=t||n,!e&&d.minutesOptions.push(r),r+=u;l()}function i(){u=+t.interval||1,c=isNaN(+t.minAmount)?0:+t.minAmount,f=isNaN(+t.maxAmount)?24:+t.maxAmount,n(),r()}function o(){""!==d.selectedHours&&""!==d.selectedMinutes&&(t.value=+d.selectedHours+d.selectedMinutes/60)}function a(){t.$watch("disabled",function(e){d.disabled=e}),t.$watch("value",function(){s()}),t.$watchGroup(["minAmount","maxAmount","interval"],function(){i()})}function s(){void 0!==t.value&&(d.selectedHours=""+Math.floor(t.value),d.selectedMinutes=""+Math.floor(t.value%1*60)),o()}function l(){d.selectedMinutese.last(d.minutesOptions)&&(d.selectedMinutes=""+e.last(d.minutesOptions))}var u,c,f,d=this;d.hoursOptions=[],d.minutesOptions=[],d.selectedHours="",d.selectedMinutes="",d.buildMinutesOptions=r,d.calculateSelectedValue=o,function(){s(),a()}()}t.directive("timeAmountPicker",["$templateCache",function(e){return{scope:{minAmount:".75?Math.floor(.25*Math.ceil(e/.25))+"h":"",n=e%1&&e%1<=.75&&e%1>0?.25*Math.ceil(e%1/.25)*60+"m":"",r+t+(t&&n?" ":"")+n)}};return function(t,n){var r=void 0===t?0:parseFloat(t);if(isNaN(r))throw new Error("Value must be a number or a numeric string: "+t);return e[n](r)}})}),define("common/bundles/filters",["common/filters/time-unit-applier.filter"],function(){}),define("common/decorators/angular-date/datepicker-popup",["common/lodash"],function(e){return["$delegate","HR_settings",function(t,n){"use strict";var r=t[0].link;return t[0].compile=function(){return function(t,i,o,a){o.uibDatepickerPopup=o.uibDatepickerPopup||n.DATE_FORMAT||"yyyy-MM-dd",o.showButtonBar=o.showButtonBar||!1,t.datepickerOptions=e.assign({formatDayHeader:"E",showWeeks:!1,startingDay:1},t.datepickerOptions),r.apply(this,arguments)}},t}]}),define("common/decorators/angular-date/date-filter",[],function(){"use strict";return["$delegate",function(e){var t=e;return function(){if("E"===arguments[1]){var e=Array.prototype.slice.call(arguments);return e[1]="EEE",t.apply(this,e)[0]}return t.apply(this,arguments)}}]}), -function(e){define("common/modules/angular-date",["common/angular","common/decorators/angular-date/datepicker-popup","common/decorators/angular-date/date-filter","common/modules/services","common/angularBootstrap","common/modules/templates"],function(t,n,r){"use strict";function i(t){var n="uib/template/datepicker/"+t+".html",r=o.get(n);r=r.replace(/glyphicon glyphicon-chevron-(left|right)/gm,"fa fa-chevron-$1"),"day"===t&&(r=function(t){return e(t).find('th[ng-if="showWeeks"]').parent().css({"border-top":"1px solid #DDD"}),e(t).prop("outerHTML")}(e.parseHTML(r))),o.put(n,r)}var o;return t.module("common.angularDate",["common.services","ui.bootstrap","common.templates"]).config(["$provide",function(e){e.decorator("uibDatepickerPopupDirective",n),e.decorator("dateFilter",r)}]).run(["$templateCache",function(e){o=e,["day","month","year"].forEach(i)}])})}(CRM.$),define("common/services/angular-date/date-format",["common/angular","common/modules/angular-date","common/services/hr-settings"],function(e,t){"use strict";t.factory("DateFormat",["$q","HR_settings",function(e,t){return{dateFormat:null,getDateFormat:function(){return this.dateFormat?e.when(this.dateFormat):e.when("dd/MM/yyyy").catch(function(){return"yyyy-MM-dd"}).then(function(e){return t.DATE_FORMAT=e,this.dateFormat=e,e}.bind(this))}}}])}),define("common/filters/angular-date/format-date",["common/moment","common/modules/angular-date","common/services/hr-settings"],function(e,t){"use strict";t.filter("formatDate",["HR_settings",function(t){var n=["DD-MM-YYYY","DD-MM-YYYY HH:mm:ss","YYYY-MM-DD","YYYY-MM-DD HH:mm:ss","DD/MM/YYYY","x","YYYY-MM-DD HH:mm:ss"];return function(r,i,o){var a,s=i||t.DATE_FORMAT||"YYYY-MM-DD",l=e(0);return r instanceof Date&&(r=e(r).format("YYYY-MM-DD HH:mm:ss")),a=e(r,n,!0),a.isValid()&&!a.isSame(l)?i===Date?a.toDate():a.format(s.toUpperCase())+("hours"===o?" "+a.format("HH:mm"):""):"Unspecified"}}])}),define("common/directives/angular-date/date-input",["common/modules/angular-date","common/filters/angular-date/format-date"],function(e){"use strict";e.directive("dateInput",["$filter",function(e){return{require:"ngModel",link:function(t,n,r,i){function o(t){var n=e("formatDate")(t);return n="Unspecified"==n?"":n}i.$formatters.push(o),i.$parsers=[]}}}])}),define("common/bundles/angular-date",["common/services/angular-date/date-format","common/filters/angular-date/format-date","common/directives/angular-date/date-input"],function(){}),define("common/modules/routers/compu-ng-route",["common/angular","common/angularRoute"],function(e){"use strict";return e.module("compuNgRoute",["ngRoute"]).config(["$routeProvider",function(t){var n=t.when;t.resolveForAll=function(e){return t.commonResolve=e,t},t.when=function(r,i){return e.extend(i.resolve||{},t.commonResolve||{}),n.call(t,r,i)}}])}),"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function r(e,t){return L(new(L(function(){},{prototype:e})),t)}function i(e){return j(arguments,function(t){t!==e&&j(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var r in e.path){if(e.path[r]!==t.path[r])break;n.push(e.path[r])}return n}function a(e){if(Object.keys)return Object.keys(e);var t=[];return j(e,function(e,n){t.push(n)}),t}function s(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,r=Number(arguments[2])||0;for(0>(r=0>r?Math.ceil(r):Math.floor(r))&&(r+=n);n>r;r++)if(r in e&&e[r]===t)return r;return-1}function l(e,t,n,r){var i,l=o(n,r),u={},c=[];for(var f in l)if(l[f].params&&(i=a(l[f].params),i.length))for(var d in i)s(c,i[d])>=0||(c.push(i[d]),u[i[d]]=e[i[d]]);return L({},u,t)}function u(e,t,n){if(!n){n=[];for(var r in e)n.push(r)}for(var i=0;i "));if(y[n]=r,I(e))g.push(n,[function(){return t.get(e)}],u);else{var i=t.annotate(e);j(i,function(e){e!==n&&l.hasOwnProperty(e)&&p(l[e],e)}),g.push(n,e,i)}v.pop(),y[n]=o}}function h(e){return P(e)&&e.then&&e.$$promises}if(!P(l))throw new Error("'invocables' must be an object");var m=a(l||{}),g=[],v=[],y={};return j(l,p),l=v=y=null,function(r,o,a){function s(){--b||($||i(y,o.$$values),p.$$values=y,p.$$promises=p.$$promises||!0,delete p.$$inheritedValues,u.resolve(y))}function l(e){p.$$failure=e,u.reject(e)}if(h(r)&&a===n&&(a=o,o=r,r=null),r){if(!P(r))throw new Error("'locals' must be an object")}else r=c;if(o){if(!h(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=f;var u=e.defer(),p=u.promise,v=p.$$promises={},y=L({},r),b=1+g.length/3,$=!1;if(N(o.$$failure))return l(o.$$failure),p;o.$$inheritedValues&&i(y,d(o.$$inheritedValues,m)),L(v,o.$$promises),o.$$values?($=i(y,d(o.$$values,m)),p.$$inheritedValues=d(o.$$values,m),s()):(o.$$inheritedValues&&(p.$$inheritedValues=d(o.$$inheritedValues,m)),o.then(s,l));for(var w=0,x=g.length;x>w;w+=3)r.hasOwnProperty(g[w])?s():function(n,i,o){function u(e){f.reject(e),l(e)}function c(){if(!N(p.$$failure))try{f.resolve(t.invoke(i,a,y)),f.promise.then(function(e){y[n]=e,s()},u)}catch(e){u(e)}}var f=e.defer(),d=0;j(o,function(e){v.hasOwnProperty(e)&&!r.hasOwnProperty(e)&&(d++,v[e].then(function(t){y[e]=t,--d||c()},u))}),d||c(),v[n]=f.promise}(g[w],g[w+1],g[w+2]);return p}},this.resolve=function(e,t,n,r){return this.study(e)(t,n,r)}}function g(e,t,n){this.fromConfig=function(e,t,n){return N(e.template)?this.fromString(e.template,t):N(e.templateUrl)?this.fromUrl(e.templateUrl,t):N(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return R(e)?e(t):e},this.fromUrl=function(n,r){return R(n)&&(n=n(r)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,r){return n.invoke(e,null,r||{params:t})}}function v(e,t,i){function o(t,n,r,i){if(g.push(t),h[t])return h[t];if(!/^\w+(-+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(m[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return m[t]=new H.Param(t,n,r,i),m[t]}function a(e,t,n,r){var i=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:i=["(",")"+(r?"?":"")];break;case!0:i=["?(",")?"];break;default:i=["("+n+"|",")?"]}return o+i[0]+t+i[1]}function s(i,o){var a,s,l,u,c;return a=i[2]||i[3],c=t.params[a],l=e.substring(d,i.index),s=o?i[4]:i[4]||("*"==i[1]?".*":null),u=H.type(s||"string")||r(H.type("string"),{pattern:new RegExp(s,t.caseInsensitive?"i":n)}),{id:a,regexp:s,segment:l,type:u,cfg:c}}t=L({params:{}},P(t)?t:{});var l,u=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,c=/([:]?)([\w\[\]-]+)|\{([\w\[\]-]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,f="^",d=0,p=this.segments=[],h=i?i.params:{},m=this.params=i?i.params.$$new():new H.ParamSet,g=[];this.source=e;for(var v,y,b;(l=u.exec(e))&&(v=s(l,!1),!(v.segment.indexOf("?")>=0));)y=o(v.id,v.type,v.cfg,"path"),f+=a(v.segment,y.type.pattern.source,y.squash,y.isOptional),p.push(v.segment),d=u.lastIndex;b=e.substring(d);var $=b.indexOf("?");if($>=0){var w=this.sourceSearch=b.substring($);if(b=b.substring(0,$),this.sourcePath=e.substring(0,d+$),w.length>0)for(d=0;l=c.exec(w);)v=s(l,!0),y=o(v.id,v.type,v.cfg,"search"),d=u.lastIndex}else this.sourcePath=e,this.sourceSearch="";f+=a(b)+(!1===t.strict?"/?":"")+"$",p.push(b),this.regexp=new RegExp(f,t.caseInsensitive?"i":n),this.prefix=p[0],this.$$paramNames=g}function y(e){L(this,e)}function b(){function e(e){return null!=e?e.toString().replace(/\//g,"%2F"):e}function i(e){return null!=e?e.toString().replace(/%2F/g,"/"):e}function o(){return{strict:m,caseInsensitive:d}}function l(e){return R(e)||F(e)&&R(e[e.length-1])}function u(){for(;x.length;){var e=x.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend($[e.name],f.invoke(e.def))}}function c(e){L(this,e||{})}H=this;var f,d=!1,m=!0,g=!1,$={},w=!0,x=[],C={string:{encode:e,decode:i,is:function(e){return null==e||!N(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return N(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};b.$$getDefaultValue=function(e){if(!l(e.value))return e.value;if(!f)throw new Error("Injectable functions cannot be called at configuration time");return f.invoke(e.value)},this.caseInsensitive=function(e){return N(e)&&(d=e),d},this.strictMode=function(e){return N(e)&&(m=e),m},this.defaultSquashPolicy=function(e){if(!N(e))return g;if(!0!==e&&!1!==e&&!I(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return g=e,e},this.compile=function(e,t){return new v(e,L(o(),t))},this.isMatcher=function(e){if(!P(e))return!1;var t=!0;return j(v.prototype,function(n,r){R(n)&&(t=t&&N(e[r])&&R(e[r]))}),t},this.type=function(e,t,n){if(!N(t))return $[e];if($.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return $[e]=new y(L({name:e},t)),n&&(x.push({name:e,def:n}),w||u()),this},j(C,function(e,t){$[t]=new y(L({name:t},e))}),$=r($,{}),this.$get=["$injector",function(e){return f=e,w=!1,u(),j(C,function(e,t){$[t]||($[t]=new y(e))}),this}],this.Param=function(e,t,r,i){function o(){if(!f)throw new Error("Injectable functions cannot be called at configuration time");var e=f.invoke(r.$$fn);if(null!==e&&e!==n&&!d.type.is(e))throw new Error("Default value ("+e+") for parameter '"+d.id+"' is not an instance of Type ("+d.type.name+")");return e}function u(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=h(p(d.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),N(e)?d.type.$normalize(e):o()}function c(){return"{Param:"+e+" "+t+" squash: '"+b+"' optional: "+v+"}"}var d=this;r=function(e){var t=P(e)?a(e):[];return-1===s(t,"value")&&-1===s(t,"type")&&-1===s(t,"squash")&&-1===s(t,"array")&&(e={value:e}),e.$$fn=l(e.value)?e.value:function(){return e.value},e}(r),t=function(t,n,r){if(t.type&&n)throw new Error("Param '"+e+"' has two type configurations.");return n||(t.type?t.type instanceof y?t.type:new y(t.type):"config"===r?$.any:$.string)}(r,t,i);var m=function(){var t={array:"search"===i&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return L(t,n,r).array}();t=m?t.$asArray(m,"search"===i):t,"string"!==t.name||m||"path"!==i||r.value!==n||(r.value="");var v=r.value!==n,b=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!N(n)||null==n)return g;if(!0===n||I(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,v),w=function(e,t,r,i){var o,a,l=[{from:"",to:r||t?n:""},{from:null,to:r||t?n:""}];return o=F(e.replace)?e.replace:[],I(i)&&o.push({from:i,to:n}),a=h(o,function(e){return e.from}),p(l,function(e){return-1===s(a,e.from)}).concat(o)}(r,m,v,b);L(this,{id:e,type:t,location:i,array:m,squash:b,replace:w,isOptional:v,value:u,dynamic:n,config:r,toString:c})},c.prototype={$$new:function(){return r(this,L(new c,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,r=a(c.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),j(t,function(t){j(a(t),function(t){-1===s(e,t)&&-1===s(r,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return j(n.$$keys(),function(r){t[r]=n[r].value(e&&e[r])}),t},$$equals:function(e,t){var n=!0,r=this;return j(r.$$keys(),function(i){var o=e&&e[i],a=t&&t[i];r[i].type.equals(o,a)||(n=!1)}),n},$$validates:function(e){var r,i,o,a,s,l=this.$$keys();for(r=0;ri;i++)if(t(u[i]))return;c&&t(c)}}function p(){return l=l||i.$on("$locationChangeSuccess",d)}var h,m=a.baseHref(),g=r.url();return f||p(),{sync:function(){d()},listen:function(){return p()},update:function(e){return e?void(g=r.url()):void(r.url()!==g&&(r.url(g),r.replace()))},push:function(e,t,i){var o=e.format(t||{});null!==o&&t&&t["#"]&&(o+="#"+t["#"]),r.url(o),h=i&&i.$$avoidResync?r.url():n,i&&i.replace&&r.replace()},href:function(n,i,o){if(!n.validates(i))return null;var a=e.html5Mode();t.isObject(a)&&(a=a.enabled);var l=n.format(i);if(o=o||{},a||null===l||(l="#"+e.hashPrefix()+l),null!==l&&i&&i["#"]&&(l+="#"+i["#"]),l=s(l,a,o.absolute),!o.absolute||!l)return l;var u=!a&&l?"/":"",c=r.port();return c=80===c||443===c?"":":"+c,[r.protocol(),"://",r.host(),c,u,l].join("")}}}var l,u=[],c=null,f=!1;this.rule=function(e){if(!R(e))throw new Error("'rule' must be a function");return u.push(e),this},this.otherwise=function(e){if(I(e)){var t=e;e=function(){return t}}else if(!R(e))throw new Error("'rule' must be a function");return c=e,this},this.when=function(e,t){var n,s=I(t);if(I(e)&&(e=r.compile(e)),!s&&!R(t)&&!F(t))throw new Error("invalid 'handler' in when()");var l={matcher:function(e,t){return s&&(n=r.compile(t),t=["$match",function(e){return n.format(e)}]),L(function(n,r){return a(n,t,e.exec(r.path(),r.search()))},{prefix:I(e.prefix)?e.prefix:""})},regex:function(e,t){if(e.global||e.sticky)throw new Error("when() RegExp must not be global or sticky");return s&&(n=t,t=["$match",function(e){return o(n,e)}]),L(function(n,r){return a(n,t,e.exec(r.path()))},{prefix:i(e)})}},u={matcher:r.isMatcher(e),regex:e instanceof RegExp};for(var c in u)if(u[c])return this.rule(l[c](e,t));throw new Error("invalid 'what' in when()")},this.deferIntercept=function(e){e===n&&(e=!0),f=e},this.$get=s,s.$inject=["$location","$rootScope","$injector","$browser"]}function w(e,i){function o(e){return 0===e.indexOf(".")||0===e.indexOf("^")}function d(e,t){if(!e)return n;var r=I(e),i=r?e:e.name;if(o(i)){if(!t)throw new Error("No reference point given for path '"+i+"'");t=d(t);for(var a=i.split("."),s=0,l=a.length,u=t;l>s;s++)if(""!==a[s]||0!==s){if("^"!==a[s])break;if(!u.parent)throw new Error("Path '"+i+"' not valid for state '"+t.name+"'");u=u.parent}else u=t;a=a.slice(s).join("."),i=u.name+(u.name&&a?".":"")+a}var c=E[i];return!c||!r&&(r||c!==e&&c.self!==e)?n:c}function p(e,t){S[e]||(S[e]=[]),S[e].push(t)}function m(e){for(var t=S[e]||[];t.length;)g(t.shift())}function g(t){t=r(t,{self:t,resolve:t.resolve||{},toString:function(){return this.name}});var n=t.name;if(!I(n)||n.indexOf("@")>=0)throw new Error("State must have a valid name");if(E.hasOwnProperty(n))throw new Error("State '"+n+"'' is already defined");var i=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):I(t.parent)?t.parent:P(t.parent)&&I(t.parent.name)?t.parent.name:"";if(i&&!E[i])return p(i,t.self);for(var o in M)R(M[o])&&(t[o]=M[o](t,M.$delegates[o]));return E[n]=t,!t[_]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){k.$current.navigable==t&&u(e,n)||k.transitionTo(t,e,{inherit:!0,location:!1})}]),m(n),t}function v(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=k.$current.name.split("."),r=0,i=t.length;i>r;r++)"*"===t[r]&&(n[r]="*");return"**"===t[0]&&(n=n.slice(s(n,t[1])),n.unshift("**")),"**"===t[t.length-1]&&(n.splice(s(n,t[t.length-2])+1,Number.MAX_VALUE),n.push("**")),t.length==n.length&&n.join("")===t.join("")}function b(e,t){return I(e)&&!N(t)?M[e]:R(t)&&I(e)?(M[e]&&!M.$delegates[e]&&(M.$delegates[e]=M[e]),M[e]=t,this):this}function $(e,t){return P(e)?t=e:t.name=e,g(t),this}function w(e,i,o,s,f,p,m,g,b){function $(t,n,r,o){var a=e.$broadcast("$stateNotFound",t,n,r);if(a.defaultPrevented)return m.update(),T;if(!a.retry)return null;if(o.$retry)return m.update(),D;var s=k.transition=i.when(a.retry);return s.then(function(){return s!==k.transition?S:(t.options.$retry=!0,k.transitionTo(t.to,t.toParams,t.options))},function(){return T}),m.update(),s}function w(e,n,r,a,l,u){function d(){var n=[];return j(e.views,function(r,i){var a=r.resolve&&r.resolve!==e.resolve?r.resolve:{};a.$template=[function(){return o.load(i,{view:r,locals:l.globals,params:p,notify:u.notify})||""}],n.push(f.resolve(a,l.globals,l.resolve,e).then(function(n){if(R(r.controllerProvider)||F(r.controllerProvider)){var o=t.extend({},a,l.globals);n.$$controller=s.invoke(r.controllerProvider,null,o)}else n.$$controller=r.controller;n.$$state=e,n.$$controllerAs=r.controllerAs,l[i]=n}))}),i.all(n).then(function(){return l.globals})}var p=r?n:c(e.params.$$keys(),n),h={$stateParams:p};l.resolve=f.resolve(e.resolve,h,l.resolve,e);var m=[l.resolve.then(function(e){l.globals=e})];return a&&m.push(a),i.all(m).then(d).then(function(e){return l})}var S=i.reject(new Error("transition superseded")),M=i.reject(new Error("transition prevented")),T=i.reject(new Error("transition aborted")),D=i.reject(new Error("transition failed"));return C.locals={resolve:null,globals:{$stateParams:{}}},k={params:{},current:C.self,$current:C,transition:null},k.reload=function(e){return k.transitionTo(k.current,p,{reload:e||!0,inherit:!1,notify:!0})},k.go=function(e,t,n){return k.transitionTo(e,t,L({inherit:!0,relative:k.$current},n))},k.transitionTo=function(t,n,o){n=n||{},o=L({location:!0,inherit:!1,relative:null,notify:!0,reload:!1,$retry:!1},o||{});var a,u=k.$current,f=k.params,h=u.path,g=d(t,o.relative),v=n["#"];if(!N(g)){var y={to:t,toParams:n,options:o},b=$(y,u.self,f,o);if(b)return b;if(t=y.to,n=y.toParams,o=y.options,g=d(t,o.relative),!N(g)){if(!o.relative)throw new Error("No such state '"+t+"'");throw new Error("Could not resolve '"+t+"' from state '"+o.relative+"'")}}if(g[_])throw new Error("Cannot transition to abstract state '"+t+"'");if(o.inherit&&(n=l(p,n||{},k.$current,g)),!g.params.$$validates(n))return D;n=g.params.$$values(n),t=g;var E=t.path,T=0,A=E[T],O=C.locals,R=[];if(o.reload){if(I(o.reload)||P(o.reload)){if(P(o.reload)&&!o.reload.name)throw new Error("Invalid reload state object");var F=!0===o.reload?h[0]:d(o.reload);if(o.reload&&!F)throw new Error("No such reload state '"+(I(o.reload)?o.reload:o.reload.name)+"'");for(;A&&A===h[T]&&A!==F;)O=R[T]=A.locals,T++,A=E[T]}}else for(;A&&A===h[T]&&A.ownParams.$$equals(n,f);)O=R[T]=A.locals,T++,A=E[T];if(x(t,n,u,f,O,o))return v&&(n["#"]=v),k.params=n,U(k.params,p),o.location&&t.navigable&&t.navigable.url&&(m.push(t.navigable.url,n,{$$avoidResync:!0,replace:"replace"===o.location}),m.update(!0)),k.transition=null,i.when(k.current);if(n=c(t.params.$$keys(),n||{}),o.notify&&e.$broadcast("$stateChangeStart",t.self,n,u.self,f).defaultPrevented)return e.$broadcast("$stateChangeCancel",t.self,n,u.self,f),m.update(),M;for(var j=i.when(O),H=T;H=T;r--)a=h[r],a.self.onExit&&s.invoke(a.self.onExit,a.self,a.locals.globals),a.locals=null;for(r=T;r=0?i:i+"@"+(o?o.state.name:"")}function _(e,t){var n,r=e.match(/^\s*({[^}]*})\s*$/);if(r&&(e=t+"("+r[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function M(e){var t=e.parent().inheritedData("$uiView");return t&&t.state&&t.state.name?t.state:void 0}function T(e,n){var r=["location","inherit","reload","absolute"];return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(i,o,a,s){var l=_(a.uiSref,e.current.name),u=null,c=M(o)||e.$current,f="[object SVGAnimatedString]"===Object.prototype.toString.call(o.prop("href"))?"xlink:href":"href",d=null,p="A"===o.prop("tagName").toUpperCase(),h="FORM"===o[0].nodeName,m=h?"action":f,g=!0,v={relative:c,inherit:!0},y=i.$eval(a.uiSrefOpts)||{};t.forEach(r,function(e){e in y&&(v[e]=y[e])});var b=function(n){if(n&&(u=t.copy(n)),g){d=e.href(l.state,u,v);var r=s[1]||s[0];return r&&r.$$addStateInfo(l.state,u),null===d?(g=!1,!1):void a.$set(m,d)}};l.paramExpr&&(i.$watch(l.paramExpr,function(e,t){e!==u&&b(e)},!0),u=t.copy(i.$eval(l.paramExpr))),b(),h||o.bind("click",function(t){if(!((t.which||t.button)>1||t.ctrlKey||t.metaKey||t.shiftKey||o.attr("target"))){var r=n(function(){e.go(l.state,u,v)});t.preventDefault();var i=p&&!d?1:0;t.preventDefault=function(){i--<=0&&n.cancel(r)}}})}}}function D(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs",function(t,r,i){function o(){a()?r.addClass(l):r.removeClass(l)}function a(){for(var e=0;er;r++){o=a[r];var c=this.params[o],f=n[r+1];for(i=0;ir;r++)o=a[r],u[o]=this.params[o].value(t[o]);return u},v.prototype.parameters=function(e){return N(e)?this.params[e]||null:this.$$paramNames},v.prototype.validates=function(e){return this.params.$$validates(e)},v.prototype.format=function(e){function t(e){return encodeURIComponent(e).replace(/-/g,function(e){return"%5C%"+e.charCodeAt(0).toString(16).toUpperCase()})}e=e||{};var n=this.segments,r=this.parameters(),i=this.params;if(!this.validates(e))return null;var o,a=!1,s=n.length-1,l=r.length,u=n[0];for(o=0;l>o;o++){var c=s>o,f=r[o],d=i[f],p=d.value(e[f]),m=d.isOptional&&d.type.equals(d.value(),p),g=!!m&&d.squash,v=d.type.encode(p);if(c){var y=n[o+1];if(!1===g)null!=v&&(u+=F(v)?h(v,t).join("-"):encodeURIComponent(v)),u+=y;else if(!0===g){var b=u.match(/\/$/)?/\/?(.*)/:/(.*)/;u+=y.match(b)[1]}else I(g)&&(u+=g+y)}else{if(null==v||m&&!1!==g)continue;F(v)||(v=[v]),v=h(v,encodeURIComponent).join("&"+f+"="),u+=(a?"&":"?")+f+"="+v,a=!0}}return u},y.prototype.is=function(e,t){return!0},y.prototype.encode=function(e,t){return e},y.prototype.decode=function(e,t){return e},y.prototype.equals=function(e,t){return e==t},y.prototype.$subPattern=function(){var e=this.pattern.toString();return e.substr(1,e.length-2)},y.prototype.pattern=/.*/,y.prototype.toString=function(){return"{Type:"+this.name+"}"},y.prototype.$normalize=function(e){return this.is(e)?e:this.decode(e)},y.prototype.$asArray=function(e,t){function r(e,t){function r(e,t){return function(){return e[t].apply(e,arguments)}}function i(e){return F(e)?e:N(e)?[e]:[]}function o(e){switch(e.length){case 0:return n;case 1:return"auto"===t?e[0]:e;default:return e}}function a(e){return!e}function s(e,t){return function(n){n=i(n);var r=h(n,e);return!0===t?0===p(r,a).length:o(r)}}this.encode=s(r(e,"encode")),this.decode=s(r(e,"decode")),this.is=s(r(e,"is"),!0),this.equals=function(e){return function(t,n){var r=i(t),o=i(n);if(r.length!==o.length)return!1;for(var a=0;a=":n(e.from)}:{"<=":n(e.to)}}function o(e){return e.in?{IN:e.in}:{"NOT IN":e.nin}}return{extend:function(t){return e.assign(Object.create(this),t)},compactFilters:function(t){return t?e.pick(t,function(e){return 0===e||!1===e||!!e}):null},processFilters:function(t){return t?(t=this.compactFilters(t),e.transform(t,function(e,t,n){t.from||t.to?e[n]=i(t):t.in||t.nin?e[n]=o(t):e[n]=t},{})):null}}})}),define("common/models/contact-job-role.model",["common/modules/models","common/models/model","common/instances/contact-job-role-instance.instance","common/services/api/contact-job-role-api.api"],function(e){"use strict";e.factory("ContactJobRole",["$log","Model","ContactJobRoleAPI","ContactJobRoleInstance",function(e,t,n,r){return e.debug("ContactJobRole"),t.extend({all:function(e){return n.all(e).then(function(e){return e.list.map(function(e){return r.init(e,!0)})})}})}])}),define("common/models/instances/group-instance",["common/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("GroupInstance",["ModelInstance",function(e){var t=["id","name","title","description"];return e.extend({fromAPIFilter:function(e,n,r){_.includes(t,r)&&(e[r]=this[r])}})}])}),define("common/mocks/module",["common/angular"],function(e){"use strict";return e.module("common.mocks",[])}),define("common/mocks/services/api/group-mock",["common/lodash","common/mocks/module"],function(e,t){"use strict";t.factory("api.group.mock",["$q",function(t){function n(e){var n=t.defer();return n.resolve(e),n.promise}return{all:function(e,t,r){var i,o,a;return i=r||this.mockedGroups().list,e&&(i=i.filter(function(t){return Object.keys(e).every(function(n){return t[n]===e[n]})})),t&&(o=(t.page-1)*t.size,a=o+t.size,i=i.slice(o,a)),n({list:i,total:i.length,allIds:i.map(function(e){return e.id}).join(",")})},find:function(e,t){return n(t||this.mockedGroups().list.filter(function(t){return t.id===e})[0])},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedGroups:function(){return{total:5,list:[{id:"1",name:"Administrators",title:"Administrators",description:"Contacts in this group are assigned Administrator role permissions.",is_active:"1",visibility:"User and User Admin Only",group_type:["1"],is_hidden:"0",is_reserved:"0"},{id:"2",name:"Newsletter Subscribers",title:"Newsletter Subscribers",is_active:'"1',visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"3",name:"Summer Program Volunteers",title:"Summer Program Volunteers",is_active:"1",visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"4",name:"Advisory Board",title:"Advisory Board",is_active:"1",visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"5",name:"Case_Resources",title:"Case Resources",description:"Contacts in this group are listed with their phone number and email when viewing case. You also can send copies of case activities to these contacts.",is_active:"1",visibility:"User and User Admin Only",where_clause:"...",select_tables:"...",where_tables:"...",group_type:"2",is_hidden:"0",is_reserved:"0"}]}}}}])}),define("common/mocks/data/contact.data",[],function(){return{all:{is_error:0,version:3,count:26,values:[{id:"1",contact_id:"1",display_name:"Dr. Kiara Jensen-Parker",email:"kh.jensen-parker@testing.info",contact_type:"Individual"},{id:"2",contact_id:"2",display_name:"jacobc82@lol.co.pl",email:"cruz.v.jacob@spamalot.com",contact_type:"Individual"},{id:"3",contact_id:"3",display_name:"Mei Müller-Nielsen",email:"mz.mller-nielsen75@infomail.co.pl",contact_type:"Individual"},{id:"4",contact_id:"4",display_name:"Ms. Brigette Deforest",email:"deforest.p.brigette9@fakemail.info",contact_type:"Individual"},{id:"5",contact_id:"5",display_name:"robertsc@testing.net",email:"clintr56@mymail.org",contact_type:"Individual"},{id:"6",contact_id:"6",display_name:"Dr. Allen Samuels Sr.",email:"samuelsa@mymail.org",contact_type:"Individual"},{id:"7",contact_id:"7",display_name:"Mei Wilson",email:"wilson.u.mei59@sample.org",contact_type:"Individual"},{id:"8",contact_id:"8",display_name:"Dr. Betty Díaz",email:"dazb@sample.co.nz",contact_type:"Individual"},{id:"9",contact_id:"9",display_name:"Bob Jones-Dimitrov",email:"bobj@testmail.biz",contact_type:"Individual"},{id:"10",contact_id:"10",display_name:"Truman Samuels III",email:"trumans@spamalot.org",contact_type:"Individual"},{id:"11",contact_id:"11",display_name:"Iris Wagner",email:"iwagner75@notmail.info",contact_type:"Individual"},{id:"12",contact_id:"12",display_name:"Mr. Rosario McReynolds",email:"rosariomcreynolds@testmail.org",contact_type:"Individual"},{id:"13",contact_id:"13",display_name:"Shad Jones-Dimitrov III",email:"shadj@lol.net",contact_type:"Individual"},{id:"14",contact_id:"14",display_name:"Toby Cruz Sr.",email:"",contact_type:"Individual"},{id:"15",contact_id:"15",display_name:"lareedaz61@testing.com",email:"lareedaz61@testing.com",contact_type:"Individual"},{id:"16",contact_id:"16",display_name:"Dr. Jay Deforest",email:"jayd@fishmail.org",contact_type:"Individual"},{id:"17",contact_id:"17",display_name:"Mr. Norris Cruz",email:"norriscruz@spamalot.info",contact_type:"Individual"},{id:"18",contact_id:"18",display_name:"herminiac@fishmail.com",email:"herminiac@fishmail.com",contact_type:"Individual"},{id:"19",contact_id:"19",display_name:"Ashley Terrell",email:"terrell.ashley@testmail.info",contact_type:"Individual"},{id:"20",contact_id:"20",display_name:"Kandace Parker-Díaz",email:"parker-daz.kandace67@fishmail.co.uk",contact_type:"Individual"},{id:"21",contact_id:"21",display_name:"Nicole Samuels",email:"ng.samuels@testmail.net",contact_type:"Individual"},{id:"22",contact_id:"22",display_name:"Dr. Kandace Wattson",email:"kandacewattson@testing.info",contact_type:"Individual"},{id:"23",contact_id:"23",display_name:"Brittney Cruz",email:"cruz.brittney@spamalot.co.nz",contact_type:"Individual"},{id:"24",contact_id:"24",display_name:"Shauna Olsen",email:"",contact_type:"Individual"},{id:"202",contact_id:"202",display_name:"civihr_staff@compucorp.co.uk",email:"civihr_staff@compucorp.co.uk",contact_type:"Individual"},{id:"203",contact_id:"203",display_name:"civihr_manager@compucorp.co.uk",email:"civihr_manager@compucorp.co.uk",contact_type:"Individual"}]}}}),define("common/mocks/services/api/contact-mock",["common/lodash","common/mocks/module","common/mocks/data/contact.data"],function(e,t,n){"use strict";t.factory("api.contact.mock",["$q",function(t){function r(e){var n=t.defer();return n.resolve(e),n.promise}return{all:function(t,i,o,a,s){var l,u,c;return l=s||n.all.values,t&&(l=l.filter(function(n){return Object.keys(t).every(function(r){return null===t[r]||("display_name"===r?new RegExp(t[r],"i").test(n[r]):t[r].IN?e.includes(t[r].IN,n[r]):n[r]===t[r])})})),i&&(u=(i.page-1)*i.size,c=u+i.size,l=l.slice(u,c)),r({list:l,total:l.length,allIds:l.map(function(e){return e.id}).join(",")})},find:function(e,t){return r(t||n.all.values.filter(function(t){return t.id===e})[0])},leaveManagees:function(){return r(this.mockedContacts().list)},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedContacts:function(){var e=n.all.values;return{total:e.length,list:e.map(function(e){return e})}}}}])}),define("common/mocks/services/api/group-contact-mock",["common/lodash","common/mocks/module","common/mocks/services/api/contact-mock","common/mocks/services/api/group-mock"],function(e,t){"use strict";t.factory("api.group-contact.mock",["$q","api.contact.mock","api.group.mock",function(t,n,r){function i(t){return e.sample(t)}function o(e){var n=t.defer();return n.resolve(e),n.promise}var a=n.mockedContacts().list,s=r.mockedGroups().list;return{all:function(e,t,n){var r,i,a;return r=n||this.mockedGroupsContacts.list,e&&(r=r.filter(function(t){return Object.keys(e).every(function(n){return t[n]===e[n]})})),t&&(i=(t.page-1)*t.size,a=i+t.size,r=r.slice(i,a)),o({list:r,total:r.length,allIds:r.map(function(e){return e.id}).join(",")})},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedGroupsContacts:{total:a.length,list:function(){var e=1;return a.map(function(t){return{id:""+e++,group_id:i(s).id,contact_id:t.id,status:"Added"}})}()}}}])}),define("common/models/group",["common/modules/models","common/models/model","common/models/instances/group-instance","common/mocks/services/api/group-mock","common/mocks/services/api/group-contact-mock"],function(e){"use strict";e.factory("Group",["Model","api.group.mock","api.group-contact.mock","GroupInstance",function(e,t,n,r){return e.extend({all:function(e,n){return t.all(this.processFilters(e),n).then(function(e){return e.list=e.list.map(function(e){return r.init(e,!0)}),e})},find:function(e){return t.find(e).then(function(e){return r.init(e,!0)})},contactIdsOf:function(e){return n.all({group_id:e}).then(function(e){return e.list.map(function(e){return e.contact_id})})}})}])}),define("common/models/instances/job-role-instance",["common/lodash","common/moment","common/modules/models-instances","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("JobRoleInstance",["ModelInstance","HR_settings",function(n,r){return n.extend({fromAPIFilter:function(n,i,o){var a=r.DATE_FORMAT.toUpperCase();e.endsWith(o,"_date")?n[o]=t(this[o],"YYYY-MM-DD HH:mm:ss").format(a):"api.HRJobContract.getsingle"===o?(n.contact_id=this[o].contact_id,n.job_contract_id=this[o].id):n[o]=this[o]},toAPIFilter:function(n,i,o){var a=["contact_id","job_contract_id"],s=r.DATE_FORMAT.toUpperCase();if(e.endsWith(o,"_date"))n[o]=t(this[o],s).format("YYYY-MM-DD HH:mm:ss");else{if(e.includes(a,o))return;n[o]=this[o]}}})}])}),define("common/services/api/job-role",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.job-role",["$log","api",function(e,t){return e.debug("api.jobRole"),t.extend({all:function(t,n,r,i){return e.debug("api.jobRole.api"),this.getAll("HrJobRoles",t,n,r,i)},find:function(t){return e.debug("api.jobRole.find"),this.sendGET("HRJobRole","get",{id:""+t},!1).then(function(e){return e.values[0]})}})}])}),define("common/models/job-role",["common/modules/models","common/models/model","common/models/instances/job-role-instance","common/services/api/job-role"],function(e){"use strict";e.factory("JobRole",["Model","api.job-role","JobRoleInstance",function(e,t,n){return e.extend({all:function(e,r){return t.all(this.processFilters(e),r).then(function(e){return e.list=e.list.map(function(e){return n.init(e,!0)}),e})},find:function(e){return t.find(e).then(function(e){return n.init(e,!0)})}})}])}),define("common/services/api/contact",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.contact",["$log","api",function(e,t){return e.debug("api.contact"),t.extend({all:function(t,n,r,i){return e.debug("api.contact.api"),this.getAll("Contact",t,n,r,i)},find:function(t){return e.debug("api.contact.find"),this.sendGET("Contact","get",{id:""+t},!1).then(function(e){return e.values[0]})},leaveManagees:function(t,n){return e.debug("api.contact.leaveManagees"),n=_.assign({},n,{managed_by:t}),this.sendGET("Contact","getleavemanagees",n).then(function(e){return e.values})}})}])}),define("common/models/instances/contact-instance",["common/modules/models-instances","common/models/instances/instance","common/services/api/contact"],function(e){"use strict";e.factory("ContactInstance",["ModelInstance","api.contact",function(e,t){return e.extend({leaveManagees:function(e){return t.leaveManagees(this.id,e)}})}])}),define("common/models/contact",["common/lodash","common/modules/models","common/models/model","common/models/contact-job-role.model","common/models/group","common/models/job-role","common/models/instances/contact-instance","common/services/api/contact"],function(e,t){"use strict";t.factory("Contact",["$q","Model","api.contact","Group","JobRole","ContactJobRole","ContactInstance",function(t,n,r,i,o,a,s){function l(t,n){return!e.isEmpty(e.intersection(e.keys(t),n))}function u(e){return a.all(e).then(function(e){return e.map(function(e){return e.contact_id})})}function c(t,n){return e(t).omit(d).omit(p).assign({id:{in:e.intersection.apply(null,n)}}).value()}function f(n){var r=t.defer(),o=[];return n=this.compactFilters(n),l(n,p)&&o.push(u(e.pick(n,p))),l(n,d)&&o.push(i.contactIdsOf(n.group_id)),e.isEmpty(o)?r.resolve(this.processFilters(n)):t.all(o).then(function(e){n=c(n,e),r.resolve(this.processFilters(n))}.bind(this)),r.promise}var d=["group_id"],p=["region","department","level_type","location"];return n.extend({all:function(e,t,n,i){return f.call(this,e).then(function(e){return e&&e.id&&!e.id.IN.length?{list:[]}:r.all(e,t,n,i)}).then(function(e){return e.list=e.list.map(function(e){return s.init(e,!0)}),e})},find:function(e){return r.find(e).then(function(e){return s.init(e,!0)})},leaveManagees:function(e,t){return f.call(this,t).then(function(t){return t&&t.id&&!t.id.IN.length?[]:r.leaveManagees(e,t)})}})}])}),define("common/models/instances/contract-instance",["common/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("ContractInstance",["ModelInstance",function(e){return e.extend({})}])}),define("common/services/api/contract",["common/lodash","common/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("api.contract",["$log","api",function(t,n){function r(t){var n=e.clone(t);return n.info=n["api.HRJobContract.getfulldetails"],delete n["api.HRJobContract.getfulldetails"],n}return t.debug("api.contract"),n.extend({all:function(e){return t.debug("ContractAPI.all"),e=e||{},e["api.HRJobContract.getfulldetails"]={jobcontract_id:"$value.id"},e.deleted=0,this.sendGET("HRJobContract","get",e,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r)})}})}])}),define("common/models/contract",["common/modules/models","common/models/model","common/models/instances/contract-instance","common/services/api/contract"],function(e){"use strict";e.factory("Contract",["$log","Model","api.contract","ContractInstance",function(e,t,n,r){return e.debug("Contract"),t.extend({all:function(e){return n.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})}})}])}),define("common/models/option-group",["common/modules/models","common/models/model","common/services/api/option-group"],function(e){"use strict";e.factory("OptionGroup",["Model","api.optionGroup",function(e,t){return e.extend({valuesOf:function(e){return t.valuesOf(e)}})}])}),function(e,t){define("common/models/session.model",["common/modules/models","common/models/model"],function(n){"use strict";n.factory("Session",["$log","$q","Model",function(n,r,i){return n.debug("Session"),i.extend({get:function(){var n={contactId:e.vars.session?e.vars.session.contact_id:t.settings.currentCiviCRMUserId};if(!n.contactId)throw new Error("Session Error: *Logged In Contact Id* is not defined");return r.resolve(n)}})}])})}(CRM,window.Drupal),define("common/bundles/models",["common/instances/contact-job-role-instance.instance","common/models/model","common/models/contact","common/models/contact-job-role.model","common/models/contract","common/models/group","common/models/job-role","common/models/option-group","common/models/session.model","common/models/instances/instance","common/models/instances/contact-instance","common/models/instances/contract-instance","common/models/instances/group-instance","common/models/instances/job-role-instance"],function(){}),define("common/services/dialog/dialog",["common/lodash","common/modules/services"],function(e,t){"use strict";function n(t,n,r){function i(i){var o;if(!e.isObject(i))throw new Error("Dialog Service: Options passed should be an object");return o=n.children(),t.open({appendTo:o.length?o.eq(0):n,size:"sm",controller:"DialogController",template:r.get("dialog.html"),resolve:{options:function(){return i}}}).result}return{open:i}}t.factory("dialog",n),n.$inject=["$uibModal","$rootElement","$templateCache"]}),define("common/controllers/dialog/dialog-ctrl",["common/lodash","common/modules/controllers"],function(e,t){"use strict";function n(t,n,r,i){function o(t){e.assign(n,e.defaultsDeep(t,{title:"CiviHR",msg:"",copyConfirm:"",copyCancel:"",classConfirm:"btn-primary",loading:!1}))}function a(){r.close(!1)}function s(){n.loading=!0,r.closed.then(n.onCloseAfterConfirm),t.resolve().then(n.onConfirm).then(function(){r.close(!0)})}n.cancel=a,n.confirm=s,function(){o(i),i.optionsPromise&&i.optionsPromise().then(function(e){o(e)})}()}t.controller("DialogController",n),n.$inject=["$q","$scope","$uibModalInstance","options"]}),define("common/modules/dialog",["common/angular","common/services/dialog/dialog","common/controllers/dialog/dialog-ctrl","common/angularBootstrap","common/directives/loading","common/modules/templates"],function(e){"use strict";return e.module("common.dialog",["ui.bootstrap","common.directives","common.templates"])}),define("common/decorators/xeditable-civi/editable-directive-factory",[],function(){"use strict";return["$delegate",function(e){return function(t){var n=e(t);return n.compile=function(e){var t,r=e[0].attributes.getNamedItem("ng-href");return e.append(''),r&&(t=angular.element(""),t.text("Follow link"),t.attr(r.nodeName,r.value),t.attr("ng-click","$event.stopPropagation();"),t.addClass("editable-link"),e.append(t),e.addClass("editable-with-link")),{post:n.link}},n}}]}),define("common/directives/xeditable-civi/editable-ta",[],function(){"use strict";return["editableDirectiveFactory","$timeout",function(e,t){var n,r;return r=e({directiveName:"editableTa",inputTpl:"",render:function(){this.parent.render.call(this),this.inputEl.parent().parent().removeClass("form-inline"),this.inputEl.addClass("editable-ta"),this.inputEl.attr("ng-model","ta.$data"),this.inputEl.attr("ta-toolbar",this.attrs.eTaToolbar||'[["bold","italics","underline","strikeThrough","ul","ol","undo","redo","clear"]]'),t(function(){this.inputEl.find("textarea").hide()}.bind(this),0)},save:function(){this.scope.$data=this.scope.ta.$data,this.parent.save.call(this)},setLocalValue:function(){this.parent.setLocalValue.call(this),this.scope.ta.$data=this.scope.$data}}),n=r.link,r.link=function(e,t,r,i){return e.ta={},n(e,t,r,i)},r}]}),define("common/modules/xeditable-civi",["common/angular","common/decorators/xeditable-civi/editable-directive-factory","common/directives/xeditable-civi/editable-ta","common/angularXeditable","common/text-angular"],function(e,t,n){"use strict";return e.module("xeditable-civi",["xeditable","textAngular"]).directive("editableTa",n)}); +this.date(a.getUTCDate()),this}function Ut(e){return null==e?Math.ceil((this.month()+1)/3):this.month(3*(e-1)+this.month()%3)}function Ht(e){return me(e,this._week.dow,this._week.doy).week}function qt(){return this._week.dow}function Vt(){return this._week.doy}function zt(e){var t=this.localeData().week(this);return null==e?t:this.add(7*(e-t),"d")}function Bt(e){var t=me(this,1,4).week;return null==e?t:this.add(7*(e-t),"d")}function Yt(e,t){return"string"!=typeof e?e:isNaN(e)?(e=t.weekdaysParse(e),"number"==typeof e?e:null):parseInt(e,10)}function Wt(e,n){return t(this._weekdays)?this._weekdays[e.day()]:this._weekdays[this._weekdays.isFormat.test(n)?"format":"standalone"][e.day()]}function Gt(e){return this._weekdaysShort[e.day()]}function Kt(e){return this._weekdaysMin[e.day()]}function Zt(e,t,n){var r,i,o;for(this._weekdaysParse||(this._weekdaysParse=[],this._minWeekdaysParse=[],this._shortWeekdaysParse=[],this._fullWeekdaysParse=[]),r=0;7>r;r++){if(i=Te([2e3,1]).day(r),n&&!this._fullWeekdaysParse[r]&&(this._fullWeekdaysParse[r]=new RegExp("^"+this.weekdays(i,"").replace(".",".?")+"$","i"),this._shortWeekdaysParse[r]=new RegExp("^"+this.weekdaysShort(i,"").replace(".",".?")+"$","i"),this._minWeekdaysParse[r]=new RegExp("^"+this.weekdaysMin(i,"").replace(".",".?")+"$","i")),this._weekdaysParse[r]||(o="^"+this.weekdays(i,"")+"|^"+this.weekdaysShort(i,"")+"|^"+this.weekdaysMin(i,""),this._weekdaysParse[r]=new RegExp(o.replace(".",""),"i")),n&&"dddd"===t&&this._fullWeekdaysParse[r].test(e))return r;if(n&&"ddd"===t&&this._shortWeekdaysParse[r].test(e))return r;if(n&&"dd"===t&&this._minWeekdaysParse[r].test(e))return r;if(!n&&this._weekdaysParse[r].test(e))return r}}function Jt(e){if(!this.isValid())return null!=e?this:NaN;var t=this._isUTC?this._d.getUTCDay():this._d.getDay();return null!=e?(e=Yt(e,this.localeData()),this.add(e-t,"d")):t}function Qt(e){if(!this.isValid())return null!=e?this:NaN;var t=(this.day()+7-this.localeData()._week.dow)%7;return null==e?t:this.add(e-t,"d")}function Xt(e){return this.isValid()?null==e?this.day()||7:this.day(this.day()%7?e:e-7):null!=e?this:NaN}function en(e){var t=Math.round((this.clone().startOf("day")-this.clone().startOf("year"))/864e5)+1;return null==e?t:this.add(e-t,"d")}function tn(){return this.hours()%12||12}function nn(e,t){R(e,0,0,function(){return this.localeData().meridiem(this.hours(),this.minutes(),t)})}function rn(e,t){return t._meridiemParse}function on(e){return"p"===(e+"").toLowerCase().charAt(0)}function an(e,t,n){return e>11?n?"pm":"PM":n?"am":"AM"}function sn(e,t){t[_r]=g(1e3*("0."+e))}function ln(){return this._isUTC?"UTC":""}function un(){return this._isUTC?"Coordinated Universal Time":""}function cn(e){return Te(1e3*e)}function fn(){return Te.apply(null,arguments).parseZone()}function dn(e,t,n){var r=this._calendar[e];return M(r)?r.call(t,n):r}function pn(e){var t=this._longDateFormat[e],n=this._longDateFormat[e.toUpperCase()];return t||!n?t:(this._longDateFormat[e]=n.replace(/MMMM|MM|DD|dddd/g,function(e){return e.slice(1)}),this._longDateFormat[e])}function hn(){return this._invalidDate}function mn(e){return this._ordinal.replace("%d",e)}function gn(e){return e}function vn(e,t,n,r){var i=this._relativeTime[n];return M(i)?i(e,t,n,r):i.replace(/%d/i,e)}function yn(e,t){var n=this._relativeTime[e>0?"future":"past"];return M(n)?n(t):n.replace(/%s/i,t)}function bn(e){var t,n;for(n in e)t=e[n],M(t)?this[n]=t:this["_"+n]=t;this._ordinalParseLenient=new RegExp(this._ordinalParse.source+"|"+/\d{1,2}/.source)}function $n(e,t,n,r){var i=k(),o=a().set(r,t);return i[n](o,e)}function wn(e,t,n,r,i){if("number"==typeof e&&(t=e,e=void 0),e=e||"",null!=t)return $n(e,t,n,i);var o,a=[];for(o=0;r>o;o++)a[o]=$n(e,o,n,i);return a}function xn(e,t){return wn(e,t,"months",12,"month")}function Cn(e,t){return wn(e,t,"monthsShort",12,"month")}function kn(e,t){return wn(e,t,"weekdays",7,"day")}function En(e,t){return wn(e,t,"weekdaysShort",7,"day")}function Sn(e,t){return wn(e,t,"weekdaysMin",7,"day")}function _n(){var e=this._data;return this._milliseconds=gi(this._milliseconds),this._days=gi(this._days),this._months=gi(this._months),e.milliseconds=gi(e.milliseconds),e.seconds=gi(e.seconds),e.minutes=gi(e.minutes),e.hours=gi(e.hours),e.months=gi(e.months),e.years=gi(e.years),this}function Mn(e,t,n,r){var i=Ze(t,n);return e._milliseconds+=r*i._milliseconds,e._days+=r*i._days,e._months+=r*i._months,e._bubble()}function Tn(e,t){return Mn(this,e,t,1)}function Dn(e,t){return Mn(this,e,t,-1)}function An(e){return 0>e?Math.floor(e):Math.ceil(e)}function On(){var e,t,n,r,i,o=this._milliseconds,a=this._days,s=this._months,l=this._data;return o>=0&&a>=0&&s>=0||0>=o&&0>=a&&0>=s||(o+=864e5*An(Rn(s)+a),a=0,s=0),l.milliseconds=o%1e3,e=m(o/1e3),l.seconds=e%60,t=m(e/60),l.minutes=t%60,n=m(t/60),l.hours=n%24,a+=m(n/24),i=m(Nn(a)),s+=i,a-=An(Rn(i)),r=m(s/12),s%=12,l.days=a,l.months=s,l.years=r,this}function Nn(e){return 4800*e/146097}function Rn(e){return 146097*e/4800}function In(e){var t,n,r=this._milliseconds;if("month"===(e=S(e))||"year"===e)return t=this._days+r/864e5,n=this._months+Nn(t),"month"===e?n:n/12;switch(t=this._days+Math.round(Rn(this._months)),e){case"week":return t/7+r/6048e5;case"day":return t+r/864e5;case"hour":return 24*t+r/36e5;case"minute":return 1440*t+r/6e4;case"second":return 86400*t+r/1e3;case"millisecond":return Math.floor(864e5*t)+r;default:throw new Error("Unknown unit "+e)}}function Pn(){return this._milliseconds+864e5*this._days+this._months%12*2592e6+31536e6*g(this._months/12)}function Fn(e){return function(){return this.as(e)}}function jn(e){return e=S(e),this[e+"s"]()}function Ln(e){return function(){return this._data[e]}}function Un(){return m(this.days()/7)}function Hn(e,t,n,r,i){return i.relativeTime(t||1,!!n,e,r)}function qn(e,t,n){var r=Ze(e).abs(),i=Oi(r.as("s")),o=Oi(r.as("m")),a=Oi(r.as("h")),s=Oi(r.as("d")),l=Oi(r.as("M")),u=Oi(r.as("y")),c=i=o&&["m"]||o=a&&["h"]||a=s&&["d"]||s=l&&["M"]||l=u&&["y"]||["yy",u];return c[2]=t,c[3]=+e>0,c[4]=n,Hn.apply(null,c)}function Vn(e,t){return void 0!==Ni[e]&&(void 0===t?Ni[e]:(Ni[e]=t,!0))}function zn(e){var t=this.localeData(),n=qn(this,!e,t);return e&&(n=t.pastFuture(+this,n)),t.postformat(n)}function Bn(){var e,t,n,r=Ri(this._milliseconds)/1e3,i=Ri(this._days),o=Ri(this._months);e=m(r/60),t=m(e/60),r%=60,e%=60,n=m(o/12),o%=12;var a=n,s=o,l=i,u=t,c=e,f=r,d=this.asSeconds();return d?(0>d?"-":"")+"P"+(a?a+"Y":"")+(s?s+"M":"")+(l?l+"D":"")+(u||c||f?"T":"")+(u?u+"H":"")+(c?c+"M":"")+(f?f+"S":""):"P0D"}var Yn,Wn,Gn=e.momentProperties=[],Kn=!1,Zn={},Jn={},Qn=/(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,Xn=/(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g,er={},tr={},nr=/\d/,rr=/\d\d/,ir=/\d{3}/,or=/\d{4}/,ar=/[+-]?\d{6}/,sr=/\d\d?/,lr=/\d\d\d\d?/,ur=/\d\d\d\d\d\d?/,cr=/\d{1,3}/,fr=/\d{1,4}/,dr=/[+-]?\d{1,6}/,pr=/\d+/,hr=/[+-]?\d+/,mr=/Z|[+-]\d\d:?\d\d/gi,gr=/Z|[+-]\d\d(?::?\d\d)?/gi,vr=/[+-]?\d+(\.\d{1,3})?/,yr=/[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i,br={},$r={},wr=0,xr=1,Cr=2,kr=3,Er=4,Sr=5,_r=6,Mr=7,Tr=8;R("M",["MM",2],"Mo",function(){return this.month()+1}),R("MMM",0,0,function(e){return this.localeData().monthsShort(this,e)}),R("MMMM",0,0,function(e){return this.localeData().months(this,e)}),E("month","M"),L("M",sr),L("MM",sr,rr),L("MMM",function(e,t){return t.monthsShortRegex(e)}),L("MMMM",function(e,t){return t.monthsRegex(e)}),V(["M","MM"],function(e,t){t[xr]=g(e)-1}),V(["MMM","MMMM"],function(e,t,n,r){var i=n._locale.monthsParse(e,r,n._strict);null!=i?t[xr]=i:l(n).invalidMonth=e});var Dr=/D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?/,Ar="January_February_March_April_May_June_July_August_September_October_November_December".split("_"),Or="Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),Nr=yr,Rr=yr,Ir={};e.suppressDeprecationWarnings=!1;var Pr=/^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/,Fr=/^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/,jr=/Z|[+-]\d\d(?::?\d\d)?/,Lr=[["YYYYYY-MM-DD",/[+-]\d{6}-\d\d-\d\d/],["YYYY-MM-DD",/\d{4}-\d\d-\d\d/],["GGGG-[W]WW-E",/\d{4}-W\d\d-\d/],["GGGG-[W]WW",/\d{4}-W\d\d/,!1],["YYYY-DDD",/\d{4}-\d{3}/],["YYYY-MM",/\d{4}-\d\d/,!1],["YYYYYYMMDD",/[+-]\d{10}/],["YYYYMMDD",/\d{8}/],["GGGG[W]WWE",/\d{4}W\d{3}/],["GGGG[W]WW",/\d{4}W\d{2}/,!1],["YYYYDDD",/\d{7}/]],Ur=[["HH:mm:ss.SSSS",/\d\d:\d\d:\d\d\.\d+/],["HH:mm:ss,SSSS",/\d\d:\d\d:\d\d,\d+/],["HH:mm:ss",/\d\d:\d\d:\d\d/],["HH:mm",/\d\d:\d\d/],["HHmmss.SSSS",/\d\d\d\d\d\d\.\d+/],["HHmmss,SSSS",/\d\d\d\d\d\d,\d+/],["HHmmss",/\d\d\d\d\d\d/],["HHmm",/\d\d\d\d/],["HH",/\d\d/]],Hr=/^\/?Date\((\-?\d+)/i;e.createFromInputFallback=ie("moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to https://github.com/moment/moment/issues/1407 for more info.",function(e){e._d=new Date(e._i+(e._useUTC?" UTC":""))}),R("Y",0,0,function(){var e=this.year();return 9999>=e?""+e:"+"+e}),R(0,["YY",2],0,function(){return this.year()%100}),R(0,["YYYY",4],0,"year"),R(0,["YYYYY",5],0,"year"),R(0,["YYYYYY",6,!0],0,"year"),E("year","y"),L("Y",hr),L("YY",sr,rr),L("YYYY",fr,or),L("YYYYY",dr,ar),L("YYYYYY",dr,ar),V(["YYYYY","YYYYYY"],wr),V("YYYY",function(t,n){n[wr]=2===t.length?e.parseTwoDigitYear(t):g(t)}),V("YY",function(t,n){n[wr]=e.parseTwoDigitYear(t)}),V("Y",function(e,t){t[wr]=parseInt(e,10)}),e.parseTwoDigitYear=function(e){return g(e)+(g(e)>68?1900:2e3)};var qr=T("FullYear",!1);e.ISO_8601=function(){};var Vr=ie("moment().min is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548",function(){var e=Te.apply(null,arguments);return this.isValid()&&e.isValid()?this>e?this:e:c()}),zr=ie("moment().max is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548",function(){var e=Te.apply(null,arguments);return this.isValid()&&e.isValid()?e>this?this:e:c()}),Br=function(){return Date.now?Date.now():+new Date};Ie("Z",":"),Ie("ZZ",""),L("Z",gr),L("ZZ",gr),V(["Z","ZZ"],function(e,t,n){n._useUTC=!0,n._tzm=Pe(gr,e)});var Yr=/([\+\-]|\d\d)/gi;e.updateOffset=function(){};var Wr=/(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/,Gr=/^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/;Ze.fn=Ne.prototype;var Kr=et(1,"add"),Zr=et(-1,"subtract");e.defaultFormat="YYYY-MM-DDTHH:mm:ssZ";var Jr=ie("moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.",function(e){return void 0===e?this.localeData():this.locale(e)});R(0,["gg",2],0,function(){return this.weekYear()%100}),R(0,["GG",2],0,function(){return this.isoWeekYear()%100}),Nt("gggg","weekYear"),Nt("ggggg","weekYear"),Nt("GGGG","isoWeekYear"),Nt("GGGGG","isoWeekYear"),E("weekYear","gg"),E("isoWeekYear","GG"),L("G",hr),L("g",hr),L("GG",sr,rr),L("gg",sr,rr),L("GGGG",fr,or),L("gggg",fr,or),L("GGGGG",dr,ar),L("ggggg",dr,ar),z(["gggg","ggggg","GGGG","GGGGG"],function(e,t,n,r){t[r.substr(0,2)]=g(e)}),z(["gg","GG"],function(t,n,r,i){n[i]=e.parseTwoDigitYear(t)}),R("Q",0,"Qo","quarter"),E("quarter","Q"),L("Q",nr),V("Q",function(e,t){t[xr]=3*(g(e)-1)}),R("w",["ww",2],"wo","week"),R("W",["WW",2],"Wo","isoWeek"),E("week","w"),E("isoWeek","W"),L("w",sr),L("ww",sr,rr),L("W",sr),L("WW",sr,rr),z(["w","ww","W","WW"],function(e,t,n,r){t[r.substr(0,1)]=g(e)});var Qr={dow:0,doy:6};R("D",["DD",2],"Do","date"),E("date","D"),L("D",sr),L("DD",sr,rr),L("Do",function(e,t){return e?t._ordinalParse:t._ordinalParseLenient}),V(["D","DD"],Cr),V("Do",function(e,t){t[Cr]=g(e.match(sr)[0],10)});var Xr=T("Date",!0);R("d",0,"do","day"),R("dd",0,0,function(e){return this.localeData().weekdaysMin(this,e)}),R("ddd",0,0,function(e){return this.localeData().weekdaysShort(this,e)}),R("dddd",0,0,function(e){return this.localeData().weekdays(this,e)}),R("e",0,0,"weekday"),R("E",0,0,"isoWeekday"),E("day","d"),E("weekday","e"),E("isoWeekday","E"),L("d",sr),L("e",sr),L("E",sr),L("dd",yr),L("ddd",yr),L("dddd",yr),z(["dd","ddd","dddd"],function(e,t,n,r){var i=n._locale.weekdaysParse(e,r,n._strict);null!=i?t.d=i:l(n).invalidWeekday=e}),z(["d","e","E"],function(e,t,n,r){t[r]=g(e)});var ei="Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),ti="Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),ni="Su_Mo_Tu_We_Th_Fr_Sa".split("_");R("DDD",["DDDD",3],"DDDo","dayOfYear"),E("dayOfYear","DDD"),L("DDD",cr),L("DDDD",ir),V(["DDD","DDDD"],function(e,t,n){n._dayOfYear=g(e)}),R("H",["HH",2],0,"hour"),R("h",["hh",2],0,tn),R("hmm",0,0,function(){return""+tn.apply(this)+N(this.minutes(),2)}),R("hmmss",0,0,function(){return""+tn.apply(this)+N(this.minutes(),2)+N(this.seconds(),2)}),R("Hmm",0,0,function(){return""+this.hours()+N(this.minutes(),2)}),R("Hmmss",0,0,function(){return""+this.hours()+N(this.minutes(),2)+N(this.seconds(),2)}),nn("a",!0),nn("A",!1),E("hour","h"),L("a",rn),L("A",rn),L("H",sr),L("h",sr),L("HH",sr,rr),L("hh",sr,rr),L("hmm",lr),L("hmmss",ur),L("Hmm",lr),L("Hmmss",ur),V(["H","HH"],kr),V(["a","A"],function(e,t,n){n._isPm=n._locale.isPM(e),n._meridiem=e}),V(["h","hh"],function(e,t,n){t[kr]=g(e),l(n).bigHour=!0}),V("hmm",function(e,t,n){var r=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r)),l(n).bigHour=!0}),V("hmmss",function(e,t,n){var r=e.length-4,i=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r,2)),t[Sr]=g(e.substr(i)),l(n).bigHour=!0}),V("Hmm",function(e,t,n){var r=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r))}),V("Hmmss",function(e,t,n){var r=e.length-4,i=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r,2)),t[Sr]=g(e.substr(i))});var ri=/[ap]\.?m?\.?/i,ii=T("Hours",!0);R("m",["mm",2],0,"minute"),E("minute","m"),L("m",sr),L("mm",sr,rr),V(["m","mm"],Er);var oi=T("Minutes",!1);R("s",["ss",2],0,"second"),E("second","s"),L("s",sr),L("ss",sr,rr),V(["s","ss"],Sr);var ai=T("Seconds",!1);R("S",0,0,function(){return~~(this.millisecond()/100)}),R(0,["SS",2],0,function(){return~~(this.millisecond()/10)}),R(0,["SSS",3],0,"millisecond"),R(0,["SSSS",4],0,function(){return 10*this.millisecond()}),R(0,["SSSSS",5],0,function(){return 100*this.millisecond()}),R(0,["SSSSSS",6],0,function(){return 1e3*this.millisecond()}),R(0,["SSSSSSS",7],0,function(){return 1e4*this.millisecond()}),R(0,["SSSSSSSS",8],0,function(){return 1e5*this.millisecond()}),R(0,["SSSSSSSSS",9],0,function(){return 1e6*this.millisecond()}),E("millisecond","ms"),L("S",cr,nr),L("SS",cr,rr),L("SSS",cr,ir);var si;for(si="SSSS";si.length<=9;si+="S")L(si,pr);for(si="S";si.length<=9;si+="S")V(si,sn);var li=T("Milliseconds",!1);R("z",0,0,"zoneAbbr"),R("zz",0,0,"zoneName");var ui=p.prototype;ui.add=Kr,ui.calendar=nt,ui.clone=rt,ui.diff=ct,ui.endOf=xt,ui.format=ht,ui.from=mt,ui.fromNow=gt,ui.to=vt,ui.toNow=yt,ui.get=O,ui.invalidAt=At,ui.isAfter=it,ui.isBefore=ot,ui.isBetween=at,ui.isSame=st,ui.isSameOrAfter=lt,ui.isSameOrBefore=ut,ui.isValid=Tt,ui.lang=Jr,ui.locale=bt,ui.localeData=$t,ui.max=zr,ui.min=Vr,ui.parsingFlags=Dt,ui.set=O,ui.startOf=wt,ui.subtract=Zr,ui.toArray=St,ui.toObject=_t,ui.toDate=Et,ui.toISOString=pt,ui.toJSON=Mt,ui.toString=dt,ui.unix=kt,ui.valueOf=Ct,ui.creationData=Ot,ui.year=qr,ui.isLeapYear=de,ui.weekYear=Rt,ui.isoWeekYear=It,ui.quarter=ui.quarters=Ut,ui.month=J,ui.daysInMonth=Q,ui.week=ui.weeks=zt,ui.isoWeek=ui.isoWeeks=Bt,ui.weeksInYear=Ft,ui.isoWeeksInYear=Pt,ui.date=Xr,ui.day=ui.days=Jt,ui.weekday=Qt,ui.isoWeekday=Xt,ui.dayOfYear=en,ui.hour=ui.hours=ii,ui.minute=ui.minutes=oi,ui.second=ui.seconds=ai,ui.millisecond=ui.milliseconds=li,ui.utcOffset=Le,ui.utc=He,ui.local=qe,ui.parseZone=Ve,ui.hasAlignedHourOffset=ze,ui.isDST=Be,ui.isDSTShifted=Ye,ui.isLocal=We,ui.isUtcOffset=Ge,ui.isUtc=Ke,ui.isUTC=Ke,ui.zoneAbbr=ln,ui.zoneName=un,ui.dates=ie("dates accessor is deprecated. Use date instead.",Xr),ui.months=ie("months accessor is deprecated. Use month instead",J),ui.years=ie("years accessor is deprecated. Use year instead",qr),ui.zone=ie("moment().zone is deprecated, use moment().utcOffset instead. https://github.com/moment/moment/issues/1779",Ue);var ci=ui,fi={sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"},di={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},pi=/\d{1,2}/,hi={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},mi=y.prototype;mi._calendar=fi,mi.calendar=dn,mi._longDateFormat=di,mi.longDateFormat=pn,mi._invalidDate="Invalid date",mi.invalidDate=hn,mi._ordinal="%d",mi.ordinal=mn,mi._ordinalParse=pi,mi.preparse=gn,mi.postformat=gn,mi._relativeTime=hi,mi.relativeTime=vn,mi.pastFuture=yn,mi.set=bn,mi.months=W,mi._months=Ar,mi.monthsShort=G,mi._monthsShort=Or,mi.monthsParse=K,mi._monthsRegex=Rr,mi.monthsRegex=ee,mi._monthsShortRegex=Nr,mi.monthsShortRegex=X,mi.week=Ht,mi._week=Qr,mi.firstDayOfYear=Vt,mi.firstDayOfWeek=qt,mi.weekdays=Wt,mi._weekdays=ei,mi.weekdaysMin=Kt,mi._weekdaysMin=ni,mi.weekdaysShort=Gt,mi._weekdaysShort=ti,mi.weekdaysParse=Zt,mi.isPM=on,mi._meridiemParse=ri,mi.meridiem=an,x("en",{ordinalParse:/\d{1,2}(th|st|nd|rd)/,ordinal:function(e){var t=e%10;return e+(1===g(e%100/10)?"th":1===t?"st":2===t?"nd":3===t?"rd":"th")}}),e.lang=ie("moment.lang is deprecated. Use moment.locale instead.",x),e.langData=ie("moment.langData is deprecated. Use moment.localeData instead.",k);var gi=Math.abs,vi=Fn("ms"),yi=Fn("s"),bi=Fn("m"),$i=Fn("h"),wi=Fn("d"),xi=Fn("w"),Ci=Fn("M"),ki=Fn("y"),Ei=Ln("milliseconds"),Si=Ln("seconds"),_i=Ln("minutes"),Mi=Ln("hours"),Ti=Ln("days"),Di=Ln("months"),Ai=Ln("years"),Oi=Math.round,Ni={s:45,m:45,h:22,d:26,M:11},Ri=Math.abs,Ii=Ne.prototype;return Ii.abs=_n,Ii.add=Tn,Ii.subtract=Dn,Ii.as=In,Ii.asMilliseconds=vi,Ii.asSeconds=yi,Ii.asMinutes=bi,Ii.asHours=$i,Ii.asDays=wi,Ii.asWeeks=xi,Ii.asMonths=Ci,Ii.asYears=ki,Ii.valueOf=Pn,Ii._bubble=On,Ii.get=jn,Ii.milliseconds=Ei,Ii.seconds=Si,Ii.minutes=_i,Ii.hours=Mi,Ii.days=Ti,Ii.weeks=Un,Ii.months=Di,Ii.years=Ai,Ii.humanize=zn,Ii.toISOString=Bn,Ii.toString=Bn,Ii.toJSON=Bn,Ii.locale=bt,Ii.localeData=$t,Ii.toIsoString=ie("toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)",Bn),Ii.lang=Jr,R("X",0,0,"unix"),R("x",0,0,"valueOf"),L("x",hr),L("X",vr),V("X",function(e,t,n){n._d=new Date(1e3*parseFloat(e,10))}),V("x",function(e,t,n){n._d=new Date(g(e))}),e.version="2.11.1",function(e){Yn=e}(Te),e.fn=ci,e.min=Ae,e.max=Oe,e.now=Br,e.utc=a,e.unix=cn,e.months=xn,e.isDate=n,e.locale=x,e.invalid=c,e.duration=Ze,e.isMoment=h,e.weekdays=kn,e.parseZone=fn,e.localeData=k,e.isDuration=Re,e.monthsShort=Cn,e.weekdaysMin=Sn,e.defineLocale=C,e.weekdaysShort=En,e.normalizeUnits=S,e.relativeTimeThreshold=Vn,e.prototype=ci,e}),define("common/bundles/vendors",["common/require","common/angular","common/angularAnimate","common/angularBootstrap","common/angular-file-upload","common/angularMocks","common/angularResource","common/angularRoute","common/angularXeditable","common/text-angular","common/ui-select","common/d3","common/lodash","common/moment"],function(){}),define("common/modules/apis",["common/angular"],function(e){"use strict";return e.module("common.apis",[])}),define("common/services/api",["common/angular","common/lodash","common/modules/apis"],function(e,t,n){"use strict";n.factory("api",["$log","$http","$httpParamSerializer","$q","$timeout",function(n,r,i,o,a){function s(e){return e.data.is_error?(n.error(e.data),o.reject(e.data.error_message)):e.data}function l(e){var n={options:{limit:0}};return JSON.stringify(t.merge(n,e||{}))}n.debug("api");return{extend:function(t){return e.extend(Object.create(this),t)},getAll:function(e,r,i,a,s,l,u){return n.debug("api.all"),r=r||{},l=l||"get",o.all([function(){var n=t.assign({},r,s||{},{options:t.assign({},r.options,{sort:a||"id DESC"})});return i&&(n.options.offset=(i.page-1)*i.size,n.options.limit=i.size),this.sendGET(e,l,n,u)}.bind(this)(),function(){if(!i)return o.resolve();var n=t.assign({},r,{return:"id"});return n=t.omit(n,function(e,n){return t.startsWith(n,"api.")}),this.sendGET(e,l,n,u)}.bind(this)()]).then(function(e){var n=e[0],r=i?e[1]:n;return{list:n.values,total:r.count,allIds:t.compact(r.values.map(function(e){return e.id})).join(",")}})},mockGET:function(e,t){var n=o.defer();return a(function(){n.resolve(e)},t||0),n.promise},mockPOST:function(e,t){return this.mockGET.apply(this,arguments)},sendGET:function(e,t,n,i){return r({method:"GET",url:"/civicrm/ajax/rest",cache:void 0===i||!!i,responseType:"json",params:{sequential:1,json:l(n),entity:e,action:t}}).then(s)},sendPOST:function(e,t,o){return n.debug("api.sendPOST"),r({method:"POST",url:"/civicrm/ajax/rest",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},responseType:"json",data:{json:l(o),sequential:1,entity:e,action:t},transformRequest:i}).then(s)}}}])}),define("common/services/api/appraisal",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.appraisal",["$log","api",function(e,t){return e.debug("api.appraisal"),t.extend({all:function(t,n,r){return e.debug("api.appraisal.api"),this.getAll("Appraisal",t,n,r)},create:function(t){return e.debug("api.appraisal.create"),this.sendPOST("Appraisal","create",t).then(function(e){return e.values[0]})},find:function(t){return e.debug("api.appraisal.find"),this.sendGET("Appraisal","get",{id:""+t},!1).then(function(e){return e.values[0]})}})}])}),define("common/services/api/option-group",["common/lodash","common/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("api.optionGroup",["$log","api",function(t,n){function r(t){return t.values.map(function(t){var n=e.clone(t);return n.option_group_name=n["option_group_id.name"],delete n["option_group_id.name"],n})}function i(t){return e.transform(t,function(e,t){var n=t.option_group_name;e[n]=e[n]||[],e[n].push(t)})}return t.debug("api.optionGroup"),n.extend({valuesOf:function(t,n,o){var a=e.isArray(t);return this.sendGET("OptionValue","get",e.assign({"option_group_id.name":{IN:a?t:[t]},is_active:"1",return:["option_group_id.name","option_group_id","id","name","label","value","weight","is_active","is_reserved"]},n),o).then(r).then(function(e){return a?i(e):e})}})}])}),define("common/services/api/appraisal-cycle",["common/lodash","common/modules/apis","common/services/api","common/services/api/option-group"],function(e,t){"use strict";t.factory("api.appraisal-cycle",["$q","$log","api","api.optionGroup",function(t,n,r,i){return n.debug("api.appraisal-cycle"),r.extend({all:function(e,t,r){return n.debug("api.appraisal-cycle.all"),this.getAll("AppraisalCycle",e,t,r,{"api.AppraisalCycle.getappraisalsperstep":{}})},create:function(t){return n.debug("api.appraisal-cycle.create"),this.sendPOST("AppraisalCycle","create",e.assign(t,{"api.AppraisalCycle.getappraisalsperstep":{}})).then(function(e){return e.values[0]})},find:function(e){n.debug("api.appraisal-cycle.find");var t={id:""+e,"api.AppraisalCycle.getappraisalsperstep":{}};return this.sendGET("AppraisalCycle","get",t,!1).then(function(e){return e.values[0]})},grades:function(){return n.debug("grades"),this.mockGET([{label:1,value:17},{label:2,value:74},{label:3,value:90},{label:4,value:30}])},statuses:function(){return n.debug("api.appraisal-cycle.statuses"),i.valuesOf("appraisal_status")},statusOverview:function(e){return n.debug("api.appraisal-cycle.statusOverview"),this.sendGET("AppraisalCycle","getstatusoverview",e).then(function(e){return e.values})},update:function(t){return n.debug("api.appraisal-cycle.update"),this.sendPOST("AppraisalCycle","create",e.assign(t,{"api.AppraisalCycle.getappraisalsperstep":{}})).then(function(e){return e.values[0]})},total:function(e){return n.debug("api.appraisal-cycle.total"),this.sendGET("AppraisalCycle","getcount",e||{}).then(function(e){return e.result})},types:function(){return n.debug("api.appraisal-cycle.types"),i.valuesOf("appraisal_cycle_type")}})}])}),define("common/services/api/contact-job-role-api.api",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("ContactJobRoleAPI",["$log","api",function(e,t){return e.debug("ContactJobRoleAPI"),t.extend({all:function(t,n,r,i){return e.debug("ContactJobRoleAPI.all()"),this.getAll("ContactHrJobRoles",t,n,r,i)}})}])}),define("common/bundles/apis",["common/services/api/appraisal","common/services/api/appraisal-cycle","common/services/api/contact-job-role-api.api","common/services/api/option-group"],function(){}),define("common/modules/services",["common/angular","common/angular-file-upload"],function(e){"use strict";return e.module("common.services",["angularFileUpload"])}),define("common/services/before-hash-query-params.service",["common/lodash","common/modules/services"],function(e,t){"use strict";t.factory("beforeHashQueryParams",["$log","$window",function(t,n){function r(e){var t=e||n.location.href,r=o(t);return-1===r.indexOf("?")?{}:i(a(r))}function i(t){return t.length?e.transform(t,function(e,t){var n=t.split("=");n[0]&&(e[n[0]]=n[1]?decodeURI(n[1]):null)},{}):{}}function o(e){var t=e.indexOf("#");return e.substring(0,-1!==t?t:e.length)}function a(e){var t=e.indexOf("?");return e.substr(t+1).split("&")}return t.debug("Service: beforeHashQueryParams"),{parse:r}}])}),function(e){define("common/services/check-permissions",["common/lodash","common/modules/services"],function(t,n){"use strict";n.factory("checkPermissions",["$q",function(n){return function(r){return r=t.isArray(r)?r:[r],n.resolve(r.every(function(t){return e.checkPerm(t)}))}}])})}(CRM),function(e){define("common/services/crm-ang.service",["common/lodash","common/modules/services"],function(t,n){"use strict";function r(t,n){return e.loadForm(t,n)}n.factory("crmAngService",function(){return{loadForm:r}})})}(CRM),define("common/services/detect-device.service",["common/modules/services"],function(e){"use strict";e.factory("detectDevice",[function(){return{isMobile:function(){return document.getElementsByTagName("body")[0].classList.contains("mobile")}}}])}),define("common/services/dom-event-trigger",["common/modules/services"],function(e){"use strict";!function(t){e.factory("DOMEventTrigger",function(){return function(e,n){t(document).trigger(e,n)}})}(CRM.$)}),define("common/services/file-mime-types",["common/lodash","common/modules/services"],function(e,t){"use strict";t.factory("fileMimeTypes",["$q",function(e){var t={txt:"plain",png:"png",jpeg:"jpeg",bmp:"bmp",gif:"gif",pdf:"pdf",doc:"msword",docx:"vnd.openxmlformats-officedocument.wordprocessingml.document",xls:"vnd.ms-excel",xlsx:"vnd.openxmlformats-officedocument.spreadsheetml.sheet",ppt:"vnd.ms-powerpoint",pptx:"vnd.openxmlformats-officedocument.presentationml.presentation"};return{getMimeTypeFor:function(n){return e.resolve(t[n])}}}])}),define("common/services/file-upload",["common/modules/services","common/lodash","common/angular-file-upload"],function(e,t){"use strict";e.factory("FileUpload",["$q","$log","FileUploader",function(e,n,r){function i(e){throw new Error(e+" missing from parameter")}function o(e,t,r,i){n.error(" ===== Item Error: "+r+" ======"),n.error(" ===== - item ======"),n.error(e),n.error(" ===== - response ======"),n.error(t),n.error(" ===== - headers ======"),n.error(i)}function a(e){return t.defaults(e,{allowedMimeTypes:{txt:"plain",png:"png",jpeg:"jpeg",bmp:"bmp",gif:"gif",pdf:"pdf"},url:"/civicrm/ajax/attachment",queueLimit:1})}return{uploader:function(n){var s,l,u,c=[];return n?(n=a(n),s=new r({url:n.url,queueLimit:+n.queueLimit,onCompleteItem:function(e,t){c.push(t)},onCompleteAll:function(){u.resolve(c)},onErrorItem:function(e){o.apply(null,arguments),u.reject("Could not upload file: "+e.file.name)},formData:[{entity_table:n.entityTable||i("entityTable"),crm_attachment_token:n.crmAttachmentToken||i("crmAttachmentToken")}],filters:[{name:"fileFormatFilter",fn:function(e){var r=e.type.slice(e.type.lastIndexOf("/")+1);return t.includes(t.values(n.allowedMimeTypes),r)}}]}),s.uploadAll=function(){return l=s.uploadAll,function(n){return u=e.defer(),s.onBeforeUploadItem=function(e){t.each(n,function(n,r){var i={};i[t.snakeCase(r)]=n,e.formData.push(i)})},l.apply(s),u.promise}}(),s):i("custom settings")}}}])}),define("common/services/file.service",["common/modules/services"],function(e){"use strict";e.factory("fileService",["$http","$window","$log",function(e,t,n){return n.debug("Service: fileService"),{openFile:function(n){return e.get(n.url,{responseType:"arraybuffer"}).success(function(e){var r=new Blob([e],{type:n.fileType});t.navigator.msSaveOrOpenBlob?t.navigator.msSaveOrOpenBlob(r,n.name):t.open(URL.createObjectURL(r),"_blank")})}}}])}),define("common/services/hr-settings",["common/modules/services"],function(e){"use strict";e.factory("HR_settings",function(){return{DATE_FORMAT:null}})}),function(e){define("common/services/notification.service",["common/lodash","common/modules/services"],function(t,n){"use strict";n.factory("notificationService",function(){return t(["alert","success","info","error"]).map(function(t){return[t,function(n,r,i){return e.alert(r,n,t,i)}]}).zipObject().value()})})}(CRM),define("common/services/pub-sub",["common/modules/services"],function(e){"use strict";var t=Object.create(null);e.factory("pubSub",["$rootScope",function(e){return{subscribe:function(n,r){var i;return t[n]=t[n]||[],r.$rootScope=e,i=t[n].push(r)-1,{remove:function(){delete t[n][i]}}},publish:function(e,n){t[e]&&(n=void 0!=n?n:{},t[e].forEach(function(e){e.$rootScope.$applyAsync(function(){e(n)})}))}}}])}),define("common/bundles/services",["common/services/before-hash-query-params.service","common/services/check-permissions","common/services/crm-ang.service","common/services/detect-device.service","common/services/dom-event-trigger","common/services/file-mime-types","common/services/file-upload","common/services/file.service","common/services/hr-settings","common/services/notification.service","common/services/pub-sub"],function(){}),define("common/modules/components",["common/angular"],function(e){return e.module("common.components",[])}),define("common/components/heatmap.component",["common/lodash","common/moment","common/modules/components"],function(e,t,n){function r(){function n(e){e.values&&(u(),l(),c())}function r(){return Object.values(d.values).filter(function(e){return!1!==e})}function i(e,t){return e.reduce(function(e,n){return Math.abs(n.value-t)');r(n,t),e.after(n)}function r(e,n){function r(){n.isOpen=!0,n.$apply()}t.isMobile()||(e.on("click",r),n.$on("$destroy",function(){e.off("click",r)}))}var i=e[0],o=i.compile;return i.compile=function(){var e=o.apply(this,arguments);return function(t,i,o){e.apply(this,arguments),n(i,t),r(i,t)}},e}]}),define("common/decorators/uib-datepicker-mobile-version.decorator",["common/moment","common/services/detect-device.service"],function(e){"use strict";return["$delegate","detectDevice",function(t,n){function r(t){return t?e(t).format("Y-MM-DD"):""}var i=t[0],o=i.compile;return i.require=["ngModel","uibDatepickerPopup"],i.compile=function(){var e=o.apply(this,arguments);return function(t,i,o,a){n.isMobile()?(i.prop("type","date"),o.ngReadonly=!1,a[0].$formatters.push(function(e){return r(e)}),t.$watch("datepickerOptions.minDate",function(e){o.$set("min",r(e))}),t.$watch("datepickerOptions.maxDate",function(e){o.$set("max",r(e))})):e.apply(this,arguments)}},t}]}),define("common/decorators/xeditable-disable-calendar-icon.decorator",[],function(){"use strict";return["$delegate",function(e){var t=e[0],n=t.compile;return t.compile=function(){var e=n.apply(this,arguments);return function(t,n,r){e.apply(this,arguments),r.eShowCalendarButton=!1}},e}]}),define("common/decorators/ui-bootstrap/uib-tabset",[],function(){"use strict";return["$delegate",function(e){return e[0].bindToController.customHeaderClass="@",e}]}),define("common/decorators/ui-bootstrap/uib-modal.decorator",["common/angular"],function(e){"use strict";return["$delegate","$document",function(t,n){function r(){var t,r=[{item:e.element(n[0].body),styles:[{name:"overflow",old:null,new:"hidden"},{name:"height",old:null,new:"100%"},{name:"width",old:null,new:"100%"}]},{item:e.element(n[0].getElementsByTagName("html")[0]),styles:[{name:"overflow",old:null,new:"hidden"},{name:"height",old:null,new:"100%"},{name:"width",old:null,new:"100%"}]}];return r.forEach(function(e){e.styles.forEach(function(t){t.old=e.item.css(t.name),e.item.css(t.name,t.new)})}),t=i.apply(this,arguments),t.closed.then(function(){r.forEach(function(e){e.styles.forEach(function(t){e.item.css(t.name,t.old)})})}),t}var i=t.open;return t.open=r,t}]}),define("common/modules/templates",["common/angular"],function(e){"use strict";return e.module("common.templates",[]).run(["$templateCache",function(e){e.put("dialog.html",'\n\n\n'),e.put("help-text.html",'\n'),e.put("loading.html",'
    \n
    \n
    \n
    \n'),e.put("time-amount-picker.html",'
    \n
    \n \n \n
    \n h\n
    \n \n \n
    \n m\n
    \n'),e.put("timepicker-select.html",'\n\n'),e.put("civihr-ui-select/choices.tpl.html",'
      \n
    • \n
      \n
        \n
      • \n
        \n
      • \n
      \n
    • \n
    \n'),e.put("civihr-ui-select/match-multiple.tpl.html",'\n
  • \n \n \n
  • \n\n'),e.put("civihr-ui-select/match.tpl.html",'\n {{$select.contactList ? \'-select-\' : $select.placeholder}}\n \n \n \n\n'),e.put("civihr-ui-select/select-contacts-multiple.tpl.html",'
    \n
    \n
      \n \n
    • \n \n
    • \n
    \n\n \n\n \n
    \n
    \n'),e.put("civihr-ui-select/select-contacts.tpl.html",'
    \n
    \n \n
    \n'),e.put("civihr-ui-select/select-multiple.tpl.html",'
    \n
    \n
      \n \n
    • \n \n
    • \n
    \n \n
    \n
    \n'),e.put("civihr-ui-select/select.tpl.html",'
    \n
    \n \n
    \n'),e.put("components/heatmap.html",'
      \n
    • \n {{day.name.short}}\n
    • \n
    \n'),e.put("contact-actions/contact-actions.html",'
    \n \n \n
    \n'),e.put("contact-actions/modals/form.html",'
    \n \n \n \n
    \n')}])}),define("common/modules/controllers",["common/angular","common/angularBootstrap","common/modules/apis"],function(e){"use strict";return e.module("common.controllers",["ui.bootstrap","common.apis"])}),define("common/modules/directives",["common/angular","common/decorators/ui-select-focus.decorator","common/decorators/uib-datepicker-calendar-icon.decorator","common/decorators/uib-datepicker-mobile-version.decorator","common/decorators/xeditable-disable-calendar-icon.decorator","common/decorators/ui-bootstrap/uib-tabset","common/decorators/ui-bootstrap/uib-modal.decorator","common/angularBootstrap","common/angularXeditable","common/ui-select","common/modules/templates","common/modules/controllers","common/modules/services","common/modules/apis"],function(e,t,n,r,i,o,a){"use strict";return e.module("common.directives",["common.templates","common.controllers","ui.select","ui.bootstrap","xeditable"]).config(["$provide",function(e){e.decorator("uibDatepickerPopupDirective",r),e.decorator("uibDatepickerPopupDirective",n),e.decorator("uibTabsetDirective",o),e.decorator("$uibModal",a),e.decorator("editableBsdateDirective",i),e.decorator("uiSelectDirective",t)}]).run(["$templateCache",function(e){var t="uib/template/tabs/tabset.html",n=jQuery(e.get(t));n.find("ul").addClass("{{tabset.customHeaderClass}}"),e.put(t,n.wrap("
    ").parent().html())}])}),define("common/services/api/contact-actions",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.contactActions",["$q","api",function(e,t){function n(e,n){return t.sendGET(e,"getoptions",{field:n,context:"search"}).then(function(e){return e.values})}function r(e){return t.sendGET("UFField","get",{uf_group_id:e,is_active:!0}).then(function(e){return e.values})}function i(n,r){return e(function(e,i){if(r.contact_type=n,r.email)return t.sendGET("CustomField","get",{return:["id"],custom_group_id:"Emergency_Contacts",name:"email"}).then(function(t){r["custom_"+t.id]=r.email,delete r.email,e()});e()}).then(function(){return t.sendPOST("Contact","create",r).then(function(e){return e.values[0]})})}return t.extend({getOptions:{forContactType:function(){return n.call(this,"Contact","contact_type")},forGroup:function(){return n.call(this,"GroupContact","group_id")},forTag:function(){return n.call(this,"EntityTag","tag_id")},forStateProvince:function(){return n.call(this,"Address","state_province_id")},forCountry:function(){return n.call(this,"Address","country_id")},forGender:function(){return n.call(this,"Contact","gender_id")},forDeceased:function(){return n.call(this,"Contact","is_deceased")}},save:{newIndividual:function(e){return i.call(this,"Individual",e)},newOrganization:function(e){return i.call(this,"Organization",e)},newHousehold:function(e){return i.call(this,"Household",e)}},getFormFields:{forNewIndividual:function(){return r.call(this,"new_individual")},forNewOrganization:function(){return r.call(this,"new_organization")},forNewHousehold:function(){return r.call(this,"new_household")}}})}])}),define("common/controllers/contact-actions/modal-ctrl",[],function(){"use strict";return function(e,t){this.errorMsg="",this.loading=!0,this.formFields=[],this.init=function(e){e().then(function(e){this.loading=!1,this.formFields=e}.bind(this)).catch(function(){this.loading=!1,this.errorMsg="Error while loading form fields"}.bind(this))},this.cancel=function(){t.dismiss("cancel")},this.save=function(n,r){this.loading=!0,n(this.formFields.reduce(function(e,t){return e[t.field_name]=t.value,e},{})).then(function(n){this.loading=!1,e.$broadcast(r,n),t.dismiss("cancel")}.bind(this)).catch(function(){this.loading=!1,this.errorMsg="Error while saving data"}.bind(this))}}}),define("common/controllers/contact-actions/new-individual-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Individual",i.init(r.getFormFields.forNewIndividual),i.submit=function(){i.save(r.save.newIndividual,"newIndividualCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewIndividualModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/new-household-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Household",i.init(r.getFormFields.forNewHousehold),i.submit=function(){i.save(r.save.newHousehold,"newHouseholdCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewHouseholdModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/new-organization-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Organization",i.init(r.getFormFields.forNewOrganization),i.submit=function(){i.save(r.save.newOrganization,"newOrganizationCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewOrganizationModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/contact-actions-ctrl",["common/modules/controllers","common/services/api/contact-actions","common/controllers/contact-actions/new-individual-ctrl","common/controllers/contact-actions/new-household-ctrl","common/controllers/contact-actions/new-organization-ctrl"],function(e){"use strict";e.controller("ContactActionsCtrl",["$scope","$rootElement","$uibModal","api.contactActions",function(e,t,n,r){var i=this;e.$watch(function(){return i.refineSearch.selected},function(t,n){t!==n&&e.$emit("contactRefineSearch",{field:t.field?t.field.label:null,option:t.option?t.option.value:null})},!0),i.refineSearch={selected:{field:null,option:null},availableFields:[{label:"Contact Type",getOptions:r.getOptions.forContactType},{label:"Group",getOptions:r.getOptions.forGroup},{label:"Tag",getOptions:r.getOptions.forTag},{label:"State / Province",getOptions:r.getOptions.forStateProvince},{label:"Country",getOptions:r.getOptions.forCountry},{label:"Gender",getOptions:r.getOptions.forGender},{label:"Deceased",getOptions:r.getOptions.forDeceased}],availableOptions:{refresh:function(){i.refineSearch.selected.field?(this.options=null,i.refineSearch.selected.field.getOptions().then(function(e){this.options=e}.bind(this))):this.options=[]},options:[]}},i.showNewIndividualModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewIndividualModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})},i.showNewHouseholdModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewHouseholdModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})},i.showNewOrganizationModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewOrganizationModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})}}])}),define("common/directives/prevent-animations",["common/modules/directives"],function(e){"use strict";e.directive("preventAnimations",["$animate",function(e){return{restrict:"A",link:function(t,n,r){e.enabled(n,!1)}}}])}),define("common/directives/loading",["common/modules/directives","common/directives/prevent-animations"],function(e){"use strict";e.directive("crmLoading",["$templateCache",function(e){return{scope:{show:"="},restrict:"E",replace:!0,transclude:!0,template:e.get("loading.html")}}])}),define("common/directives/contact-actions/contact-actions",["common/modules/directives","common/controllers/contact-actions/contact-actions-ctrl","common/directives/loading"],function(e){"use strict";e.directive("contactActions",[function(){return{restrict:"E",templateUrl:"contact-actions/contact-actions.html",controller:"ContactActionsCtrl",controllerAs:"$ctrl",link:function(e,t,n){e.$ctrl.refineSearchVisible=t.parent().parent()[0].hasAttribute("refine-search")}}}])}),define("common/directives/help-text.directive",["common/lodash","common/moment","common/modules/directives","common/services/notification.service"],function(e,t,n){function r(e,t){function n(){var n=e.getHelpText();t.info(e.title||r,n)}var r="Help";this.displayHelpText=n}function i(e,t,n){function r(){return t.find(".help-text").html()}e.getHelpText=r}n.directive("helpText",["$templateCache",function(e){return{restrict:"E",scope:{title:"@?"},transclude:!0,controller:r,controllerAs:"helpText",template:e.get("help-text.html"),link:i}}]),r.$inject=["$scope","notificationService"]}),define("common/directives/scroll-shadows.directive",["common/angular","common/modules/directives"],function(e,t){"use strict";function n(t,n,r){function i(){u(),a(),l(),s()}function o(){var e=f.width(),t=p+"__shadows--show-left",n=p+"__shadows--show-right",r=d.scrollLeft(),i=d.width();if(e<=i)return void d.removeClass(t+" "+n);d[r>0?"addClass":"removeClass"](t),d[r
    ').parent(),d=f.wrap('
    ').parent(),d.wrap('
    ')}var f,d,p="chr_scroll-shadows";!function(){c(),i(),o()}()}t.directive("scrollShadows",[function(){return{restrict:"A",controller:n}}]),n.$inject=["$element","$scope","$window"]}),define("common/directives/timepicker-select.directive",["common/moment","common/modules/directives"],function(e,t){"use strict";function n(t){function n(){var n=+t.timepickerSelectInterval||1,i=e.duration(t.timepickerSelectTimeFrom||"00:00"),o=e.duration(t.timepickerSelectTimeTo||"23:59");for(r.options=[];i.asMinutes()<=o.asMinutes();){var a=e.utc(i.asMilliseconds());r.options.push(a.format("HH:mm")),i.add(n,"minutes")}}var r=this;r.placeholder=t.timepickerSelectPlaceholder,r.options=[],t.$watchGroup(["timepickerSelectTimeFrom","timepickerSelectTimeTo","timepickerSelectInterval"],function(){n()})}t.directive("timepickerSelect",["$templateCache",function(e){return{scope:{timepickerSelectPlaceholder:"@",timepickerSelectTimeFrom:"<",timepickerSelectTimeTo:"<",timepickerSelectInterval:"<"},restrict:"A",controllerAs:"selector",controller:["$scope",n],template:e.get("timepicker-select.html")}}]),n.$inject=["$scope"]}),define("common/directives/time-amount-picker.directive",["common/lodash","common/modules/directives"],function(e,t){"use strict";function n(t){function n(){var e=Math.floor(c);for(d.hoursOptions=[];e<=f;)d.hoursOptions.push(e),e++}function r(){var e,t,n,r=0;for(d.minutesOptions=[];r<60;)t=+d.selectedHours===Math.floor(c)&&rf%1*60,e=t||n,!e&&d.minutesOptions.push(r),r+=u;l()}function i(){u=+t.interval||1,c=isNaN(+t.minAmount)?0:+t.minAmount,f=isNaN(+t.maxAmount)?24:+t.maxAmount,n(),r()}function o(){""!==d.selectedHours&&""!==d.selectedMinutes&&(t.value=+d.selectedHours+d.selectedMinutes/60)}function a(){t.$watch("disabled",function(e){d.disabled=e}),t.$watch("value",function(){s()}),t.$watchGroup(["minAmount","maxAmount","interval"],function(){i()})}function s(){void 0!==t.value&&(d.selectedHours=""+Math.floor(t.value),d.selectedMinutes=""+Math.floor(t.value%1*60)),o()}function l(){d.selectedMinutese.last(d.minutesOptions)&&(d.selectedMinutes=""+e.last(d.minutesOptions))}var u,c,f,d=this;d.hoursOptions=[],d.minutesOptions=[],d.selectedHours="",d.selectedMinutes="",d.buildMinutesOptions=r,d.calculateSelectedValue=o,function(){s(),a()}()}t.directive("timeAmountPicker",["$templateCache",function(e){return{scope:{minAmount:".75?Math.floor(.25*Math.ceil(e/.25))+"h":"",n=e%1&&e%1<=.75&&e%1>0?.25*Math.ceil(e%1/.25)*60+"m":"",r+t+(t&&n?" ":"")+n)}};return function(t,n){var r=void 0===t?0:parseFloat(t);if(isNaN(r))throw new Error("Value must be a number or a numeric string: "+t);return e[n](r)}})}),define("common/bundles/filters",["common/filters/time-unit-applier.filter"],function(){}),define("common/decorators/angular-date/datepicker-popup",["common/lodash"],function(e){return["$delegate","HR_settings",function(t,n){"use strict";var r=t[0].link;return t[0].compile=function(){return function(t,i,o,a){o.uibDatepickerPopup=o.uibDatepickerPopup||n.DATE_FORMAT||"yyyy-MM-dd",o.showButtonBar=o.showButtonBar||!1,t.datepickerOptions=e.assign({formatDayHeader:"E",showWeeks:!1,startingDay:1},t.datepickerOptions),r.apply(this,arguments)}},t}] +}),define("common/decorators/angular-date/date-filter",[],function(){"use strict";return["$delegate",function(e){var t=e;return function(){if("E"===arguments[1]){var e=Array.prototype.slice.call(arguments);return e[1]="EEE",t.apply(this,e)[0]}return t.apply(this,arguments)}}]}),function(e){define("common/modules/angular-date",["common/angular","common/decorators/angular-date/datepicker-popup","common/decorators/angular-date/date-filter","common/modules/services","common/angularBootstrap","common/modules/templates"],function(t,n,r){"use strict";function i(t){var n="uib/template/datepicker/"+t+".html",r=o.get(n);r=r.replace(/glyphicon glyphicon-chevron-(left|right)/gm,"fa fa-chevron-$1"),"day"===t&&(r=function(t){return e(t).find('th[ng-if="showWeeks"]').parent().css({"border-top":"1px solid #DDD"}),e(t).prop("outerHTML")}(e.parseHTML(r))),o.put(n,r)}var o;return t.module("common.angularDate",["common.services","ui.bootstrap","common.templates"]).config(["$provide",function(e){e.decorator("uibDatepickerPopupDirective",n),e.decorator("dateFilter",r)}]).run(["$templateCache",function(e){o=e,["day","month","year"].forEach(i)}])})}(CRM.$),define("common/services/angular-date/date-format",["common/angular","common/modules/angular-date","common/services/hr-settings"],function(e,t){"use strict";t.factory("DateFormat",["$q","HR_settings",function(e,t){return{dateFormat:null,getDateFormat:function(){return this.dateFormat?e.when(this.dateFormat):e.when("dd/MM/yyyy").catch(function(){return"yyyy-MM-dd"}).then(function(e){return t.DATE_FORMAT=e,this.dateFormat=e,e}.bind(this))}}}])}),define("common/filters/angular-date/format-date",["common/moment","common/modules/angular-date","common/services/hr-settings"],function(e,t){"use strict";t.filter("formatDate",["HR_settings",function(t){var n=["DD-MM-YYYY","DD-MM-YYYY HH:mm:ss","YYYY-MM-DD","YYYY-MM-DD HH:mm:ss","DD/MM/YYYY","x","YYYY-MM-DD HH:mm:ss"];return function(r,i,o){var a,s=i||t.DATE_FORMAT||"YYYY-MM-DD",l=e(0);return r instanceof Date&&(r=e(r).format("YYYY-MM-DD HH:mm:ss")),a=e(r,n,!0),a.isValid()&&!a.isSame(l)?i===Date?a.toDate():a.format(s.toUpperCase())+("hours"===o?" "+a.format("HH:mm"):""):"Unspecified"}}])}),define("common/directives/angular-date/date-input",["common/modules/angular-date","common/filters/angular-date/format-date"],function(e){"use strict";e.directive("dateInput",["$filter",function(e){return{require:"ngModel",link:function(t,n,r,i){function o(t){var n=e("formatDate")(t);return n="Unspecified"==n?"":n}i.$formatters.push(o),i.$parsers=[]}}}])}),define("common/bundles/angular-date",["common/services/angular-date/date-format","common/filters/angular-date/format-date","common/directives/angular-date/date-input"],function(){}),define("common/modules/routers/compu-ng-route",["common/angular","common/angularRoute"],function(e){"use strict";return e.module("compuNgRoute",["ngRoute"]).config(["$routeProvider",function(t){var n=t.when;t.resolveForAll=function(e){return t.commonResolve=e,t},t.when=function(r,i){return e.extend(i.resolve||{},t.commonResolve||{}),n.call(t,r,i)}}])}),"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function r(e,t){return L(new(L(function(){},{prototype:e})),t)}function i(e){return j(arguments,function(t){t!==e&&j(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var r in e.path){if(e.path[r]!==t.path[r])break;n.push(e.path[r])}return n}function a(e){if(Object.keys)return Object.keys(e);var t=[];return j(e,function(e,n){t.push(n)}),t}function s(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,r=Number(arguments[2])||0;for(0>(r=0>r?Math.ceil(r):Math.floor(r))&&(r+=n);n>r;r++)if(r in e&&e[r]===t)return r;return-1}function l(e,t,n,r){var i,l=o(n,r),u={},c=[];for(var f in l)if(l[f].params&&(i=a(l[f].params),i.length))for(var d in i)s(c,i[d])>=0||(c.push(i[d]),u[i[d]]=e[i[d]]);return L({},u,t)}function u(e,t,n){if(!n){n=[];for(var r in e)n.push(r)}for(var i=0;i "));if(y[n]=r,I(e))g.push(n,[function(){return t.get(e)}],u);else{var i=t.annotate(e);j(i,function(e){e!==n&&l.hasOwnProperty(e)&&p(l[e],e)}),g.push(n,e,i)}v.pop(),y[n]=o}}function h(e){return P(e)&&e.then&&e.$$promises}if(!P(l))throw new Error("'invocables' must be an object");var m=a(l||{}),g=[],v=[],y={};return j(l,p),l=v=y=null,function(r,o,a){function s(){--b||($||i(y,o.$$values),p.$$values=y,p.$$promises=p.$$promises||!0,delete p.$$inheritedValues,u.resolve(y))}function l(e){p.$$failure=e,u.reject(e)}if(h(r)&&a===n&&(a=o,o=r,r=null),r){if(!P(r))throw new Error("'locals' must be an object")}else r=c;if(o){if(!h(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=f;var u=e.defer(),p=u.promise,v=p.$$promises={},y=L({},r),b=1+g.length/3,$=!1;if(N(o.$$failure))return l(o.$$failure),p;o.$$inheritedValues&&i(y,d(o.$$inheritedValues,m)),L(v,o.$$promises),o.$$values?($=i(y,d(o.$$values,m)),p.$$inheritedValues=d(o.$$values,m),s()):(o.$$inheritedValues&&(p.$$inheritedValues=d(o.$$inheritedValues,m)),o.then(s,l));for(var w=0,x=g.length;x>w;w+=3)r.hasOwnProperty(g[w])?s():function(n,i,o){function u(e){f.reject(e),l(e)}function c(){if(!N(p.$$failure))try{f.resolve(t.invoke(i,a,y)),f.promise.then(function(e){y[n]=e,s()},u)}catch(e){u(e)}}var f=e.defer(),d=0;j(o,function(e){v.hasOwnProperty(e)&&!r.hasOwnProperty(e)&&(d++,v[e].then(function(t){y[e]=t,--d||c()},u))}),d||c(),v[n]=f.promise}(g[w],g[w+1],g[w+2]);return p}},this.resolve=function(e,t,n,r){return this.study(e)(t,n,r)}}function g(e,t,n){this.fromConfig=function(e,t,n){return N(e.template)?this.fromString(e.template,t):N(e.templateUrl)?this.fromUrl(e.templateUrl,t):N(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return R(e)?e(t):e},this.fromUrl=function(n,r){return R(n)&&(n=n(r)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,r){return n.invoke(e,null,r||{params:t})}}function v(e,t,i){function o(t,n,r,i){if(g.push(t),h[t])return h[t];if(!/^\w+(-+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(m[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return m[t]=new H.Param(t,n,r,i),m[t]}function a(e,t,n,r){var i=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:i=["(",")"+(r?"?":"")];break;case!0:i=["?(",")?"];break;default:i=["("+n+"|",")?"]}return o+i[0]+t+i[1]}function s(i,o){var a,s,l,u,c;return a=i[2]||i[3],c=t.params[a],l=e.substring(d,i.index),s=o?i[4]:i[4]||("*"==i[1]?".*":null),u=H.type(s||"string")||r(H.type("string"),{pattern:new RegExp(s,t.caseInsensitive?"i":n)}),{id:a,regexp:s,segment:l,type:u,cfg:c}}t=L({params:{}},P(t)?t:{});var l,u=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,c=/([:]?)([\w\[\]-]+)|\{([\w\[\]-]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,f="^",d=0,p=this.segments=[],h=i?i.params:{},m=this.params=i?i.params.$$new():new H.ParamSet,g=[];this.source=e;for(var v,y,b;(l=u.exec(e))&&(v=s(l,!1),!(v.segment.indexOf("?")>=0));)y=o(v.id,v.type,v.cfg,"path"),f+=a(v.segment,y.type.pattern.source,y.squash,y.isOptional),p.push(v.segment),d=u.lastIndex;b=e.substring(d);var $=b.indexOf("?");if($>=0){var w=this.sourceSearch=b.substring($);if(b=b.substring(0,$),this.sourcePath=e.substring(0,d+$),w.length>0)for(d=0;l=c.exec(w);)v=s(l,!0),y=o(v.id,v.type,v.cfg,"search"),d=u.lastIndex}else this.sourcePath=e,this.sourceSearch="";f+=a(b)+(!1===t.strict?"/?":"")+"$",p.push(b),this.regexp=new RegExp(f,t.caseInsensitive?"i":n),this.prefix=p[0],this.$$paramNames=g}function y(e){L(this,e)}function b(){function e(e){return null!=e?e.toString().replace(/\//g,"%2F"):e}function i(e){return null!=e?e.toString().replace(/%2F/g,"/"):e}function o(){return{strict:m,caseInsensitive:d}}function l(e){return R(e)||F(e)&&R(e[e.length-1])}function u(){for(;x.length;){var e=x.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend($[e.name],f.invoke(e.def))}}function c(e){L(this,e||{})}H=this;var f,d=!1,m=!0,g=!1,$={},w=!0,x=[],C={string:{encode:e,decode:i,is:function(e){return null==e||!N(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return N(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};b.$$getDefaultValue=function(e){if(!l(e.value))return e.value;if(!f)throw new Error("Injectable functions cannot be called at configuration time");return f.invoke(e.value)},this.caseInsensitive=function(e){return N(e)&&(d=e),d},this.strictMode=function(e){return N(e)&&(m=e),m},this.defaultSquashPolicy=function(e){if(!N(e))return g;if(!0!==e&&!1!==e&&!I(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return g=e,e},this.compile=function(e,t){return new v(e,L(o(),t))},this.isMatcher=function(e){if(!P(e))return!1;var t=!0;return j(v.prototype,function(n,r){R(n)&&(t=t&&N(e[r])&&R(e[r]))}),t},this.type=function(e,t,n){if(!N(t))return $[e];if($.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return $[e]=new y(L({name:e},t)),n&&(x.push({name:e,def:n}),w||u()),this},j(C,function(e,t){$[t]=new y(L({name:t},e))}),$=r($,{}),this.$get=["$injector",function(e){return f=e,w=!1,u(),j(C,function(e,t){$[t]||($[t]=new y(e))}),this}],this.Param=function(e,t,r,i){function o(){if(!f)throw new Error("Injectable functions cannot be called at configuration time");var e=f.invoke(r.$$fn);if(null!==e&&e!==n&&!d.type.is(e))throw new Error("Default value ("+e+") for parameter '"+d.id+"' is not an instance of Type ("+d.type.name+")");return e}function u(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=h(p(d.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),N(e)?d.type.$normalize(e):o()}function c(){return"{Param:"+e+" "+t+" squash: '"+b+"' optional: "+v+"}"}var d=this;r=function(e){var t=P(e)?a(e):[];return-1===s(t,"value")&&-1===s(t,"type")&&-1===s(t,"squash")&&-1===s(t,"array")&&(e={value:e}),e.$$fn=l(e.value)?e.value:function(){return e.value},e}(r),t=function(t,n,r){if(t.type&&n)throw new Error("Param '"+e+"' has two type configurations.");return n||(t.type?t.type instanceof y?t.type:new y(t.type):"config"===r?$.any:$.string)}(r,t,i);var m=function(){var t={array:"search"===i&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return L(t,n,r).array}();t=m?t.$asArray(m,"search"===i):t,"string"!==t.name||m||"path"!==i||r.value!==n||(r.value="");var v=r.value!==n,b=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!N(n)||null==n)return g;if(!0===n||I(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,v),w=function(e,t,r,i){var o,a,l=[{from:"",to:r||t?n:""},{from:null,to:r||t?n:""}];return o=F(e.replace)?e.replace:[],I(i)&&o.push({from:i,to:n}),a=h(o,function(e){return e.from}),p(l,function(e){return-1===s(a,e.from)}).concat(o)}(r,m,v,b);L(this,{id:e,type:t,location:i,array:m,squash:b,replace:w,isOptional:v,value:u,dynamic:n,config:r,toString:c})},c.prototype={$$new:function(){return r(this,L(new c,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,r=a(c.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),j(t,function(t){j(a(t),function(t){-1===s(e,t)&&-1===s(r,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return j(n.$$keys(),function(r){t[r]=n[r].value(e&&e[r])}),t},$$equals:function(e,t){var n=!0,r=this;return j(r.$$keys(),function(i){var o=e&&e[i],a=t&&t[i];r[i].type.equals(o,a)||(n=!1)}),n},$$validates:function(e){var r,i,o,a,s,l=this.$$keys();for(r=0;ri;i++)if(t(u[i]))return;c&&t(c)}}function p(){return l=l||i.$on("$locationChangeSuccess",d)}var h,m=a.baseHref(),g=r.url();return f||p(),{sync:function(){d()},listen:function(){return p()},update:function(e){return e?void(g=r.url()):void(r.url()!==g&&(r.url(g),r.replace()))},push:function(e,t,i){var o=e.format(t||{});null!==o&&t&&t["#"]&&(o+="#"+t["#"]),r.url(o),h=i&&i.$$avoidResync?r.url():n,i&&i.replace&&r.replace()},href:function(n,i,o){if(!n.validates(i))return null;var a=e.html5Mode();t.isObject(a)&&(a=a.enabled);var l=n.format(i);if(o=o||{},a||null===l||(l="#"+e.hashPrefix()+l),null!==l&&i&&i["#"]&&(l+="#"+i["#"]),l=s(l,a,o.absolute),!o.absolute||!l)return l;var u=!a&&l?"/":"",c=r.port();return c=80===c||443===c?"":":"+c,[r.protocol(),"://",r.host(),c,u,l].join("")}}}var l,u=[],c=null,f=!1;this.rule=function(e){if(!R(e))throw new Error("'rule' must be a function");return u.push(e),this},this.otherwise=function(e){if(I(e)){var t=e;e=function(){return t}}else if(!R(e))throw new Error("'rule' must be a function");return c=e,this},this.when=function(e,t){var n,s=I(t);if(I(e)&&(e=r.compile(e)),!s&&!R(t)&&!F(t))throw new Error("invalid 'handler' in when()");var l={matcher:function(e,t){return s&&(n=r.compile(t),t=["$match",function(e){return n.format(e)}]),L(function(n,r){return a(n,t,e.exec(r.path(),r.search()))},{prefix:I(e.prefix)?e.prefix:""})},regex:function(e,t){if(e.global||e.sticky)throw new Error("when() RegExp must not be global or sticky");return s&&(n=t,t=["$match",function(e){return o(n,e)}]),L(function(n,r){return a(n,t,e.exec(r.path()))},{prefix:i(e)})}},u={matcher:r.isMatcher(e),regex:e instanceof RegExp};for(var c in u)if(u[c])return this.rule(l[c](e,t));throw new Error("invalid 'what' in when()")},this.deferIntercept=function(e){e===n&&(e=!0),f=e},this.$get=s,s.$inject=["$location","$rootScope","$injector","$browser"]}function w(e,i){function o(e){return 0===e.indexOf(".")||0===e.indexOf("^")}function d(e,t){if(!e)return n;var r=I(e),i=r?e:e.name;if(o(i)){if(!t)throw new Error("No reference point given for path '"+i+"'");t=d(t);for(var a=i.split("."),s=0,l=a.length,u=t;l>s;s++)if(""!==a[s]||0!==s){if("^"!==a[s])break;if(!u.parent)throw new Error("Path '"+i+"' not valid for state '"+t.name+"'");u=u.parent}else u=t;a=a.slice(s).join("."),i=u.name+(u.name&&a?".":"")+a}var c=E[i];return!c||!r&&(r||c!==e&&c.self!==e)?n:c}function p(e,t){S[e]||(S[e]=[]),S[e].push(t)}function m(e){for(var t=S[e]||[];t.length;)g(t.shift())}function g(t){t=r(t,{self:t,resolve:t.resolve||{},toString:function(){return this.name}});var n=t.name;if(!I(n)||n.indexOf("@")>=0)throw new Error("State must have a valid name");if(E.hasOwnProperty(n))throw new Error("State '"+n+"'' is already defined");var i=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):I(t.parent)?t.parent:P(t.parent)&&I(t.parent.name)?t.parent.name:"";if(i&&!E[i])return p(i,t.self);for(var o in M)R(M[o])&&(t[o]=M[o](t,M.$delegates[o]));return E[n]=t,!t[_]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){k.$current.navigable==t&&u(e,n)||k.transitionTo(t,e,{inherit:!0,location:!1})}]),m(n),t}function v(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=k.$current.name.split("."),r=0,i=t.length;i>r;r++)"*"===t[r]&&(n[r]="*");return"**"===t[0]&&(n=n.slice(s(n,t[1])),n.unshift("**")),"**"===t[t.length-1]&&(n.splice(s(n,t[t.length-2])+1,Number.MAX_VALUE),n.push("**")),t.length==n.length&&n.join("")===t.join("")}function b(e,t){return I(e)&&!N(t)?M[e]:R(t)&&I(e)?(M[e]&&!M.$delegates[e]&&(M.$delegates[e]=M[e]),M[e]=t,this):this}function $(e,t){return P(e)?t=e:t.name=e,g(t),this}function w(e,i,o,s,f,p,m,g,b){function $(t,n,r,o){var a=e.$broadcast("$stateNotFound",t,n,r);if(a.defaultPrevented)return m.update(),T;if(!a.retry)return null;if(o.$retry)return m.update(),D;var s=k.transition=i.when(a.retry);return s.then(function(){return s!==k.transition?S:(t.options.$retry=!0,k.transitionTo(t.to,t.toParams,t.options))},function(){return T}),m.update(),s}function w(e,n,r,a,l,u){function d(){var n=[];return j(e.views,function(r,i){var a=r.resolve&&r.resolve!==e.resolve?r.resolve:{};a.$template=[function(){return o.load(i,{view:r,locals:l.globals,params:p,notify:u.notify})||""}],n.push(f.resolve(a,l.globals,l.resolve,e).then(function(n){if(R(r.controllerProvider)||F(r.controllerProvider)){var o=t.extend({},a,l.globals);n.$$controller=s.invoke(r.controllerProvider,null,o)}else n.$$controller=r.controller;n.$$state=e,n.$$controllerAs=r.controllerAs,l[i]=n}))}),i.all(n).then(function(){return l.globals})}var p=r?n:c(e.params.$$keys(),n),h={$stateParams:p};l.resolve=f.resolve(e.resolve,h,l.resolve,e);var m=[l.resolve.then(function(e){l.globals=e})];return a&&m.push(a),i.all(m).then(d).then(function(e){return l})}var S=i.reject(new Error("transition superseded")),M=i.reject(new Error("transition prevented")),T=i.reject(new Error("transition aborted")),D=i.reject(new Error("transition failed"));return C.locals={resolve:null,globals:{$stateParams:{}}},k={params:{},current:C.self,$current:C,transition:null},k.reload=function(e){return k.transitionTo(k.current,p,{reload:e||!0,inherit:!1,notify:!0})},k.go=function(e,t,n){return k.transitionTo(e,t,L({inherit:!0,relative:k.$current},n))},k.transitionTo=function(t,n,o){n=n||{},o=L({location:!0,inherit:!1,relative:null,notify:!0,reload:!1,$retry:!1},o||{});var a,u=k.$current,f=k.params,h=u.path,g=d(t,o.relative),v=n["#"];if(!N(g)){var y={to:t,toParams:n,options:o},b=$(y,u.self,f,o);if(b)return b;if(t=y.to,n=y.toParams,o=y.options,g=d(t,o.relative),!N(g)){if(!o.relative)throw new Error("No such state '"+t+"'");throw new Error("Could not resolve '"+t+"' from state '"+o.relative+"'")}}if(g[_])throw new Error("Cannot transition to abstract state '"+t+"'");if(o.inherit&&(n=l(p,n||{},k.$current,g)),!g.params.$$validates(n))return D;n=g.params.$$values(n),t=g;var E=t.path,T=0,A=E[T],O=C.locals,R=[];if(o.reload){if(I(o.reload)||P(o.reload)){if(P(o.reload)&&!o.reload.name)throw new Error("Invalid reload state object");var F=!0===o.reload?h[0]:d(o.reload);if(o.reload&&!F)throw new Error("No such reload state '"+(I(o.reload)?o.reload:o.reload.name)+"'");for(;A&&A===h[T]&&A!==F;)O=R[T]=A.locals,T++,A=E[T]}}else for(;A&&A===h[T]&&A.ownParams.$$equals(n,f);)O=R[T]=A.locals,T++,A=E[T];if(x(t,n,u,f,O,o))return v&&(n["#"]=v),k.params=n,U(k.params,p),o.location&&t.navigable&&t.navigable.url&&(m.push(t.navigable.url,n,{$$avoidResync:!0,replace:"replace"===o.location}),m.update(!0)),k.transition=null,i.when(k.current);if(n=c(t.params.$$keys(),n||{}),o.notify&&e.$broadcast("$stateChangeStart",t.self,n,u.self,f).defaultPrevented)return e.$broadcast("$stateChangeCancel",t.self,n,u.self,f),m.update(),M;for(var j=i.when(O),H=T;H=T;r--)a=h[r],a.self.onExit&&s.invoke(a.self.onExit,a.self,a.locals.globals),a.locals=null;for(r=T;r=0?i:i+"@"+(o?o.state.name:"")}function _(e,t){var n,r=e.match(/^\s*({[^}]*})\s*$/);if(r&&(e=t+"("+r[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function M(e){var t=e.parent().inheritedData("$uiView");return t&&t.state&&t.state.name?t.state:void 0}function T(e,n){var r=["location","inherit","reload","absolute"];return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(i,o,a,s){var l=_(a.uiSref,e.current.name),u=null,c=M(o)||e.$current,f="[object SVGAnimatedString]"===Object.prototype.toString.call(o.prop("href"))?"xlink:href":"href",d=null,p="A"===o.prop("tagName").toUpperCase(),h="FORM"===o[0].nodeName,m=h?"action":f,g=!0,v={relative:c,inherit:!0},y=i.$eval(a.uiSrefOpts)||{};t.forEach(r,function(e){e in y&&(v[e]=y[e])});var b=function(n){if(n&&(u=t.copy(n)),g){d=e.href(l.state,u,v);var r=s[1]||s[0];return r&&r.$$addStateInfo(l.state,u),null===d?(g=!1,!1):void a.$set(m,d)}};l.paramExpr&&(i.$watch(l.paramExpr,function(e,t){e!==u&&b(e)},!0),u=t.copy(i.$eval(l.paramExpr))),b(),h||o.bind("click",function(t){if(!((t.which||t.button)>1||t.ctrlKey||t.metaKey||t.shiftKey||o.attr("target"))){var r=n(function(){e.go(l.state,u,v)});t.preventDefault();var i=p&&!d?1:0;t.preventDefault=function(){i--<=0&&n.cancel(r)}}})}}}function D(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs",function(t,r,i){function o(){a()?r.addClass(l):r.removeClass(l)}function a(){for(var e=0;er;r++){o=a[r];var c=this.params[o],f=n[r+1];for(i=0;ir;r++)o=a[r],u[o]=this.params[o].value(t[o]);return u},v.prototype.parameters=function(e){return N(e)?this.params[e]||null:this.$$paramNames},v.prototype.validates=function(e){return this.params.$$validates(e)},v.prototype.format=function(e){function t(e){return encodeURIComponent(e).replace(/-/g,function(e){return"%5C%"+e.charCodeAt(0).toString(16).toUpperCase()})}e=e||{};var n=this.segments,r=this.parameters(),i=this.params;if(!this.validates(e))return null;var o,a=!1,s=n.length-1,l=r.length,u=n[0];for(o=0;l>o;o++){var c=s>o,f=r[o],d=i[f],p=d.value(e[f]),m=d.isOptional&&d.type.equals(d.value(),p),g=!!m&&d.squash,v=d.type.encode(p);if(c){var y=n[o+1];if(!1===g)null!=v&&(u+=F(v)?h(v,t).join("-"):encodeURIComponent(v)),u+=y;else if(!0===g){var b=u.match(/\/$/)?/\/?(.*)/:/(.*)/;u+=y.match(b)[1]}else I(g)&&(u+=g+y)}else{if(null==v||m&&!1!==g)continue;F(v)||(v=[v]),v=h(v,encodeURIComponent).join("&"+f+"="),u+=(a?"&":"?")+f+"="+v,a=!0}}return u},y.prototype.is=function(e,t){return!0},y.prototype.encode=function(e,t){return e},y.prototype.decode=function(e,t){return e},y.prototype.equals=function(e,t){return e==t},y.prototype.$subPattern=function(){var e=this.pattern.toString();return e.substr(1,e.length-2)},y.prototype.pattern=/.*/,y.prototype.toString=function(){return"{Type:"+this.name+"}"},y.prototype.$normalize=function(e){return this.is(e)?e:this.decode(e)},y.prototype.$asArray=function(e,t){function r(e,t){function r(e,t){return function(){return e[t].apply(e,arguments)}}function i(e){return F(e)?e:N(e)?[e]:[]}function o(e){switch(e.length){case 0:return n;case 1:return"auto"===t?e[0]:e;default:return e}}function a(e){return!e}function s(e,t){return function(n){n=i(n);var r=h(n,e);return!0===t?0===p(r,a).length:o(r)}}this.encode=s(r(e,"encode")),this.decode=s(r(e,"decode")),this.is=s(r(e,"is"),!0),this.equals=function(e){return function(t,n){var r=i(t),o=i(n);if(r.length!==o.length)return!1;for(var a=0;a=":n(e.from)}:{"<=":n(e.to)}}function o(e){return e.in?{IN:e.in}:{"NOT IN":e.nin}}return{extend:function(t){return e.assign(Object.create(this),t)},compactFilters:function(t){return t?e.pick(t,function(e){return 0===e||!1===e||!!e}):null},processFilters:function(t){return t?(t=this.compactFilters(t),e.transform(t,function(e,t,n){t.from||t.to?e[n]=i(t):t.in||t.nin?e[n]=o(t):e[n]=t},{})):null}}})}),define("common/models/contact-job-role.model",["common/modules/models","common/models/model","common/instances/contact-job-role-instance.instance","common/services/api/contact-job-role-api.api"],function(e){"use strict";e.factory("ContactJobRole",["$log","Model","ContactJobRoleAPI","ContactJobRoleInstance",function(e,t,n,r){return e.debug("ContactJobRole"),t.extend({all:function(e){return n.all(e).then(function(e){return e.list.map(function(e){return r.init(e,!0)})})}})}])}),define("common/models/instances/group-instance",["common/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("GroupInstance",["ModelInstance",function(e){var t=["id","name","title","description"];return e.extend({fromAPIFilter:function(e,n,r){_.includes(t,r)&&(e[r]=this[r])}})}])}),define("common/mocks/module",["common/angular"],function(e){"use strict";return e.module("common.mocks",[])}),define("common/mocks/services/api/group-mock",["common/lodash","common/mocks/module"],function(e,t){"use strict";t.factory("api.group.mock",["$q",function(t){function n(e){var n=t.defer();return n.resolve(e),n.promise}return{all:function(e,t,r){var i,o,a;return i=r||this.mockedGroups().list,e&&(i=i.filter(function(t){return Object.keys(e).every(function(n){return t[n]===e[n]})})),t&&(o=(t.page-1)*t.size,a=o+t.size,i=i.slice(o,a)),n({list:i,total:i.length,allIds:i.map(function(e){return e.id}).join(",")})},find:function(e,t){return n(t||this.mockedGroups().list.filter(function(t){return t.id===e})[0])},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedGroups:function(){return{total:5,list:[{id:"1",name:"Administrators",title:"Administrators",description:"Contacts in this group are assigned Administrator role permissions.",is_active:"1",visibility:"User and User Admin Only",group_type:["1"],is_hidden:"0",is_reserved:"0"},{id:"2",name:"Newsletter Subscribers",title:"Newsletter Subscribers",is_active:'"1',visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"3",name:"Summer Program Volunteers",title:"Summer Program Volunteers",is_active:"1",visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"4",name:"Advisory Board",title:"Advisory Board",is_active:"1",visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"5",name:"Case_Resources",title:"Case Resources",description:"Contacts in this group are listed with their phone number and email when viewing case. You also can send copies of case activities to these contacts.",is_active:"1",visibility:"User and User Admin Only",where_clause:"...",select_tables:"...",where_tables:"...",group_type:"2",is_hidden:"0",is_reserved:"0"}]}}}}])}),define("common/mocks/data/contact.data",[],function(){return{all:{is_error:0,version:3,count:26,values:[{id:"1",contact_id:"1",display_name:"Dr. Kiara Jensen-Parker",email:"kh.jensen-parker@testing.info",contact_type:"Individual"},{id:"2",contact_id:"2",display_name:"jacobc82@lol.co.pl",email:"cruz.v.jacob@spamalot.com",contact_type:"Individual"},{id:"3",contact_id:"3",display_name:"Mei Müller-Nielsen",email:"mz.mller-nielsen75@infomail.co.pl",contact_type:"Individual"},{id:"4",contact_id:"4",display_name:"Ms. Brigette Deforest",email:"deforest.p.brigette9@fakemail.info",contact_type:"Individual"},{id:"5",contact_id:"5",display_name:"robertsc@testing.net",email:"clintr56@mymail.org",contact_type:"Individual"},{id:"6",contact_id:"6",display_name:"Dr. Allen Samuels Sr.",email:"samuelsa@mymail.org",contact_type:"Individual"},{id:"7",contact_id:"7",display_name:"Mei Wilson",email:"wilson.u.mei59@sample.org",contact_type:"Individual"},{id:"8",contact_id:"8",display_name:"Dr. Betty Díaz",email:"dazb@sample.co.nz",contact_type:"Individual"},{id:"9",contact_id:"9",display_name:"Bob Jones-Dimitrov",email:"bobj@testmail.biz",contact_type:"Individual"},{id:"10",contact_id:"10",display_name:"Truman Samuels III",email:"trumans@spamalot.org",contact_type:"Individual"},{id:"11",contact_id:"11",display_name:"Iris Wagner",email:"iwagner75@notmail.info",contact_type:"Individual"},{id:"12",contact_id:"12",display_name:"Mr. Rosario McReynolds",email:"rosariomcreynolds@testmail.org",contact_type:"Individual"},{id:"13",contact_id:"13",display_name:"Shad Jones-Dimitrov III",email:"shadj@lol.net",contact_type:"Individual"},{id:"14",contact_id:"14",display_name:"Toby Cruz Sr.",email:"",contact_type:"Individual"},{id:"15",contact_id:"15",display_name:"lareedaz61@testing.com",email:"lareedaz61@testing.com",contact_type:"Individual"},{id:"16",contact_id:"16",display_name:"Dr. Jay Deforest",email:"jayd@fishmail.org",contact_type:"Individual"},{id:"17",contact_id:"17",display_name:"Mr. Norris Cruz",email:"norriscruz@spamalot.info",contact_type:"Individual"},{id:"18",contact_id:"18",display_name:"herminiac@fishmail.com",email:"herminiac@fishmail.com",contact_type:"Individual"},{id:"19",contact_id:"19",display_name:"Ashley Terrell",email:"terrell.ashley@testmail.info",contact_type:"Individual"},{id:"20",contact_id:"20",display_name:"Kandace Parker-Díaz",email:"parker-daz.kandace67@fishmail.co.uk",contact_type:"Individual"},{id:"21",contact_id:"21",display_name:"Nicole Samuels",email:"ng.samuels@testmail.net",contact_type:"Individual"},{id:"22",contact_id:"22",display_name:"Dr. Kandace Wattson",email:"kandacewattson@testing.info",contact_type:"Individual"},{id:"23",contact_id:"23",display_name:"Brittney Cruz",email:"cruz.brittney@spamalot.co.nz",contact_type:"Individual"},{id:"24",contact_id:"24",display_name:"Shauna Olsen",email:"",contact_type:"Individual"},{id:"202",contact_id:"202",display_name:"civihr_staff@compucorp.co.uk",email:"civihr_staff@compucorp.co.uk",contact_type:"Individual"},{id:"203",contact_id:"203",display_name:"civihr_manager@compucorp.co.uk",email:"civihr_manager@compucorp.co.uk",contact_type:"Individual"}]}}}),define("common/mocks/services/api/contact-mock",["common/lodash","common/mocks/module","common/mocks/data/contact.data"],function(e,t,n){"use strict";t.factory("api.contact.mock",["$q",function(t){function r(e){var n=t.defer();return n.resolve(e),n.promise}return{all:function(t,i,o,a,s){var l,u,c;return l=s||n.all.values,t&&(l=l.filter(function(n){return Object.keys(t).every(function(r){return null===t[r]||("display_name"===r?new RegExp(t[r],"i").test(n[r]):t[r].IN?e.includes(t[r].IN,n[r]):n[r]===t[r])})})),i&&(u=(i.page-1)*i.size,c=u+i.size,l=l.slice(u,c)),r({list:l,total:l.length,allIds:l.map(function(e){return e.id}).join(",")})},find:function(e,t){return r(t||n.all.values.filter(function(t){return t.id===e})[0])},leaveManagees:function(){return r(this.mockedContacts().list)},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedContacts:function(){var e=n.all.values;return{total:e.length,list:e.map(function(e){return e})}}}}])}),define("common/mocks/services/api/group-contact-mock",["common/lodash","common/mocks/module","common/mocks/services/api/contact-mock","common/mocks/services/api/group-mock"],function(e,t){"use strict";t.factory("api.group-contact.mock",["$q","api.contact.mock","api.group.mock",function(t,n,r){function i(t){return e.sample(t)}function o(e){var n=t.defer();return n.resolve(e),n.promise}var a=n.mockedContacts().list,s=r.mockedGroups().list;return{all:function(e,t,n){var r,i,a;return r=n||this.mockedGroupsContacts.list,e&&(r=r.filter(function(t){return Object.keys(e).every(function(n){return t[n]===e[n]})})),t&&(i=(t.page-1)*t.size,a=i+t.size,r=r.slice(i,a)),o({list:r,total:r.length,allIds:r.map(function(e){return e.id}).join(",")})},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedGroupsContacts:{total:a.length,list:function(){var e=1;return a.map(function(t){return{id:""+e++,group_id:i(s).id,contact_id:t.id,status:"Added"}})}()}}}])}),define("common/models/group",["common/modules/models","common/models/model","common/models/instances/group-instance","common/mocks/services/api/group-mock","common/mocks/services/api/group-contact-mock"],function(e){"use strict";e.factory("Group",["Model","api.group.mock","api.group-contact.mock","GroupInstance",function(e,t,n,r){return e.extend({all:function(e,n){return t.all(this.processFilters(e),n).then(function(e){return e.list=e.list.map(function(e){return r.init(e,!0)}),e})},find:function(e){return t.find(e).then(function(e){return r.init(e,!0)})},contactIdsOf:function(e){return n.all({group_id:e}).then(function(e){return e.list.map(function(e){return e.contact_id})})}})}])}),define("common/models/instances/job-role-instance",["common/lodash","common/moment","common/modules/models-instances","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("JobRoleInstance",["ModelInstance","HR_settings",function(n,r){return n.extend({fromAPIFilter:function(n,i,o){var a=r.DATE_FORMAT.toUpperCase();e.endsWith(o,"_date")?n[o]=t(this[o],"YYYY-MM-DD HH:mm:ss").format(a):"api.HRJobContract.getsingle"===o?(n.contact_id=this[o].contact_id,n.job_contract_id=this[o].id):n[o]=this[o]},toAPIFilter:function(n,i,o){var a=["contact_id","job_contract_id"],s=r.DATE_FORMAT.toUpperCase();if(e.endsWith(o,"_date"))n[o]=t(this[o],s).format("YYYY-MM-DD HH:mm:ss");else{if(e.includes(a,o))return;n[o]=this[o]}}})}])}),define("common/services/api/job-role",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.job-role",["$log","api",function(e,t){return e.debug("api.jobRole"),t.extend({all:function(t,n,r,i){return e.debug("api.jobRole.api"),this.getAll("HrJobRoles",t,n,r,i)},find:function(t){return e.debug("api.jobRole.find"),this.sendGET("HRJobRole","get",{id:""+t},!1).then(function(e){return e.values[0]})}})}])}),define("common/models/job-role",["common/modules/models","common/models/model","common/models/instances/job-role-instance","common/services/api/job-role"],function(e){"use strict";e.factory("JobRole",["Model","api.job-role","JobRoleInstance",function(e,t,n){return e.extend({all:function(e,r){return t.all(this.processFilters(e),r).then(function(e){return e.list=e.list.map(function(e){return n.init(e,!0)}),e})},find:function(e){return t.find(e).then(function(e){return n.init(e,!0)})}})}])}),define("common/services/api/contact",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.contact",["$log","api",function(e,t){return e.debug("api.contact"),t.extend({all:function(t,n,r,i){return e.debug("api.contact.api"),this.getAll("Contact",t,n,r,i)},find:function(t){return e.debug("api.contact.find"),this.sendGET("Contact","get",{id:""+t},!1).then(function(e){return e.values[0]})},leaveManagees:function(t,n){return e.debug("api.contact.leaveManagees"),n=_.assign({},n,{managed_by:t}),this.sendGET("Contact","getleavemanagees",n).then(function(e){return e.values})}})}])}),define("common/models/instances/contact-instance",["common/modules/models-instances","common/models/instances/instance","common/services/api/contact"],function(e){"use strict";e.factory("ContactInstance",["ModelInstance","api.contact",function(e,t){return e.extend({leaveManagees:function(e){return t.leaveManagees(this.id,e)}})}])}),define("common/models/contact",["common/lodash","common/modules/models","common/models/model","common/models/contact-job-role.model","common/models/group","common/models/job-role","common/models/instances/contact-instance","common/services/api/contact"],function(e,t){"use strict";t.factory("Contact",["$q","Model","api.contact","Group","JobRole","ContactJobRole","ContactInstance",function(t,n,r,i,o,a,s){function l(t,n){return!e.isEmpty(e.intersection(e.keys(t),n))}function u(e){return a.all(e).then(function(e){return e.map(function(e){return e.contact_id})})}function c(t,n){return e(t).omit(d).omit(p).assign({id:{in:e.intersection.apply(null,n)}}).value()}function f(n){var r=t.defer(),o=[];return n=this.compactFilters(n),l(n,p)&&o.push(u(e.pick(n,p))),l(n,d)&&o.push(i.contactIdsOf(n.group_id)),e.isEmpty(o)?r.resolve(this.processFilters(n)):t.all(o).then(function(e){n=c(n,e),r.resolve(this.processFilters(n))}.bind(this)),r.promise}var d=["group_id"],p=["region","department","level_type","location"];return n.extend({all:function(e,t,n,i){return f.call(this,e).then(function(e){return e&&e.id&&!e.id.IN.length?{list:[]}:r.all(e,t,n,i)}).then(function(e){return e.list=e.list.map(function(e){return s.init(e,!0)}),e})},find:function(e){return r.find(e).then(function(e){return s.init(e,!0)})},leaveManagees:function(e,t){return f.call(this,t).then(function(t){return t&&t.id&&!t.id.IN.length?[]:r.leaveManagees(e,t)})}})}])}),define("common/models/instances/contract-instance",["common/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("ContractInstance",["ModelInstance",function(e){return e.extend({})}])}),define("common/services/api/contract",["common/lodash","common/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("api.contract",["$log","api",function(t,n){function r(t){var n=e.clone(t);return n.info=n["api.HRJobContract.getfulldetails"],delete n["api.HRJobContract.getfulldetails"],n}return t.debug("api.contract"),n.extend({all:function(e){return t.debug("ContractAPI.all"),e=e||{},e["api.HRJobContract.getfulldetails"]={jobcontract_id:"$value.id"},e.deleted=0,this.sendGET("HRJobContract","get",e,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r)})}})}])}),define("common/models/contract",["common/modules/models","common/models/model","common/models/instances/contract-instance","common/services/api/contract"],function(e){"use strict";e.factory("Contract",["$log","Model","api.contract","ContractInstance",function(e,t,n,r){return e.debug("Contract"),t.extend({all:function(e){return n.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})}})}])}),define("common/models/option-group",["common/modules/models","common/models/model","common/services/api/option-group"],function(e){"use strict";e.factory("OptionGroup",["Model","api.optionGroup",function(e,t){return e.extend({valuesOf:function(e,n){return t.valuesOf(e,n)}})}])}),function(e,t){define("common/models/session.model",["common/modules/models","common/models/model"],function(n){"use strict";n.factory("Session",["$log","$q","Model",function(n,r,i){return n.debug("Session"),i.extend({get:function(){var n={contactId:e.vars.session?e.vars.session.contact_id:t.settings.currentCiviCRMUserId};if(!n.contactId)throw new Error("Session Error: *Logged In Contact Id* is not defined");return r.resolve(n)}})}])})}(CRM,window.Drupal),define("common/bundles/models",["common/instances/contact-job-role-instance.instance","common/models/model","common/models/contact","common/models/contact-job-role.model","common/models/contract","common/models/group","common/models/job-role","common/models/option-group","common/models/session.model","common/models/instances/instance","common/models/instances/contact-instance","common/models/instances/contract-instance","common/models/instances/group-instance","common/models/instances/job-role-instance"],function(){}),define("common/services/dialog/dialog",["common/lodash","common/modules/services"],function(e,t){"use strict";function n(t,n,r){function i(i){var o;if(!e.isObject(i))throw new Error("Dialog Service: Options passed should be an object");return o=n.children(),t.open({appendTo:o.length?o.eq(0):n,size:"sm",controller:"DialogController",template:r.get("dialog.html"),resolve:{options:function(){return i}}}).result}return{open:i}}t.factory("dialog",n),n.$inject=["$uibModal","$rootElement","$templateCache"]}),define("common/controllers/dialog/dialog-ctrl",["common/lodash","common/modules/controllers"],function(e,t){"use strict";function n(t,n,r,i){function o(t){e.assign(n,e.defaultsDeep(t,{title:"CiviHR",msg:"",copyConfirm:"",copyCancel:"",classConfirm:"btn-primary",loading:!1}))}function a(){r.close(!1)}function s(){n.loading=!0,r.closed.then(n.onCloseAfterConfirm),t.resolve().then(n.onConfirm).then(function(){r.close(!0)})}n.cancel=a,n.confirm=s,function(){o(i),i.optionsPromise&&i.optionsPromise().then(function(e){o(e)})}()}t.controller("DialogController",n),n.$inject=["$q","$scope","$uibModalInstance","options"]}),define("common/modules/dialog",["common/angular","common/services/dialog/dialog","common/controllers/dialog/dialog-ctrl","common/angularBootstrap","common/directives/loading","common/modules/templates"],function(e){"use strict";return e.module("common.dialog",["ui.bootstrap","common.directives","common.templates"])}),define("common/decorators/xeditable-civi/editable-directive-factory",[],function(){"use strict";return["$delegate",function(e){return function(t){var n=e(t);return n.compile=function(e){var t,r=e[0].attributes.getNamedItem("ng-href");return e.append(''),r&&(t=angular.element(""),t.text("Follow link"),t.attr(r.nodeName,r.value),t.attr("ng-click","$event.stopPropagation();"),t.addClass("editable-link"),e.append(t),e.addClass("editable-with-link")),{post:n.link}},n}}]}),define("common/directives/xeditable-civi/editable-ta",[],function(){"use strict";return["editableDirectiveFactory","$timeout",function(e,t){var n,r;return r=e({directiveName:"editableTa",inputTpl:"",render:function(){this.parent.render.call(this),this.inputEl.parent().parent().removeClass("form-inline"),this.inputEl.addClass("editable-ta"),this.inputEl.attr("ng-model","ta.$data"),this.inputEl.attr("ta-toolbar",this.attrs.eTaToolbar||'[["bold","italics","underline","strikeThrough","ul","ol","undo","redo","clear"]]'),t(function(){this.inputEl.find("textarea").hide()}.bind(this),0)},save:function(){this.scope.$data=this.scope.ta.$data,this.parent.save.call(this)},setLocalValue:function(){this.parent.setLocalValue.call(this),this.scope.ta.$data=this.scope.$data}}),n=r.link,r.link=function(e,t,r,i){return e.ta={},n(e,t,r,i)},r}]}),define("common/modules/xeditable-civi",["common/angular","common/decorators/xeditable-civi/editable-directive-factory","common/directives/xeditable-civi/editable-ta","common/angularXeditable","common/text-angular"],function(e,t,n){"use strict";return e.module("xeditable-civi",["xeditable","textAngular"]).directive("editableTa",n)}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/org.civicrm.reqangular/dist/reqangular.min.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js index 440749a136a..c94be2fb841 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js @@ -1,5 +1,5 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,o){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:t(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,o,s,i){return t.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return s.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,o,s){return t.debug("WorkPatternAPI.getCalendar",n,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,o){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,o,s,i){function r(t,n){return u().then(function(a){var o=this.days[c(t).valueOf()];return!!o&&e.find(a,function(e){return e.name===n}).value===o.type}.bind(this))}function c(e){return t(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[c(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,o){return t.debug("Calendar"),n.extend({get:function(n,s,i,r){return t.debug("Calendar.get"),a.getCalendar(n,s,i,r).then(function(t){var a=t.values.map(function(e){return o.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function o(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,o,s){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return o.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",t,n,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t,n,o,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var i=a.defer();t&&n||i.reject("contact_id and period_id are mandatory");var r={contact_id:t,period_id:n,statuses:o?{IN:o}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",r,!1).then(function(e){i.resolve(e.values)}),i.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?o.reject(t(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(t){return s.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,o&&(i.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return r.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),n.all(t)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(s.permissions.admin.administer).then(function(t){return t?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,o,s,i){return n.all(this.processFilters(e),t,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,o){return n.balanceChangeByAbsenceType(e,t,a,o)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/instances/work-pattern.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("WorkPatternInstance",["$log","ModelInstance",function(e,t){return e.debug("WorkPatternInstance"),t.extend({})}])}),define("leave-absences/shared/models/work-pattern.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/work-pattern.instance"],function(e,t){"use strict";t.factory("WorkPattern",["$log","Model","WorkPatternAPI","WorkPatternInstance",function(t,n,a,o){return t.debug("WorkPattern"),n.extend({assignWorkPattern:function(e,t,n,o,s,i){return a.assignWorkPattern(e,t,n,o,s,i)},default:function(){return a.get({is_default:!0}).then(function(t){return o.init(e.first(t),!0)})},unassignWorkPattern:function(e){return a.unassignWorkPattern(e)},workPatternsOf:function(e,t,n){return a.workPatternsOf(e,t,n).then(function(e){return e.map(function(e){return o.init(e,!0)})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function u(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?c():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return o.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):i.all()}function m(e){return"me"===e?o.leaveManagees(v.contactId):"unassigned"===e?o.leaveManagees(void 0,{unassigned:!0}):o.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){r.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,u()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:i.contactId}).leaveManagees().then(function(e){i.lookupContacts=e}).then(o)}}}function o(){return t.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:i.filters.userSettings.department?i.filters.userSettings.department.value:null,level_type:i.filters.userSettings.level_type?i.filters.userSettings.level_type.value:null,location:i.filters.userSettings.location?i.filters.userSettings.location.value:null,region:i.filters.userSettings.region?i.filters.userSettings.region.value:null,id:{IN:i.filters.userSettings.contact?[i.filters.userSettings.contact.id]:i.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var i;return{init:function(e){return i=e,i.showContactName=!0,i.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function o(a,o,s,i,r,c,u,l,d,m){function f(){for(var e=[],t=n(M.selectedPeriod.start_date).clone().startOf("month"),a=n(M.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(R(t)),t.add(1,"month");M.months=e}function p(){i.$new().$watch(function(){return M.selectedMonths},function(t,n){null===n||e.equals(t,n)||I()})}function h(e){M.injectMonths=!0,S("injected").then(function(){I(e)}).then(function(){M.loading.calendar=!1})}function v(){L=a("LeaveCalendar"+t.capitalize(k)+"Controller").init(M)}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function g(){return c.all().then(function(e){M.absencePeriods=t.sortBy(e,"start_date"),M.selectedPeriod=t.find(M.absencePeriods,function(e){return!!e.current})}).then(f).then(w)}function _(){return u.all().then(u.loadCalculationUnits)}function y(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return L.loadContacts().then(function(e){M.contacts=e})}function C(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){M.filters.optionValues.regions=e.hrjc_region,M.filters.optionValues.locations=e.hrjc_location,M.filters.optionValues.levelTypes=e.hrjc_level_type,M.filters.optionValues.departments=e.hrjc_department})}function D(){return l.all()}function T(){return o.all([_(),D(),y()]).then(function(e){M.supportData.absenceTypes=e[0],M.supportData.publicHolidays=e[1],M.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,M.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,M.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,M.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function P(){var e=o.resolve();return M.injectMonths&&(e=S("destroyed"),M.injectMonths=!1),e}function R(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function A(e){e=t.includes(["contacts","period"],e)?e:"period",o.resolve().then(function(){M.loading.calendar=!0}).then(P).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function I(e){var n=M.selectedMonths.length?M.months.filter(function(e){return t.includes(M.selectedMonths,e.index)}):M.months;i.$emit("LeaveCalendar::showMonths",n,!!e)}function w(){M.selectedMonths=[n().month()]}function O(){return M.roleOverride?o.resolve().then(function(){k=M.roleOverride}):o.all([m(r.permissions.admin.administer),m(r.permissions.ssp.manage)]).then(function(e){k=e[0]?"admin":e[1]?"manager":"staff"})}function S(e){return o(function(n){var a=0,o=i.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===M.months.length&&(o(),n())})})}s.debug("Component: leave-calendar");var L,k,M=this;M.absencePeriods=[],M.contacts=[],M.contactIdsToReduceTo=null,M.injectMonths=!1,M.months=[],M.selectedMonths=null,M.selectedPeriod=null,M.showContactName=!1,M.showFilters=!1,M.supportData={},M.loading={calendar:!0,page:!0},M.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},M.labelPeriod=b,M.refresh=A,function(){O().then(p).then(v).then(P).then(g).then(function(){return o.all([q(),T()])}).then(function(){return M.showFilters?C():t.noop}).then(function(){h()}).then(function(){M.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",o]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,o){"use strict";function s(){y.calculationUnit=i(y.supportData.calculationUnits,"value",b.calculation_unit)}function i(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function r(){var e,n;return n=t(y.contactData.leaveRequest.from_date).isSame(y.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+y.calculationUnit.name+"-on-"+e+"-tooltip"}function c(){b=i(y.supportData.absenceTypes,"id",y.contactData.leaveRequest.type_id),y.contactData.leaveRequest["type_id.title"]=b.title}function u(){"days"===y.calculationUnit.name&&(g=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.from_date_type),_=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.to_date_type),y.contactData.leaveRequest["from_date_type.label"]=g.label,y.contactData.leaveRequest["to_date_type.label"]=_.label)}function l(e,t,n,a,s){e.stopPropagation(),o.openModal(t,n,a,s)}function d(){y.dates.from=new Date(y.contactData.leaveRequest.from_date),y.dates.to=new Date(y.contactData.leaveRequest.to_date)}function m(){y.contactData.isAccruedTOIL?y.label="AT":"days"===y.calculationUnit.name?f():p()}function f(){y.label=y.contactData.isAM?"AM":y.contactData.isPM?"PM":""}function p(){var e=t(y.contactData.leaveRequest.from_date).isSame(y.date,"day"),n=t(y.contactData.leaveRequest.to_date).isSame(y.date,"day");y.label=e?t(y.contactData.leaveRequest.from_date).format("HH:mm"):n?t(y.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){y.tooltipTemplate=y.contactData.isAccruedTOIL?"accrued-toil-tooltip":r()}function v(){a.$watch("day.contactData.leaveRequest",function(){y.contactData&&y.contactData.leaveRequest&&(c(),s(),u(),m(),d(),h()) -})}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(e){_([e]),U(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return j[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){L(e),U(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=P(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){F.push(o.$on("LeaveCalendar::showMonths",$)),F.push(r.subscribe("LeaveRequest::new",u)),F.push(r.subscribe("LeaveRequest::edit",B)),F.push(r.subscribe("LeaveRequest::updatedByManager",B)),F.push(r.subscribe("LeaveRequest::delete",h)),F.push(r.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function D(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function T(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function P(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function R(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function A(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function I(){return[A(c.statusNames.approved),A(c.statusNames.adminApproved),A(c.statusNames.awaitingApproval),A(c.statusNames.moreInformationRequired)]}function w(){return H.month.loading=!0,a.all([S(),O()]).then(b).then(x).then(function(){N=!0}).then(function(){H.month.loading=!1})}function O(){return i.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:I()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function S(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){j=e.indexBy(t,"contact_id")})}function L(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function k(){o.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function M(t,n,o){var s,i;return t.contactsData[n]=t.contactsData[n]||{},i=m(n),s=!0===o?a.resolve():a.all([i.isWeekend(p(t.date)),i.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:D(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?T(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function x(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return M(e,t.id)}))}))}function $(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!N)&&w())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=R(e);t&&(h(t),-1!==I().indexOf(e.status_id)&&u(e))}function U(e){return a.all(P(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],j={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=k,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,i,r,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(i.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=D[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&r.publish("ManagerBadge:: Update Count"),r.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(D,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:D[e].label,isDirectAction:D[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,D={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return r.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,c.serverDateFormat).toDate()}function h(e){return t(e).format(c.serverDateFormat)}function v(e){var t;return i.resolve().then(function(){F(e),"from"===e&&N(),S("hours")&&(_(e),"from"!==e||te.uiOptions.multipleDays||_("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return i.reject("Please change date as it is not in any absence period")}).then(W).then(function(){if(t)return x()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(V(),!t)return E();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(P).finally(y)}function b(){return V(),E()}function g(){return te.uiOptions.toDate=null,F("to"),i.resolve().then(V).then(te.setDaysSelectionModeExtended).then(y).then(!te.uiOptions.multipleDays&&E)}function _(e){te.uiOptions.times[e].loading=!0}function y(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,S("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function C(){return te.request?te.request.request_type:te.leaveType||null}function D(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(j).catch(P)}function P(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function R(){return te.isMode("create")||te.forceRecalculateBalanceChange?E():T()}function A(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():i.resolve()}function I(){ee.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){Q()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){J(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",E))}function w(){te.isMode("edit")&&(te.isLeaveStatus(c.statusNames.approved)||te.isLeaveStatus(c.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function O(){o.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(K(e),V()))})}function S(e){return te.selectedAbsenceType.calculation_unit_name===e}function L(e){return te.request.request_type===e}function k(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function M(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function x(){return u.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function $(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function E(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(j).catch(P).finally(function(){te.loading.balanceChange=!1})):i.resolve()}function B(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function U(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),V(),z()}function j(e){te.balance.change=e,te.request.balance_change=e.amount,f(),B(),te.loading.balanceChange=!1}function W(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function H(){return!te.isMode("create")&&U()||te.isMode("create")&&(L("sickness")||S("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,i.resolve().then(te.setDaysSelectionModeExtended)}function G(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function Y(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function V(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(S("hours")||L("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function X(){e.forEach(ee,function(e){e()})}function Q(){var e,t=te.selectedAbsenceType.calculation_unit_name;return Y(),e=t!==te.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&H).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&V).then(y).then(E)}function J(e){return te.absenceTypes=e,Y(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),G(),E()}function K(e){var t=D(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(D(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(D(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=c.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:$},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:r.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=b,te.daysSelectionModeChangeHandler=g,te.disableAndShowLoadingTimeInput=_,te.getMomentDateWithGivenTime=D,te.handleError=P,te.isCalculationUnit=S,te.isLeaveType=L,te.isNotWorkingDay=k,te.performBalanceChangeCalculation=E,te.setRequestDateTimesAndDateTypes=V,te.updateEndTimeInputMinTime=K,te.$onDestroy=X,function(){n("RequestModalDetails"+e.capitalize(C(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",te),I(),te.initChildController().then(function(){return i.all([x(),M()])}).then(!te.isMode("create")&&A).then(H).then(function(){if(!te.isMode("create"))return i.resolve().then(te.initTimesExtended).then(V)}).then(!te.isMode("create")&&W).then(w).then(G).then(R).then(O).then(!te.isMode("view")&&te.initWatchersExtended).catch(P).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l){function d(){return O.fileUploader&&O.fileUploader.queue.length>0}function m(){return O.getFilesAmount()0?A.map(function(e){return e.label}).join(", "):""}function q(){return O.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(A.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){w[e.label]=t})})).catch(function(){w=null})}function D(){return c.valuesOf("safe_file_extension").then(function(e){A=e})}function T(e){return!e.attachment_id||O.canManage}function P(){e.forEach(I,function(e){e()})}function R(e,t){O.fileUploader.queue&&O.fileUploader.queue.length>0?O.fileUploader.uploadAll({entityID:O.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var A=[],I=[],w={},O=Object.create(this);return O.filesLoaded=!1,O.fileUploader=null,O.today=Date.now(),O.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",O.userDateFormat=i.DATE_FORMAT,O.$onDestroy=P,O.canRemoveAttachment=T,O.canSubmit=d,O.canUploadMore=m,O.formatDateTime=f,O.getAuthorName=p,O.getFilesAmount=h,O.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",O),g(),a.all([D(),q()]).then(_).finally(function(){O.filesLoaded=!0})}(),O}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,o){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],s.openLeavePopup=a,function(){o=n.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,o,s,i,r,c,u,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var t=j[e.status];t?t(e.leaveRequest):W.refresh()}function b(t){t.dataIndex=e.indexBy(t.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return i.all().then(i.loadCalculationUnits).then(function(t){W.absenceTypes=t,W.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return A("approved",{status_id:F(m.statusNames.approved)})}function C(){return n.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function D(){return r.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(t){var n=e.find(W.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function T(){return r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return M(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function P(){return n.all([r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),R({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:M(e[0]),expiredTOILS:x(e[1].list)})}).then(function(t){W.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function R(t){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function A(e,t){return R(t).then(function(t){W.sections[e].data=t.list})}function I(){return n.all(Object.values(W.sections).filter(function(e){return e.open}).map(L))}function w(){return A("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function O(){return A("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function S(){return A("holidays",{public_holiday:!0})}function L(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function k(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){W.leaveRequestStatuses=e.indexBy(t,"value")})}function M(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(W.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function x(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function $(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(W.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],B(t,a))})}function B(e,t){var n=W.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function U(){W.loading.content=!0,n.all([D(),C()]).then(function(){W.loading.content=!1}).then(function(){return n.all([I(),h()])})}function N(e){var t=W.sections[e];t.open=!t.open,t.open&&!t.data.length&&L(t)}function F(t){return e.find(W.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var j={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:T},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:P},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w}},W.labelPeriod=g,W.refresh=U,W.toggleSection=N,function(){n.all([k(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return n.all([D(),C()])}).then(function(){W.loading.content=!1}),$()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report", -controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function u(){var e=i.request,t=!!e.from_date&&!!e.to_date,n=i.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return i.canCalculateChange()}function d(t,n){var a=i.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);i.uiOptions.multipleDays||("from"===t&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=i.convertDateToServerFormat(t),r.isPublicHoliday(t).then(function(n){return n?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,i.requestDayTypes).then(function(t){return t.length?t:i.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return R(n,e),e})):o.reject([])}function f(e,n){return e=t(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return o.resolve()}function v(){return C(i.uiOptions.fromDate,"from").then(function(){return C(i.uiOptions.toDate,"to")})}function b(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,t){i.isCalculationUnit("days")||+e==+t||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function g(e){var n=t(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),i.uiOptions.times[e].time=n}function _(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],t=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(T)).then(function(){["from","to"].forEach(function(e){g(e),I(e),t[e].amount=Math.min(i.request[e+"_date_amount"],t[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function y(){["from","to"].forEach(function(e){b(e),q(e)})}function q(e){s.$watch(function(){return i.uiOptions.times[e].time},function(t,n){i.isCalculationUnit("days")||t===n||(i.setRequestDateTimesAndDateTypes(),t&&I(e,!0))})}function C(e,t){return m(e,t).then(function(){i.loading[t+"DayTypes"]=!1})}function D(e){return C(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return T(e).then(function(){I(e,!0)})})}function T(e){var t=i.uiOptions[e+"Date"],n=!i.uiOptions.multipleDays;return t?i.request.getWorkDayForDate(i.convertDateToServerFormat(t)).then(function(t){S[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return S[e]={},i.handleError(t)}).finally(function(){n&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(t){var n=i.uiOptions.times[t];i["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function R(t,n){var a="request"+e.startCase(t)+"DayTypes";i[a]=n,i.isMode("create")&&(i.request[t+"_date_type"]=i[a][0].value)}function A(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),T("from").then(function(){I("from",!0)})):o.resolve()}function I(e,t){var n=i.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,c=S[a].number_of_hours?p(s,r).toString():"0";o.maxAmount=c,t&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function O(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?T("from").then(function(){I("from",!0)}):o.resolve()}var S={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=c,i.canCalculateChange=u,i.canSubmit=l,i.initChildController=h,i.initDayTypesExtended=v,i.initTimesExtended=_,i.initWatchersExtended=y,i.onAbsenceTypeUpdateExtended=O,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=A}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function i(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function r(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=i,s.initChildController=r,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return r.balance.change.amount=+r.request.toil_to_accrue,a.resolve(r.balance.change)}function u(){if(!r.request.from_date||!r.request.to_date)return r.uiOptions.max_toil_duration_and_accrual=null,void(r.uiOptions.toil_duration_in_hours=null);r.uiOptions.max_toil_duration_and_accrual=t.duration(t(r.request.to_date).diff(r.request.from_date)).asHours()}function l(){return h().catch(function(e){return e.length&&(r.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(r.request.type_id,e)}).then(function(e){return r.request.toil_expiry_date=e,r.uiOptions.expiryDate=new Date(e),e})}function d(){return!!r.request.toil_to_accrue}function m(){var e=r.uiOptions.multipleDays&&!!r.request.to_date,t=!r.uiOptions.multipleDays&&!!r.request.from_date,n=t||e,a=x.from_date!==r.request.from_date||x.to_date!==r.request.to_date;return r.canDisplayToilExpirationField&&n&&E.hasExpirationFromAdminSettings&&a}function f(){return!!(r.request.from_date&&r.request.to_date&&r.request.toil_duration&&r.request.toil_to_accrue)}function p(){r.request.toil_expiry_date=!1,r.uiOptions.expiryDate=null}function h(){var e=r.uiOptions.multipleDays,t=r.request;return v({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function v(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=r.isMode("create")&&E.hasExpirationFromAdminSettings,t=E.hasPreviousExpirationDate,n=r.isLeaveType("toil"),a=r.canManage;r.canDisplayToilExpirationField=n&&(a||e||t)}function g(){r.uiOptions.toil_duration_in_hours=r.request.toil_duration/60}function _(){return E.hasPreviousExpirationDate=r.isMode("edit")&&!!r.request.toil_expiry_date,i.canExpire(r.request.type_id).then(function(e){E.hasExpirationFromAdminSettings=e})}function y(){return r.request.to_date_type=r.request.from_date_type="1",_().then(b).then(q).then(A)}function q(){r.canManage&&(r.uiOptions.expiryDate=r.convertDateFormatFromServer(r.request.toil_expiry_date))}function C(){o.$watch(function(){return r.request.toil_to_accrue},function(e,t){+e!=+t&&r.performBalanceChangeCalculation()})}function D(){o.$watch(function(){return r.uiOptions.toil_duration_in_hours},function(e,t){r.isCalculationUnit("hours")&&e!==t&&(r.request.toil_to_accrue=r.uiOptions.toil_duration_in_hours),r.request.toil_duration=r.uiOptions.toil_duration_in_hours?60*r.uiOptions.toil_duration_in_hours:null})}function T(){var e=r.uiOptions.times;e.from.time=t(r.request.from_date).format("HH:mm"),e.to.time=t(r.request.to_date).format("HH:mm"),r.uiOptions.multipleDays||r.updateEndTimeInputMinTime(r.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){o.$watch(function(){return r.uiOptions.times[e].time},function(e,t){e!==t&&(r.setRequestDateTimesAndDateTypes(),k(),u(),O())})})}function R(){r.isMode("view")||(C(),D(),P())}function A(){return s.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){r.toilAmounts=e.sortBy(t,"value")})}function I(){return u(),O(),k()}function w(){return L(),r.uiOptions.multipleDays||r.updateEndTimeInputMinTime(r.uiOptions.times.from.time),u(),$?$=!1:O(),k()}function O(){r.uiOptions.toil_duration_in_hours=r.uiOptions.max_toil_duration_and_accrual}function S(){x=e.cloneDeep(r.request.attributes())}function L(){r.uiOptions.multipleDays?["from","to"].forEach(function(e){r.uiOptions.times[e].min="00:00",r.uiOptions.times[e].max="23:45"}):(r.uiOptions.times.from.min="00:00",r.uiOptions.times.from.max="23:30",r.uiOptions.times.to.min="00:15",r.uiOptions.times.to.max="23:45")}function k(){return m()?l().catch(a.resolve):a.resolve()}function M(){r.uiOptions.expiryDate&&(r.request.toil_expiry_date=r.convertDateToServerFormat(r.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var x,$=!r.isMode("create"),E={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};r.canDisplayToilExpirationField=!1,r.calculateBalanceChange=c,r.canCalculateChange=d,r.canSubmit=f,r.clearExpiryDate=p,r.initChildController=y,r.initTimesExtended=T,r.initWatchersExtended=R,r.onDateChangeExtended=I,r.setDaysSelectionModeExtended=w,r.updateExpiryDate=M,function(){S(),L(),!r.isMode("create")&&g()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,D){function T(e){"days"===xe.selectedAbsenceType.calculation_unit_name?delete xe.request[e+"_date_amount"]:delete xe.request[e+"_date_type"]}function P(){["from","to"].forEach(T)}function R(){var e=xe.requestStatuses[y.statusNames.awaitingApproval].value;we.status_id===e&&e!==xe.request.status_id&&d.publish("ManagerBadge:: Update Count")}function A(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!xe.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function O(){var e=A();return xe.isMode("edit")&&(e=e&&(G()||I())),xe.canManage&&xe.requestStatuses&&(e=e&&!!xe.getStatusFromValue(xe.newStatusOnSave)),(e=e&&!!xe.period.id)&&!xe.isMode("view")}function S(){xe.isSelfRecord?xe.request.status_id=xe.requestStatuses[y.statusNames.awaitingApproval].value:xe.canManage&&(xe.request.status_id=xe.newStatusOnSave||xe.request.status_id)}function L(){if(xe.isMode("edit")&&!xe.isRole("staff")&&"toil"!==F())return xe.request.calculateBalanceChange(xe.selectedAbsenceType.calculation_unit_name).then(function(e){if(+xe.balance.change.amount!=+e.amount)return D.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function k(){xe.errors=[]}function M(){return xe.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function x(){ee()&&!xe.isRole("staff")&&(xe.request.change_balance=!0)}function $(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return xe.request.delete().then(function(){xe.dismissModal(),d.publish("LeaveRequest::delete",xe.request)})}})}function E(){r.dismiss({$value:"cancel"})}function B(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return N(xe.getStatusFromValue(xe.request.status_id).name)}function N(e){return n.map(Ae[e],function(e){return xe.requestStatuses[e]})}function F(){return xe.request?xe.request.request_type:xe.leaveType||null}function j(){return!xe.request||e.equals({},xe.requestStatuses)?[]:xe.request.status_id?U():N("none")}function W(e){return n.find(xe.requestStatuses,function(t){return t.value===e})}function H(e){xe.errors=n.isArray(e)?e:[e],xe.loading.absenceTypes=!1,xe.submitting=!1}function G(){return!e.equals(we,xe.request.attributes())||xe.canManage&&xe.newStatusOnSave}function Y(){return xe.postContactSelection=!0,xe.staffMemberSelectionComplete=!1,xe.request.contact_id?o.resolve().then(re).then(ce).then(he).then(be).then(Z).then(z).then(xe.isMode("edit")?ge:n.noop).then(function(){xe.postContactSelection=!1,xe.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Le)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Ae.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Ae.awaiting_approval=e,Ae.more_information_required=e,Ae.rejected=e,Ae.approved=e,Ae.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return xe.canManage?f.find(xe.request.contact_id).then(function(e){xe.contactName=e.display_name}):o.resolve()}function X(){Oe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",xe.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Ie++})),i.$on("$destroy",De),i.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function Q(){var e,t;xe.request=xe.leaveRequest||null,e=F(),t=xe.initRequestAttributes(),"leave"===e?xe.request=_.init(t):"sickness"===e?xe.request=q.init(t):"toil"===e&&(xe.request=C.init(t))}function J(){var e={};return xe.request?e=xe.request.attributes():xe.canManage||(e={contact_id:Se}),e}function K(){if(ke="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(ke="admin")}).then(function(){return"staff"===ke&&c(y.permissions.ssp.manage).then(function(e){e&&(ke="manager")})}).finally(function(){xe.canManage=xe.isRole("manager")||xe.isRole("admin")})}function Z(){(xe.isRole("admin")||xe.isMode("create")&&xe.isRole("manager"))&&(xe.newStatusOnSave=xe.requestStatuses[y.statusNames.approved].value)}function ee(){return!xe.request.status_id||!n.includes(["cancelled","rejected"],W(xe.request.status_id).name)}function te(e){var t=xe.getStatusFromValue(xe.request.status_id);return!!t&&t.name===e}function ne(e){return xe.request&&xe.request.request_type===e}function ae(e){return xe.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return ke===e}function ie(){return h.all().then(function(e){xe.absencePeriods=e})}function re(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Re={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return xe.loading.entitlements=!0,b.all({contact_id:xe.request.contact_id,period_id:xe.period.id,type_id:{IN:Re.ids}},!0).finally(function(){xe.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Se=e.contactId})}function le(){return xe.selectedContactId?f.find(xe.selectedContactId).then(function(e){xe.managedContacts=[e]}):xe.isRole("admin")?f.all().then(function(e){xe.managedContacts=n.remove(e.list,function(e){return e.id!==Se})}):f.find(Se).then(function(e){return e.leaveManagees()}).then(function(e){xe.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){xe.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){R(),d.publish(e,xe.request),xe.errors=[],xe.dismissModal()}function pe(){["from","to"].forEach(function(e){xe.request[e+"_date"]=we[e+"_date"]})}function he(e){if(xe.absenceTypes=me(Re.types,e),!xe.absenceTypes.length)return o.reject(Le)}function ve(){xe.period=n.find(xe.absencePeriods,function(e){return xe.isMode("create")?e.current:oe(xe.request,e)})}function be(){xe.isMode("create")?(xe.selectedAbsenceType=xe.absenceTypes[0],xe.request.type_id=xe.selectedAbsenceType.id):xe.selectedAbsenceType=n.find(xe.absenceTypes,function(e){return e.id===xe.request.type_id})}function ge(){we=e.copy(xe.request.attributes())}function _e(){var e;xe.request.id?(e=[xe.requestStatuses[y.statusNames.approved].value,xe.requestStatuses[y.statusNames.adminApproved].value,xe.requestStatuses[y.statusNames.rejected].value,xe.requestStatuses[y.statusNames.cancelled].value],xe.mode="edit",xe.isRole("staff")&&e.indexOf(xe.request.status_id)>-1&&(xe.mode="view")):xe.mode="create"}function ye(){var e=xe.request.status_id;if(!xe.isMode("view")&&!xe.submitting)return xe.submitting=!0,S(),P(),xe.request.isValid().then(ee()&&L).then(x).then(!xe.request.change_balance&&pe).then(qe).then(function(){return xe.isMode("edit")?Pe():M()}).catch(function(t){xe.request.status_id=e,t&&H(t)}).finally(function(){xe.submitting=!1})}function qe(){return o.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===Ie&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return Ie>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function De(){Oe.forEach(function(e){e()})}function Te(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Pe(){return xe.request.update().then(Ce).then(function(){xe.isRole("manager")?fe("LeaveRequest::updatedByManager"):(xe.isRole("staff")||xe.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Re,Ae={},Ie=0,we={},Oe=[],Se="",Le="No entitlement",ke="",Me=[],xe=n.assign(this,m);xe.absencePeriods=[],xe.absenceTypes=[],xe.canManage=!1,xe.contactName=null,xe.errors=[],xe.loading={absenceTypes:!0,entitlements:!0},xe.managedContacts=[],xe.mode="",xe.newStatusOnSave=null,xe.period={},xe.postContactSelection=!1,xe.requestStatuses={},xe.selectedAbsenceType={},xe.staffMemberSelectionComplete=!1,xe.submitting=!1,xe.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},xe.canChangeAbsenceType=w,xe.canSubmit=O,xe.closeAlert=k,xe.deleteLeaveRequest=$,xe.dismissModal=E,xe.getStatuses=j,xe.getStatusFromValue=W,xe.initAfterContactSelection=Y,xe.initRequestAttributes=J,xe.isLeaveStatus=te,xe.isLeaveType=ne,xe.isMode=ae,xe.isRole=se,xe.submit=ye,xe.updateAbsenceType=Te,function(){xe.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),ie(),de()]).then(Q).then(_e).then(ve).then(function(){return xe.canManage&&!xe.isMode("edit")&&le()}).then(function(){if(xe.selectedContactId&&(xe.request.contact_id=xe.selectedContactId),xe.request.contact_id)return xe.initAfterContactSelection()}).catch(H).finally(function(){xe.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,i,r,c){function u(e){return r.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,i,r){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:i,forceRecalculateBalanceChange:r}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,i){function r(e){l.errorMessage=e}function c(){return i.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrjc_revision_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,i.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(r).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrjc_revision_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(),g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){r.open({title:"Confirm Deletion?",copyCancel:"Cancel", -copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){i.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i){function r(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,i){n=o.entitlements.slice(0,i),a=e.entitlements.slice(i+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,i;return s=e.indexBy(n,"entitlement_id.type_id"),i=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:i}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t];e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,i){o.comment&&(t=s.concat(o).concat(i),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(r).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,i,r,c,u,l,d){function m(){D.absencePeriods=t.chain(D.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){D.absenceTypes=t.filter(D.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:D.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:D.contactId,returnUrl:n})}function h(){return c.all().then(function(e){D.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:D.contactId}).then(function(e){q=e})}function g(e){i.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=D.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){D.absencePeriods=t.map(D.absencePeriods,function(e){var n=t.map(D.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

    Last updated:
    By: "+e.author_name+"
    Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
    ";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],D=this;D.absencePeriods=[],D.loading={absencePeriods:!0},D.getEditEntitlementsPageURL=p,D.openAnnualEntitlementChangeLog=g,D.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){D.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i,r){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return i.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){r.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); +})}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(e){_([e]),U(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return j[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){L(e),U(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=P(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){N.push(o.$on("LeaveCalendar::showMonths",$)),N.push(r.subscribe("LeaveRequest::new",u)),N.push(r.subscribe("LeaveRequest::edit",B)),N.push(r.subscribe("LeaveRequest::updatedByManager",B)),N.push(r.subscribe("LeaveRequest::delete",h)),N.push(r.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function D(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function T(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function P(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function R(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function A(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function I(){return[A(c.statusNames.approved),A(c.statusNames.adminApproved),A(c.statusNames.awaitingApproval),A(c.statusNames.moreInformationRequired)]}function w(){return H.month.loading=!0,a.all([S(),O()]).then(b).then(x).then(function(){F=!0}).then(function(){H.month.loading=!1})}function O(){return i.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:I()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function S(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){j=e.indexBy(t,"contact_id")})}function L(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function k(){o.$emit("LeaveCalendar::monthDestroyed"),N.map(function(e){e.remove?e.remove():e()})}function M(t,n,o){var s,i;return t.contactsData[n]=t.contactsData[n]||{},i=m(n),s=!0===o?a.resolve():a.all([i.isWeekend(p(t.date)),i.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:D(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?T(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function x(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return M(e,t.id)}))}))}function $(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!F)&&w())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=R(e);t&&(h(t),-1!==I().indexOf(e.status_id)&&u(e))}function U(e){return a.all(P(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var F=!1,N=[],j={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=k,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,i,r,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(i.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=D[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&r.publish("ManagerBadge:: Update Count"),r.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(D,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:D[e].label,isDirectAction:D[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,D={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return r.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,c.serverDateFormat).toDate()}function h(e){return t(e).format(c.serverDateFormat)}function v(e){var t;return i.resolve().then(function(){N(e),"from"===e&&F(),S("hours")&&(_(e),"from"!==e||te.uiOptions.multipleDays||_("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return i.reject("Please change date as it is not in any absence period")}).then(W).then(function(){if(t)return x()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(V(),!t)return E();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(P).finally(y)}function b(){return V(),E()}function g(){return te.uiOptions.toDate=null,N("to"),i.resolve().then(V).then(te.setDaysSelectionModeExtended).then(y).then(!te.uiOptions.multipleDays&&E)}function _(e){te.uiOptions.times[e].loading=!0}function y(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,S("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function C(){return te.request?te.request.request_type:te.leaveType||null}function D(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(j).catch(P)}function P(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function R(){return te.isMode("create")||te.forceRecalculateBalanceChange?E():T()}function A(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():i.resolve()}function I(){ee.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){Q()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){J(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",E))}function w(){te.isMode("edit")&&(te.isLeaveStatus(c.statusNames.approved)||te.isLeaveStatus(c.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function O(){o.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(K(e),V()))})}function S(e){return te.selectedAbsenceType.calculation_unit_name===e}function L(e){return te.request.request_type===e}function k(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function M(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function x(){return u.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function $(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function E(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(j).catch(P).finally(function(){te.loading.balanceChange=!1})):i.resolve()}function B(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function U(){return h(te.request.from_date)===h(te.request.to_date)}function F(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,N("to"))}function N(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),V(),z()}function j(e){te.balance.change=e,te.request.balance_change=e.amount,f(),B(),te.loading.balanceChange=!1}function W(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function H(){return!te.isMode("create")&&U()||te.isMode("create")&&(L("sickness")||S("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,i.resolve().then(te.setDaysSelectionModeExtended)}function G(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function Y(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function V(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(S("hours")||L("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function X(){e.forEach(ee,function(e){e()})}function Q(){var e,t=te.selectedAbsenceType.calculation_unit_name;return Y(),e=t!==te.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&H).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&V).then(y).then(E)}function J(e){return te.absenceTypes=e,Y(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,N("to")),G(),E()}function K(e){var t=D(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(D(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(D(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=c.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:$},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:r.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=b,te.daysSelectionModeChangeHandler=g,te.disableAndShowLoadingTimeInput=_,te.getMomentDateWithGivenTime=D,te.handleError=P,te.isCalculationUnit=S,te.isLeaveType=L,te.isNotWorkingDay=k,te.performBalanceChangeCalculation=E,te.setRequestDateTimesAndDateTypes=V,te.updateEndTimeInputMinTime=K,te.$onDestroy=X,function(){n("RequestModalDetails"+e.capitalize(C(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",te),I(),te.initChildController().then(function(){return i.all([x(),M()])}).then(!te.isMode("create")&&A).then(H).then(function(){if(!te.isMode("create"))return i.resolve().then(te.initTimesExtended).then(V)}).then(!te.isMode("create")&&W).then(w).then(G).then(R).then(O).then(!te.isMode("view")&&te.initWatchersExtended).catch(P).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l){function d(){return O.fileUploader&&O.fileUploader.queue.length>0}function m(){return O.getFilesAmount()0?A.map(function(e){return e.label}).join(", "):""}function q(){return O.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(A.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){w[e.label]=t})})).catch(function(){w=null})}function D(){return c.valuesOf("safe_file_extension").then(function(e){A=e})}function T(e){return!e.attachment_id||O.canManage}function P(){e.forEach(I,function(e){e()})}function R(e,t){O.fileUploader.queue&&O.fileUploader.queue.length>0?O.fileUploader.uploadAll({entityID:O.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var A=[],I=[],w={},O=Object.create(this);return O.filesLoaded=!1,O.fileUploader=null,O.today=Date.now(),O.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",O.userDateFormat=i.DATE_FORMAT,O.$onDestroy=P,O.canRemoveAttachment=T,O.canSubmit=d,O.canUploadMore=m,O.formatDateTime=f,O.getAuthorName=p,O.getFilesAmount=h,O.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",O),g(),a.all([D(),q()]).then(_).finally(function(){O.filesLoaded=!0})}(),O}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,o){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],s.openLeavePopup=a,function(){o=n.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,o,s,i,r,c,u,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var t=j[e.status];t?t(e.leaveRequest):W.refresh()}function b(t){t.dataIndex=e.indexBy(t.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return i.all().then(i.loadCalculationUnits).then(function(t){W.absenceTypes=t,W.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return A("approved",{status_id:N(m.statusNames.approved)})}function C(){return n.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[N(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[N(m.statusNames.awaitingApproval),N(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function D(){return r.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(t){var n=e.find(W.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function T(){return r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return M(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function P(){return n.all([r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),R({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:M(e[0]),expiredTOILS:x(e[1].list)})}).then(function(t){W.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function R(t){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function A(e,t){return R(t).then(function(t){W.sections[e].data=t.list})}function I(){return n.all(Object.values(W.sections).filter(function(e){return e.open}).map(L))}function w(){return A("other",{status_id:{in:[N(m.statusNames.rejected),N(m.statusNames.cancelled)]}})}function O(){return A("pending",{status_id:{in:[N(m.statusNames.awaitingApproval),N(m.statusNames.moreInformationRequired)]}})}function S(){return A("holidays",{public_holiday:!0})}function L(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function k(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){W.leaveRequestStatuses=e.indexBy(t,"value")})}function M(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(W.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function x(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function $(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(W.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],B(t,a))})}function B(e,t){var n=W.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function U(){W.loading.content=!0,n.all([D(),C()]).then(function(){W.loading.content=!1}).then(function(){return n.all([I(),h()])})}function F(e){var t=W.sections[e];t.open=!t.open,t.open&&!t.data.length&&L(t)}function N(t){return e.find(W.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var j={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:T},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:P},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w}},W.labelPeriod=g,W.refresh=U,W.toggleSection=F,function(){n.all([k(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return n.all([D(),C()])}).then(function(){W.loading.content=!1}),$()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report", +controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function u(){var e=i.request,t=!!e.from_date&&!!e.to_date,n=i.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return i.canCalculateChange()}function d(t,n){var a=i.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);i.uiOptions.multipleDays||("from"===t&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=i.convertDateToServerFormat(t),r.isPublicHoliday(t).then(function(n){return n?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,i.requestDayTypes).then(function(t){return t.length?t:i.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return R(n,e),e})):o.reject([])}function f(e,n){return e=t(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return o.resolve()}function v(){return C(i.uiOptions.fromDate,"from").then(function(){return C(i.uiOptions.toDate,"to")})}function b(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,t){i.isCalculationUnit("days")||+e==+t||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function g(e){var n=t(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),i.uiOptions.times[e].time=n}function _(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],t=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(T)).then(function(){["from","to"].forEach(function(e){g(e),I(e),t[e].amount=Math.min(i.request[e+"_date_amount"],t[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function y(){["from","to"].forEach(function(e){b(e),q(e)})}function q(e){s.$watch(function(){return i.uiOptions.times[e].time},function(t,n){i.isCalculationUnit("days")||t===n||(i.setRequestDateTimesAndDateTypes(),t&&I(e,!0))})}function C(e,t){return m(e,t).then(function(){i.loading[t+"DayTypes"]=!1})}function D(e){return C(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return T(e).then(function(){I(e,!0)})})}function T(e){var t=i.uiOptions[e+"Date"],n=!i.uiOptions.multipleDays;return t?i.request.getWorkDayForDate(i.convertDateToServerFormat(t)).then(function(t){S[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return S[e]={},i.handleError(t)}).finally(function(){n&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(t){var n=i.uiOptions.times[t];i["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function R(t,n){var a="request"+e.startCase(t)+"DayTypes";i[a]=n,i.isMode("create")&&(i.request[t+"_date_type"]=i[a][0].value)}function A(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),T("from").then(function(){I("from",!0)})):o.resolve()}function I(e,t){var n=i.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,c=S[a].number_of_hours?p(s,r).toString():"0";o.maxAmount=c,t&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function O(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?T("from").then(function(){I("from",!0)}):o.resolve()}var S={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=c,i.canCalculateChange=u,i.canSubmit=l,i.initChildController=h,i.initDayTypesExtended=v,i.initTimesExtended=_,i.initWatchersExtended=y,i.onAbsenceTypeUpdateExtended=O,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=A}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function i(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function r(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=i,s.initChildController=r,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=t.duration(t(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,t=!c.uiOptions.multipleDays&&!!c.request.from_date,n=t||e,a=E.from_date!==c.request.from_date||E.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&n&&U.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,t=c.request;return b({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function b(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&U.hasExpirationFromAdminSettings,t=U.hasPreviousExpirationDate,n=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=n&&(a||e||t)}function _(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function y(){return U.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){U.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",y().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function D(){o.$watch(function(){return c.request.toil_to_accrue},function(e,t){+e!=+t&&c.performBalanceChangeCalculation()})}function T(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,t){c.isCalculationUnit("hours")&&e!==t&&(c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function P(){var e=c.uiOptions.times;e.from.time=t(c.request.from_date).format("HH:mm"),e.to.time=t(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,t){e!==t&&(c.setRequestDateTimesAndDateTypes(),x(),l(),S())})})}function A(){c.isMode("view")||(D(),T(),R())}function I(){return i.valuesOf("hrleaveandabsences_toil_amounts",{},!1).then(function(t){c.toilAmounts=e.sortBy(t,"value")})}function w(){return l(),S(),x()}function O(){return k(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),B?B=!1:S(),x()}function S(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function L(){E=e.cloneDeep(c.request.attributes())}function k(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function M(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",I)}function x(){return f()?d().catch(a.resolve):a.resolve()}function $(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var E,B=!c.isMode("create"),U={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=P,c.initWatchersExtended=A,c.onDateChangeExtended=w,c.openToilInDaysAccrualOptionsEditor=M,c.setDaysSelectionModeExtended=O,c.updateExpiryDate=$,function(){L(),k(),!c.isMode("create")&&_()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,D){function T(e){"days"===xe.selectedAbsenceType.calculation_unit_name?delete xe.request[e+"_date_amount"]:delete xe.request[e+"_date_type"]}function P(){["from","to"].forEach(T)}function R(){var e=xe.requestStatuses[y.statusNames.awaitingApproval].value;we.status_id===e&&e!==xe.request.status_id&&d.publish("ManagerBadge:: Update Count")}function A(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!xe.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function O(){var e=A();return xe.isMode("edit")&&(e=e&&(G()||I())),xe.canManage&&xe.requestStatuses&&(e=e&&!!xe.getStatusFromValue(xe.newStatusOnSave)),(e=e&&!!xe.period.id)&&!xe.isMode("view")}function S(){xe.isSelfRecord?xe.request.status_id=xe.requestStatuses[y.statusNames.awaitingApproval].value:xe.canManage&&(xe.request.status_id=xe.newStatusOnSave||xe.request.status_id)}function L(){if(xe.isMode("edit")&&!xe.isRole("staff")&&"toil"!==N())return xe.request.calculateBalanceChange(xe.selectedAbsenceType.calculation_unit_name).then(function(e){if(+xe.balance.change.amount!=+e.amount)return D.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function k(){xe.errors=[]}function M(){return xe.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function x(){ee()&&!xe.isRole("staff")&&(xe.request.change_balance=!0)}function $(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return xe.request.delete().then(function(){xe.dismissModal(),d.publish("LeaveRequest::delete",xe.request)})}})}function E(){r.dismiss({$value:"cancel"})}function B(){var e=N();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return F(xe.getStatusFromValue(xe.request.status_id).name)}function F(e){return n.map(Ae[e],function(e){return xe.requestStatuses[e]})}function N(){return xe.request?xe.request.request_type:xe.leaveType||null}function j(){return!xe.request||e.equals({},xe.requestStatuses)?[]:xe.request.status_id?U():F("none")}function W(e){return n.find(xe.requestStatuses,function(t){return t.value===e})}function H(e){xe.errors=n.isArray(e)?e:[e],xe.loading.absenceTypes=!1,xe.submitting=!1}function G(){return!e.equals(we,xe.request.attributes())||xe.canManage&&xe.newStatusOnSave}function Y(){return xe.postContactSelection=!0,xe.staffMemberSelectionComplete=!1,xe.request.contact_id?o.resolve().then(re).then(ce).then(he).then(be).then(Z).then(z).then(xe.isMode("edit")?ge:n.noop).then(function(){xe.postContactSelection=!1,xe.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Le)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Ae.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Ae.awaiting_approval=e,Ae.more_information_required=e,Ae.rejected=e,Ae.approved=e,Ae.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return xe.canManage?f.find(xe.request.contact_id).then(function(e){xe.contactName=e.display_name}):o.resolve()}function X(){Oe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",xe.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Ie++})),i.$on("$destroy",De),i.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function Q(){var e,t;xe.request=xe.leaveRequest||null,e=N(),t=xe.initRequestAttributes(),"leave"===e?xe.request=_.init(t):"sickness"===e?xe.request=q.init(t):"toil"===e&&(xe.request=C.init(t))}function J(){var e={};return xe.request?e=xe.request.attributes():xe.canManage||(e={contact_id:Se}),e}function K(){if(ke="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(ke="admin")}).then(function(){return"staff"===ke&&c(y.permissions.ssp.manage).then(function(e){e&&(ke="manager")})}).finally(function(){xe.canManage=xe.isRole("manager")||xe.isRole("admin")})}function Z(){(xe.isRole("admin")||xe.isMode("create")&&xe.isRole("manager"))&&(xe.newStatusOnSave=xe.requestStatuses[y.statusNames.approved].value)}function ee(){return!xe.request.status_id||!n.includes(["cancelled","rejected"],W(xe.request.status_id).name)}function te(e){var t=xe.getStatusFromValue(xe.request.status_id);return!!t&&t.name===e}function ne(e){return xe.request&&xe.request.request_type===e}function ae(e){return xe.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return ke===e}function ie(){return h.all().then(function(e){xe.absencePeriods=e})}function re(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Re={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return xe.loading.entitlements=!0,b.all({contact_id:xe.request.contact_id,period_id:xe.period.id,type_id:{IN:Re.ids}},!0).finally(function(){xe.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Se=e.contactId})}function le(){return xe.selectedContactId?f.find(xe.selectedContactId).then(function(e){xe.managedContacts=[e]}):xe.isRole("admin")?f.all().then(function(e){xe.managedContacts=n.remove(e.list,function(e){return e.id!==Se})}):f.find(Se).then(function(e){return e.leaveManagees()}).then(function(e){xe.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){xe.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){R(),d.publish(e,xe.request),xe.errors=[],xe.dismissModal()}function pe(){["from","to"].forEach(function(e){xe.request[e+"_date"]=we[e+"_date"]})}function he(e){if(xe.absenceTypes=me(Re.types,e),!xe.absenceTypes.length)return o.reject(Le)}function ve(){xe.period=n.find(xe.absencePeriods,function(e){return xe.isMode("create")?e.current:oe(xe.request,e)})}function be(){xe.isMode("create")?(xe.selectedAbsenceType=xe.absenceTypes[0],xe.request.type_id=xe.selectedAbsenceType.id):xe.selectedAbsenceType=n.find(xe.absenceTypes,function(e){return e.id===xe.request.type_id})}function ge(){we=e.copy(xe.request.attributes())}function _e(){var e;xe.request.id?(e=[xe.requestStatuses[y.statusNames.approved].value,xe.requestStatuses[y.statusNames.adminApproved].value,xe.requestStatuses[y.statusNames.rejected].value,xe.requestStatuses[y.statusNames.cancelled].value],xe.mode="edit",xe.isRole("staff")&&e.indexOf(xe.request.status_id)>-1&&(xe.mode="view")):xe.mode="create"}function ye(){var e=xe.request.status_id;if(!xe.isMode("view")&&!xe.submitting)return xe.submitting=!0,S(),P(),xe.request.isValid().then(ee()&&L).then(x).then(!xe.request.change_balance&&pe).then(qe).then(function(){return xe.isMode("edit")?Pe():M()}).catch(function(t){xe.request.status_id=e,t&&H(t)}).finally(function(){xe.submitting=!1})}function qe(){return o.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===Ie&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return Ie>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function De(){Oe.forEach(function(e){e()})}function Te(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Pe(){return xe.request.update().then(Ce).then(function(){xe.isRole("manager")?fe("LeaveRequest::updatedByManager"):(xe.isRole("staff")||xe.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Re,Ae={},Ie=0,we={},Oe=[],Se="",Le="No entitlement",ke="",Me=[],xe=n.assign(this,m);xe.absencePeriods=[],xe.absenceTypes=[],xe.canManage=!1,xe.contactName=null,xe.errors=[],xe.loading={absenceTypes:!0,entitlements:!0},xe.managedContacts=[],xe.mode="",xe.newStatusOnSave=null,xe.period={},xe.postContactSelection=!1,xe.requestStatuses={},xe.selectedAbsenceType={},xe.staffMemberSelectionComplete=!1,xe.submitting=!1,xe.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},xe.canChangeAbsenceType=w,xe.canSubmit=O,xe.closeAlert=k,xe.deleteLeaveRequest=$,xe.dismissModal=E,xe.getStatuses=j,xe.getStatusFromValue=W,xe.initAfterContactSelection=Y,xe.initRequestAttributes=J,xe.isLeaveStatus=te,xe.isLeaveType=ne,xe.isMode=ae,xe.isRole=se,xe.submit=ye,xe.updateAbsenceType=Te,function(){xe.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),ie(),de()]).then(Q).then(_e).then(ve).then(function(){return xe.canManage&&!xe.isMode("edit")&&le()}).then(function(){if(xe.selectedContactId&&(xe.request.contact_id=xe.selectedContactId),xe.request.contact_id)return xe.initAfterContactSelection()}).catch(H).finally(function(){xe.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,i,r,c){function u(e){return r.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,i,r){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:i,forceRecalculateBalanceChange:r}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,i){function r(e){l.errorMessage=e}function c(){return i.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrjc_revision_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,i.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(r).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrjc_revision_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(),g.loading={ +workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){r.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){i.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i){function r(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,i){n=o.entitlements.slice(0,i),a=e.entitlements.slice(i+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,i;return s=e.indexBy(n,"entitlement_id.type_id"),i=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:i}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t];e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,i){o.comment&&(t=s.concat(o).concat(i),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(r).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,i,r,c,u,l,d){function m(){D.absencePeriods=t.chain(D.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){D.absenceTypes=t.filter(D.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:D.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:D.contactId,returnUrl:n})}function h(){return c.all().then(function(e){D.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:D.contactId}).then(function(e){q=e})}function g(e){i.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=D.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){D.absencePeriods=t.map(D.absencePeriods,function(e){var n=t.map(D.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

    Last updated:
    By: "+e.author_name+"
    Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
    ";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],D=this;D.absencePeriods=[],D.loading={absencePeriods:!0},D.getEditEntitlementsPageURL=p,D.openAnnualEntitlementChangeLog=g,D.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){D.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i,r){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return i.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){r.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js index 082c23d2f24..2e778bd288e 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js @@ -6,9 +6,9 @@ */ -!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){A.$current.navigable==t&&c(e,n)||A.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=A.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(A.$current=t,A.current=t.self,A.params=n,V(A.params,m),A.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),A.current)}).then(null,function(a){return a===D?S:A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(A.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},A.is=function(e,t,a){a=W({relative:A.$current},a||{});var r=f(e,a.relative);return j(r)?A.$current===r&&(!t||c(r.params.$$values(t),m)):n},A.includes=function(e,t,a){if(a=W({relative:A.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=A.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(A.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:S(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function M(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function L(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;aWhen All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){E.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function w(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(A).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){E.selectedMonths=[n().month()]}function T(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=D,function(){T().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),w()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",L)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function w(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([O(),T()]).then(g).then(M).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?w(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function M(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function L(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(A(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}), -define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(A).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function w(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(A)}function A(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():w()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function S(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function T(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function L(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(A).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:L},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=A,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),E()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(S).then(V).then(P).then(T).then(!te.isMode("view")&&te.initWatchersExtended).catch(A).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function w(e){return!e.attachment_id||T.canManage}function A(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=A,T.canRemoveAttachment=w,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=h,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function w(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function A(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:E(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:L(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function E(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function M(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function L(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=M(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,A(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=h,U.getAbsenceTypeByID=v,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=x,U.refresh=k,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),w(),O(),P(),S(),R(),I()]).then(function(){U.loading.page=!1,A()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),S(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(w)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(S)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return w(e).then(function(){R(e,!0)})})}function w(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function A(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),w("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function S(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function T(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?w("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=T,s.onDateChangeExtended=C,s.resetUIInputsExtended=A,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return i.balance.change.amount=+i.request.toil_to_accrue,a.resolve(i.balance.change)}function c(){if(!i.request.from_date||!i.request.to_date)return i.uiOptions.max_toil_duration_and_accrual=null,void(i.uiOptions.toil_duration_in_hours=null);i.uiOptions.max_toil_duration_and_accrual=t.duration(t(i.request.to_date).diff(i.request.from_date)).asHours()}function l(){return h().catch(function(e){return e.length&&(i.errors=e),a.reject(e)}).then(function(e){return s.calculateToilExpiryDate(i.request.type_id,e)}).then(function(e){return i.request.toil_expiry_date=e,i.uiOptions.expiryDate=new Date(e),e})}function d(){return!!i.request.toil_to_accrue}function f(){var e=i.uiOptions.multipleDays&&!!i.request.to_date,t=!i.uiOptions.multipleDays&&!!i.request.from_date,n=t||e,a=M.from_date!==i.request.from_date||M.to_date!==i.request.to_date;return i.canDisplayToilExpirationField&&n&&k.hasExpirationFromAdminSettings&&a}function m(){return!!(i.request.from_date&&i.request.to_date&&i.request.toil_duration&&i.request.toil_to_accrue)}function p(){i.request.toil_expiry_date=!1,i.uiOptions.expiryDate=null}function h(){var e=i.uiOptions.multipleDays,t=i.request;return v({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function v(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=i.isMode("create")&&k.hasExpirationFromAdminSettings,t=k.hasPreviousExpirationDate,n=i.isLeaveType("toil"),a=i.canManage;i.canDisplayToilExpirationField=n&&(a||e||t)}function b(){i.uiOptions.toil_duration_in_hours=i.request.toil_duration/60}function y(){return k.hasPreviousExpirationDate=i.isMode("edit")&&!!i.request.toil_expiry_date,s.canExpire(i.request.type_id).then(function(e){k.hasExpirationFromAdminSettings=e})}function _(){return i.request.to_date_type=i.request.from_date_type="1",y().then(g).then(q).then(D)}function q(){i.canManage&&(i.uiOptions.expiryDate=i.convertDateFormatFromServer(i.request.toil_expiry_date))}function $(){r.$watch(function(){return i.request.toil_to_accrue},function(e,t){+e!=+t&&i.performBalanceChangeCalculation()})}function C(){r.$watch(function(){return i.uiOptions.toil_duration_in_hours},function(e,t){i.isCalculationUnit("hours")&&e!==t&&(i.request.toil_to_accrue=i.uiOptions.toil_duration_in_hours),i.request.toil_duration=i.uiOptions.toil_duration_in_hours?60*i.uiOptions.toil_duration_in_hours:null})}function w(){var e=i.uiOptions.times;e.from.time=t(i.request.from_date).format("HH:mm"),e.to.time=t(i.request.to_date).format("HH:mm"),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}function A(){["from","to"].forEach(function(e){r.$watch(function(){return i.uiOptions.times[e].time},function(e,t){e!==t&&(i.setRequestDateTimesAndDateTypes(),x(),c(),T())})})}function P(){i.isMode("view")||($(), -C(),A())}function D(){return o.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){i.toilAmounts=e.sortBy(t,"value")})}function R(){return c(),T(),x()}function S(){return I(),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time),c(),L?L=!1:T(),x()}function T(){i.uiOptions.toil_duration_in_hours=i.uiOptions.max_toil_duration_and_accrual}function O(){M=e.cloneDeep(i.request.attributes())}function I(){i.uiOptions.multipleDays?["from","to"].forEach(function(e){i.uiOptions.times[e].min="00:00",i.uiOptions.times[e].max="23:45"}):(i.uiOptions.times.from.min="00:00",i.uiOptions.times.from.max="23:30",i.uiOptions.times.to.min="00:15",i.uiOptions.times.to.max="23:45")}function x(){return f()?l().catch(a.resolve):a.resolve()}function E(){i.uiOptions.expiryDate&&(i.request.toil_expiry_date=i.convertDateToServerFormat(i.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var M,L=!i.isMode("create"),k={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};i.canDisplayToilExpirationField=!1,i.calculateBalanceChange=u,i.canCalculateChange=d,i.canSubmit=m,i.clearExpiryDate=p,i.initChildController=_,i.initTimesExtended=w,i.initWatchersExtended=P,i.onDateChangeExtended=R,i.setDaysSelectionModeExtended=S,i.updateExpiryDate=E,function(){O(),I(),!i.isMode("create")&&b()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,r,o){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(o.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function w(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function A(){["from","to"].forEach(w)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==F())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function E(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function L(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function F(){return Me.request?Me.request.request_type:Me.leaveType||null}function U(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Se,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=F(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Me.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Se[e+"_date"]})}function he(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function ve(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Se=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),A(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?Ae():E()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function we(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Ee=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=S,Me.canSubmit=T,Me.closeAlert=x,Me.deleteLeaveRequest=L,Me.dismissModal=k,Me.getStatuses=U,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=we,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(t){return t.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM),define("leave-absences/admin-dashboard/modules/config",["common/angular","leave-absences/admin-dashboard/modules/settings"],function(e){ -return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(e,t,n,a,r,o){var s={format:["DateFormat",function(e){return e.getDateFormat()}]};r.debugEnabled(o.debug),t.defaults.stripTrailingSlashes=!1,a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:s}).state("calendar",{url:"/calendar",template:'',resolve:s}).state("leave-balances",{url:"/leave-balances",template:"",resolve:s})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function t(e,t){e.debug("Component: admin-dashboard-container"),t.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",t]})}),define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/admin-dashboard":n+"/admin-dashboard"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); +!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),w.current)}).then(null,function(a){return a===D?S:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:S(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function M(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function L(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;aWhen All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){E.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){E.selectedMonths=[n().month()]}function T(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=D,function(){T().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",L)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([O(),T()]).then(g).then(M).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function M(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function L(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}), +define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function S(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function T(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function L(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:L},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),E()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(S).then(V).then(P).then(T).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||T.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=w,T.canRemoveAttachment=A,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=h,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:E(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:L(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function E(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function M(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function L(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=M(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=h,U.getAbsenceTypeByID=v,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=x,U.refresh=k,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),O(),P(),S(),R(),I()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),S(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(S)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function S(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function T(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=T,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=k.from_date!==u.request.from_date||k.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&B.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&B.hasExpirationFromAdminSettings,t=B.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return B.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){B.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),M(),l(),O())})})} +function D(){u.isMode("view")||(C(),A(),P())}function R(){return s.valuesOf("hrleaveandabsences_toil_amounts",{},!1).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function S(){return l(),O(),M()}function T(){return x(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),j?j=!1:O(),M()}function O(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function I(){k=e.cloneDeep(u.request.attributes())}function x(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function E(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",R)}function M(){return m()?d().catch(a.resolve):a.resolve()}function L(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var k,j=!u.isMode("create"),B={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=S,u.openToilInDaysAccrualOptionsEditor=E,u.setDaysSelectionModeExtended=T,u.updateExpiryDate=L,function(){I(),x(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,r,o){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(o.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==F())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function E(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function L(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function F(){return Me.request?Me.request.request_type:Me.leaveType||null}function U(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Se,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=F(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Me.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Se[e+"_date"]})}function he(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function ve(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Se=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():E()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Ee=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=S,Me.canSubmit=T,Me.closeAlert=x,Me.deleteLeaveRequest=L,Me.dismissModal=k,Me.getStatuses=U,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(t){return t.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM), +define("leave-absences/admin-dashboard/modules/config",["common/angular","leave-absences/admin-dashboard/modules/settings"],function(e){return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(e,t,n,a,r,o){var s={format:["DateFormat",function(e){return e.getDateFormat()}]};r.debugEnabled(o.debug),t.defaults.stripTrailingSlashes=!1,a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:s}).state("calendar",{url:"/calendar",template:'',resolve:s}).state("leave-balances",{url:"/leave-balances",template:"",resolve:s})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function t(e,t){e.debug("Component: admin-dashboard-container"),t.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",t]})}),define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/admin-dashboard":n+"/admin-dashboard"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js index b76384e628d..f527a6844b6 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js @@ -6,9 +6,9 @@ */ -!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=L[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),w.current)}).then(null,function(a){return a===D?S:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:S(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function L(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function M(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function E(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n){function a(e){e.absencePeriods&&c.absencePeriods.length&&(c.filters.period_id=o().id),e.absenceTypes&&c.absenceTypes.length&&(c.filters.type_id=s().id),(e.loggedInContactId||e.userRole)&&(c.filters.managed_by="manager"===c.userRole?c.loggedInContactId:void 0),r()&&c.submitFilters()}function r(){return e.every(c.filters,function(e){return null!==e})}function o(){return e.find(c.absencePeriods,function(e){return e.current})||c.absencePeriods.reduce(function(e,n){return t(e.end_date).isAfter(n.end_date)?e:n})}function s(){return c.absenceTypes.reduce(function(e,t){return e.title.localeCompare(t.title)?e:t})}function i(e){return e.current?"Current Period ("+e.title+")":e.title}function u(){n.$emit("LeaveBalanceFilters::update",c.filters)}var c=this;c.filters={period_id:null,type_id:null,managed_by:null},c.$onChanges=a,c.labelPeriod=i,c.submitFilters=u}n.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,t){return e.extend({all:function(e,n,a,r,o){return t.getLeaveBalances(this.processFilters(e),n,a,r,o)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){return r.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function p(){return o.all().then(o.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function h(){return s.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function v(){return n.all([m(),p(),h(),g(),q()]).catch(function(e){u.error("Error",e)})}function g(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function b(){return P.loading.report=!0,i.all(w,P.pagination,void 0,void 0,!1).then(function(e){P.report=y(e.list),P.reportCount=e.total}).catch(function(e){u.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function y(n){return n.map(function(n){return n=e.copy(n),n.absence_types=t.indexBy(n.absence_types,function(e){return e.id}),n})}function _(){a.$on("LeaveBalanceFilters::update",C),c.subscribe("LeaveRequest::new",$)}function q(){return f(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function $(e){C(e,w)}function C(e,t){w=t,P.pagination.page=1,A(),P.loadReportCurrentPage()}function A(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+w.type_id})}var w={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.loadReportCurrentPage=b,function(){_(),v().then(function(){P.loading.component=!1})}()}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return f(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(m(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function f(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function m(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(L.selectedPeriod.start_date).clone().startOf("month"),a=n(L.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");L.months=e}function p(){s.$new().$watch(function(){return L.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){L.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){L.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(L)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){L.absencePeriods=t.sortBy(e,"start_date"),L.selectedPeriod=t.find(L.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){L.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){L.filters.optionValues.regions=e.hrjc_region,L.filters.optionValues.locations=e.hrjc_location,L.filters.optionValues.levelTypes=e.hrjc_level_type,L.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){L.supportData.absenceTypes=e[0],L.supportData.publicHolidays=e[1],L.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,L.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,L.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,L.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return L.injectMonths&&(e=O("destroyed"),L.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){L.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=L.selectedMonths.length?L.months.filter(function(e){return t.includes(L.selectedMonths,e.index)}):L.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){L.selectedMonths=[n().month()]}function T(){return L.roleOverride?r.resolve().then(function(){x=L.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===L.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,L=this;L.absencePeriods=[],L.contacts=[],L.contactIdsToReduceTo=null,L.injectMonths=!1,L.months=[],L.selectedMonths=null,L.selectedPeriod=null,L.showContactName=!1,L.showFilters=!1,L.supportData={},L.loading={calendar:!0,page:!0},L.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},L.labelPeriod=g,L.refresh=D,function(){T().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return L.showFilters?$():t.noop}).then(function(){h()}).then(function(){L.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",E)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([O(),T()]).then(g).then(M).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function L(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function M(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return L(e,t.id)}))}))}function E(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return L(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}), -define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function S(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function T(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function L(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function E(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:E},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),L()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(S).then(V).then(P).then(T).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||T.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=w,T.canRemoveAttachment=A,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=h,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:L(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:E(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function L(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function M(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function E(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=M(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=h,U.getAbsenceTypeByID=v,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=x,U.refresh=k,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),O(),P(),S(),R(),I()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),S(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(S)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function S(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function T(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=T,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){ -function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return i.balance.change.amount=+i.request.toil_to_accrue,a.resolve(i.balance.change)}function c(){if(!i.request.from_date||!i.request.to_date)return i.uiOptions.max_toil_duration_and_accrual=null,void(i.uiOptions.toil_duration_in_hours=null);i.uiOptions.max_toil_duration_and_accrual=t.duration(t(i.request.to_date).diff(i.request.from_date)).asHours()}function l(){return h().catch(function(e){return e.length&&(i.errors=e),a.reject(e)}).then(function(e){return s.calculateToilExpiryDate(i.request.type_id,e)}).then(function(e){return i.request.toil_expiry_date=e,i.uiOptions.expiryDate=new Date(e),e})}function d(){return!!i.request.toil_to_accrue}function f(){var e=i.uiOptions.multipleDays&&!!i.request.to_date,t=!i.uiOptions.multipleDays&&!!i.request.from_date,n=t||e,a=M.from_date!==i.request.from_date||M.to_date!==i.request.to_date;return i.canDisplayToilExpirationField&&n&&k.hasExpirationFromAdminSettings&&a}function m(){return!!(i.request.from_date&&i.request.to_date&&i.request.toil_duration&&i.request.toil_to_accrue)}function p(){i.request.toil_expiry_date=!1,i.uiOptions.expiryDate=null}function h(){var e=i.uiOptions.multipleDays,t=i.request;return v({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function v(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=i.isMode("create")&&k.hasExpirationFromAdminSettings,t=k.hasPreviousExpirationDate,n=i.isLeaveType("toil"),a=i.canManage;i.canDisplayToilExpirationField=n&&(a||e||t)}function b(){i.uiOptions.toil_duration_in_hours=i.request.toil_duration/60}function y(){return k.hasPreviousExpirationDate=i.isMode("edit")&&!!i.request.toil_expiry_date,s.canExpire(i.request.type_id).then(function(e){k.hasExpirationFromAdminSettings=e})}function _(){return i.request.to_date_type=i.request.from_date_type="1",y().then(g).then(q).then(D)}function q(){i.canManage&&(i.uiOptions.expiryDate=i.convertDateFormatFromServer(i.request.toil_expiry_date))}function $(){r.$watch(function(){return i.request.toil_to_accrue},function(e,t){+e!=+t&&i.performBalanceChangeCalculation()})}function C(){r.$watch(function(){return i.uiOptions.toil_duration_in_hours},function(e,t){i.isCalculationUnit("hours")&&e!==t&&(i.request.toil_to_accrue=i.uiOptions.toil_duration_in_hours),i.request.toil_duration=i.uiOptions.toil_duration_in_hours?60*i.uiOptions.toil_duration_in_hours:null})}function A(){var e=i.uiOptions.times;e.from.time=t(i.request.from_date).format("HH:mm"),e.to.time=t(i.request.to_date).format("HH:mm"),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}function w(){["from","to"].forEach(function(e){r.$watch(function(){return i.uiOptions.times[e].time},function(e,t){e!==t&&(i.setRequestDateTimesAndDateTypes(),x(),c(),T())})})}function P(){i.isMode("view")||($(),C(),w())}function D(){return o.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){i.toilAmounts=e.sortBy(t,"value")})}function R(){return c(),T(),x()}function S(){return I(),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time),c(),E?E=!1:T(),x()}function T(){i.uiOptions.toil_duration_in_hours=i.uiOptions.max_toil_duration_and_accrual}function O(){M=e.cloneDeep(i.request.attributes())}function I(){i.uiOptions.multipleDays?["from","to"].forEach(function(e){i.uiOptions.times[e].min="00:00",i.uiOptions.times[e].max="23:45"}):(i.uiOptions.times.from.min="00:00",i.uiOptions.times.from.max="23:30",i.uiOptions.times.to.min="00:15",i.uiOptions.times.to.max="23:45")}function x(){return f()?l().catch(a.resolve):a.resolve()}function L(){i.uiOptions.expiryDate&&(i.request.toil_expiry_date=i.convertDateToServerFormat(i.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var M,E=!i.isMode("create"),k={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};i.canDisplayToilExpirationField=!1,i.calculateBalanceChange=u,i.canCalculateChange=d,i.canSubmit=m,i.clearExpiryDate=p,i.initChildController=_,i.initTimesExtended=A,i.initWatchersExtended=P,i.onDateChangeExtended=R,i.setDaysSelectionModeExtended=S,i.updateExpiryDate=L,function(){O(),I(),!i.isMode("create")&&b()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Le.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Le.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==F())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function L(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function F(){return Me.request?Me.request.request_type:Me.leaveType||null}function U(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Se,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Le.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=F(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Me.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Se[e+"_date"]})}function he(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function ve(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Se=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():L()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Le.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Le=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=S,Me.canSubmit=T,Me.closeAlert=x,Me.deleteLeaveRequest=E,Me.dismissModal=k,Me.getStatuses=U,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var r=this;r.tabName=n.current.name, -r.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e){define("leave-absences/manager-leave/modules/config",["common/angular","leave-absences/manager-leave/modules/settings"],function(t){return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/manager-leave/requests"),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","leave-absences/shared/ui-router","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); +!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))h.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),h.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var v=s(u||{}),h=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+h.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,v)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,v)),m.$$inheritedValues=f(o.$$values,v),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,v)),o.then(i,u));for(var q=0,$=h.length;q<$;q+=3)a.hasOwnProperty(h[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(h[q],h[q+1],h[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(h.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(v[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return v[t]=new Y.Param(t,n,a,r),v[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},v=this.params=r?r.params.$$new():new Y.ParamSet,h=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=h}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:v,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,v=!0,h=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(v=e),v},this.defaultSquashPolicy=function(e){if(!j(e))return h;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return h=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!v.type.is(e))throw new Error("Default value ("+e+") for parameter '"+v.id+"' is not an instance of Type ("+v.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(v.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?v.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var v=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return h;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),h(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=L[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&h.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),h.update(!0),w.current)}).then(null,function(a){return a===D?S:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||h.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==v){d=n.$new(),v=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(h)}}var f,m,p,v,h=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:S(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function L(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function M(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return v.push(u),h[s]=r,function(){var e=v.indexOf(u);-1!==e&&v.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function E(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),h.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",h),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n){function a(e){e.absencePeriods&&c.absencePeriods.length&&(c.filters.period_id=o().id),e.absenceTypes&&c.absenceTypes.length&&(c.filters.type_id=s().id),(e.loggedInContactId||e.userRole)&&(c.filters.managed_by="manager"===c.userRole?c.loggedInContactId:void 0),r()&&c.submitFilters()}function r(){return e.every(c.filters,function(e){return null!==e})}function o(){return e.find(c.absencePeriods,function(e){return e.current})||c.absencePeriods.reduce(function(e,n){return t(e.end_date).isAfter(n.end_date)?e:n})}function s(){return c.absenceTypes.reduce(function(e,t){return e.title.localeCompare(t.title)?e:t})}function i(e){return e.current?"Current Period ("+e.title+")":e.title}function u(){n.$emit("LeaveBalanceFilters::update",c.filters)}var c=this;c.filters={period_id:null,type_id:null,managed_by:null},c.$onChanges=a,c.labelPeriod=i,c.submitFilters=u}n.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,t){return e.extend({all:function(e,n,a,r,o){return t.getLeaveBalances(this.processFilters(e),n,a,r,o)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){return r.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function p(){return o.all().then(o.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function v(){return s.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function h(){return n.all([m(),p(),v(),g(),q()]).catch(function(e){u.error("Error",e)})}function g(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function b(){return P.loading.report=!0,i.all(w,P.pagination,void 0,void 0,!1).then(function(e){P.report=y(e.list),P.reportCount=e.total}).catch(function(e){u.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function y(n){return n.map(function(n){return n=e.copy(n),n.absence_types=t.indexBy(n.absence_types,function(e){return e.id}),n})}function _(){a.$on("LeaveBalanceFilters::update",C),c.subscribe("LeaveRequest::new",$)}function q(){return f(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function $(e){C(e,w)}function C(e,t){w=t,P.pagination.page=1,A(),P.loadReportCurrentPage()}function A(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+w.type_id})}var w={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.loadReportCurrentPage=b,function(){_(),h().then(function(){P.loading.component=!1})}()}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(h.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(h.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=h.filters.userSettings.assignedTo.type;return f(e).then(function(e){h.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return h.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(m(),null,"display_name").then(function(e){return e.list})}function d(){return v?a.resolve(v):s.all()}function f(e){return"me"===e?r.leaveManagees(h.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function m(){return{department:h.filters.userSettings.department?h.filters.userSettings.department.value:null,level_type:h.filters.userSettings.level_type?h.filters.userSettings.level_type.value:null,location:h.filters.userSettings.location?h.filters.userSettings.location.value:null,region:h.filters.userSettings.region?h.filters.userSettings.region.value:null,id:{IN:h.filters.userSettings.contact?[h.filters.userSettings.contact.id]:h.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var v,h;return{init:function(e){return h=e,h.showContactDetailsLink=!0,h.showContactName=!0,h.showFilters=!0,h.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],h.filters.userSettings.assignedTo=h.filtersByAssignee[0],h.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(L.selectedPeriod.start_date).clone().startOf("month"),a=n(L.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");L.months=e}function p(){s.$new().$watch(function(){return L.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function v(e){L.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){L.loading.calendar=!1})}function h(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(L)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){L.absencePeriods=t.sortBy(e,"start_date"),L.selectedPeriod=t.find(L.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){L.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){L.filters.optionValues.regions=e.hrjc_region,L.filters.optionValues.locations=e.hrjc_location,L.filters.optionValues.levelTypes=e.hrjc_level_type,L.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){L.supportData.absenceTypes=e[0],L.supportData.publicHolidays=e[1],L.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,L.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,L.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,L.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return L.injectMonths&&(e=O("destroyed"),L.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){L.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){v("contacts"===e)})}function R(e){var n=L.selectedMonths.length?L.months.filter(function(e){return t.includes(L.selectedMonths,e.index)}):L.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){L.selectedMonths=[n().month()]}function T(){return L.roleOverride?r.resolve().then(function(){x=L.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===L.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,L=this;L.absencePeriods=[],L.contacts=[],L.contactIdsToReduceTo=null,L.injectMonths=!1,L.months=[],L.selectedMonths=null,L.selectedPeriod=null,L.showContactName=!1,L.showFilters=!1,L.supportData={},L.loading={calendar:!0,page:!0},L.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},L.labelPeriod=g,L.refresh=D,function(){T().then(p).then(h).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return L.showFilters?$():t.noop}).then(function(){v()}).then(function(){L.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function v(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function h(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),v())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){h()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function v(e){I(e),B(e)}function h(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",E)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",v)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?v(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([O(),T()]).then(g).then(M).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function L(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function M(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return L(e,t.id)}))}))}function E(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(v(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return L(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=h,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}), +define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(v(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):v(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function v(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function h(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=h,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function v(e){return q.mode===e}function h(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=v,q.onBeforeSubmit=h,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function v(e){return t(e).format(u.serverDateFormat)}function h(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function S(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function T(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function L(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function E(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return v(te.request.from_date)===v(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?v(e.fromDate):null,te.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:E},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=v,te.dateChangeHandler=h,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),L()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(S).then(V).then(P).then(T).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||T.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=w,T.canRemoveAttachment=A,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=v,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function v(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function h(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:L(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:E(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function L(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function M(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function E(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=M(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=v,U.getAbsenceTypeByID=h,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=x,U.refresh=k,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),O(),P(),S(),R(),I()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function v(){return r.resolve()}function h(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),S(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(S)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function S(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function T(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=v,s.initDayTypesExtended=h,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=T,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){ +function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return h().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=k.from_date!==u.request.from_date||k.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&B.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function v(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function h(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&B.hasExpirationFromAdminSettings,t=B.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return B.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){B.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),M(),l(),O())})})}function D(){u.isMode("view")||(C(),A(),P())}function R(){return s.valuesOf("hrleaveandabsences_toil_amounts",{},!1).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function S(){return l(),O(),M()}function T(){return x(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),j?j=!1:O(),M()}function O(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function I(){k=e.cloneDeep(u.request.attributes())}function x(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function L(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",R)}function M(){return m()?d().catch(a.resolve):a.resolve()}function E(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var k,j=!u.isMode("create"),B={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=v,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=S,u.openToilInDaysAccrualOptionsEditor=L,u.setDaysSelectionModeExtended=T,u.updateExpiryDate=E,function(){I(),x(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function v(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function h(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?v.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([h.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([h.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,v,h,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Le.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Le.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==F())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function L(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function F(){return Me.request?Me.request.request_type:Me.leaveType||null}function U(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Se,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(ve).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(ve).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Le.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=F(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return v.all().then(function(e){Me.absencePeriods=e})}function ie(){return h.all(j()).then(h.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Se[e+"_date"]})}function ve(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function he(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Se=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():L()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Le.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Le=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=S,Me.canSubmit=T,Me.closeAlert=x,Me.deleteLeaveRequest=E,Me.dismissModal=k,Me.getStatuses=U,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(he).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){ +return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e){define("leave-absences/manager-leave/modules/config",["common/angular","leave-absences/manager-leave/modules/settings"],function(t){return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/manager-leave/requests"),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","leave-absences/shared/ui-router","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js index fa767e85d9a..cc76e0e5cab 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js @@ -6,9 +6,9 @@ */ -!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[m]),c[r[m]]=e[r[m]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&f(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,f),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),f.$$values=b,f.$$promises=f.$$promises||!0,delete f.$$inheritedValues,c.resolve(b))}function u(e){f.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),f=c.promise,g=f.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),f;o.$$inheritedValues&&r(b,m(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,m(o.$$values,h)),f.$$inheritedValues=m(o.$$values,h),i()):(o.$$inheritedValues&&(f.$$inheritedValues=m(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(f.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),m=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(m++,g[e].then(function(t){b[e]=t,--m||l()},c))}),m||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return f}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(m,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",m=0,f=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),f.push(g.segment),m=c.lastIndex;y=e.substring(m);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,m+_),q.length>0)for(m=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),m=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",f.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=f[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:m}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,m=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(m=e),m},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(f(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function m(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),f(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:m})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(D.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!D[r])return f(r,t.self);for(var o in T)B(T[o])&&(t[o]=T[o](t,T.$delegates[o]));return D[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){A.$current.navigable==t&&c(e,n)||A.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=A.$current.name.split("."),a=0,r=t.length;a=D;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=D;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(A.$current=t,A.current=t.self,A.params=n,V(A.params,f),A.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),A.current)}).then(null,function(a){return a===P?T:A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(A.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},A.is=function(e,t,a){a=W({relative:A.$current},a||{});var r=m(e,a.relative);return j(r)?A.$current===r&&(!t||c(r.params.$$values(t),f)):n},A.includes=function(e,t,a){if(a=W({relative:A.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=A.$current.name}var r=m(e,a.relative);if(!j(r))return n;if(!j(A.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(m&&(m.remove(),m=null),p&&(p.$destroy(),p=null),f){var e=f.data("$uiViewAnim");b.leave(f,function(){e.$$animLeave.resolve(),m=null}),m=f,f=null}}function d(s){var d,m=P(n,c,i,r),y=m&&e.$current&&e.$current.locals[m];if(s||y!==h){d=n.$new(),h=e.$current.locals[m],d.$emit("$viewContentLoading",m);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});f=_,p=d,p.$emit("$viewContentLoaded",m),p.$eval(v)}}var m,f,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function D(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=P(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var m=t.extend({},d);o[d.$$resolveAs]=m;var f=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=m),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}f(o)}}}}}function P(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function T(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function x(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function O(e,t){return{relative:T(e)||t.$current,inherit:!0}}function I(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],m=null;c.options=W(O(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var f=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),m&&m(),d&&(m=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&f(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),f(),l.clickable&&(i=x(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){m.state=t[0],m.params=t[1],m.options=t[2],m.href=e.href(m.state,m.params,m.options),f&&f(),c&&(f=c.$$addStateInfo(m.state,m.params)),m.href&&r.$set(u.attr,m.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",m={state:null,params:null,options:null,href:null},f=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=x(a,e,t,u,function(){return m}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function L(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,T(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function m(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,m){function f(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(D(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){E.injectMonths=!0,x("injected").then(function(){R(e)}).then(function(){E.loading.calendar=!1})}function v(){O=a("LeaveCalendar"+t.capitalize(I)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(f).then(T)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return O.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function w(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return E.injectMonths&&(e=x("destroyed"),E.injectMonths=!1),e}function D(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function P(e){ -e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(A).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function T(){E.selectedMonths=[n().month()]}function S(){return E.roleOverride?r.resolve().then(function(){I=E.roleOverride}):r.all([m(i.permissions.admin.administer),m(i.permissions.ssp.manage)]).then(function(e){I=e[0]?"admin":e[1]?"manager":"staff"})}function x(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var O,I,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=P,function(){S().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),w()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function m(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?f():p()}function f(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),m(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function m(e){return U[e]}function f(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){O(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",M)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function w(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function D(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function P(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[P(u.statusNames.approved),P(u.statusNames.adminApproved),P(u.statusNames.awaitingApproval),P(u.statusNames.moreInformationRequired)]}function T(){return W.month.loading=!0,a.all([x(),S()]).then(g).then(L).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function x(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function O(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function I(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=m(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?w(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function L(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&T())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=D(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(A(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=I,W.contactsList=f,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),x("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return L()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(A).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,x("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function w(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(A)}function A(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function D(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():w()}function P(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function T(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function x(e){return te.selectedAbsenceType.calculation_unit_name===e}function O(e){return te.request.request_type===e}function I(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function L(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(A).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,f(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(O("sickness")||x("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(x("hours")||O("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=A,te.isCalculationUnit=x,te.isLeaveType=O,te.isNotWorkingDay=I,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([L(),E()])}).then(!te.isMode("create")&&P).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(T).then(V).then(D).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(A).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function m(){return S.getFilesAmount()0?P.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(P.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){T[e.label]=t})})).catch(function(){T=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){P=e})}function w(e){return!e.attachment_id||S.canManage}function A(){e.forEach(R,function(e){e()})}function D(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var P=[],R=[],T={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=A,S.canRemoveAttachment=w,S.canSubmit=d,S.canUploadMore=m,S.formatDateTime=f,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,r,o,s,i,u,c,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){k(e),H.sections.other.open&&f(e,H.sections.other)}function h(){Object.values(H.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):H.refresh()}function g(t){t.dataIndex=e.indexBy(t.data,"id")}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function y(){return o.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.selectedPeriod=e.find(H.absencePeriods,function(e){return!0===e.current})})}function _(){return s.all().then(s.loadCalculationUnits).then(function(t){H.absenceTypes=t,H.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return P("approved",{status_id:F(m.statusNames.approved)})}function $(){return n.all([u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,null,!0),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.approved)]),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){H.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function C(){return i.all({contact_id:H.contactId,period_id:H.selectedPeriod.id},!0).then(function(e){H.entitlements=e}).then(function(){H.absenceTypesFiltered=H.absenceTypes.filter(function(t){var n=e.find(H.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function w(){return i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id},H.entitlements).then(function(){return E(H.entitlements)}).then(function(e){H.sections.entitlements.data=e})}function A(){return n.all([i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id,expired:!0}),D({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:E(e[0]),expiredTOILS:L(e[1].list)})}).then(function(t){ -H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function D(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function P(e,t){return D(t).then(function(t){H.sections[e].data=t.list})}function R(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(O))}function T(){return P("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function S(){return P("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function x(){return P("holidays",{public_holiday:!0})}function O(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function I(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function E(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function L(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){k(e)})}function k(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([C(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([R(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&O(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:k,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:x},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:T}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([I(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([C(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return D(n,e),e})):r.reject([])}function f(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),T(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(w)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(T)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return m(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return w(e).then(function(){R(e,!0)})})}function w(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){x[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return x[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function A(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function D(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function P(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),w("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=x[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function T(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?w("from").then(function(){R("from",!0)}):r.resolve()}var x={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=A,s.setDaysSelectionModeExtended=P}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return i.balance.change.amount=+i.request.toil_to_accrue,a.resolve(i.balance.change)}function c(){if(!i.request.from_date||!i.request.to_date)return i.uiOptions.max_toil_duration_and_accrual=null,void(i.uiOptions.toil_duration_in_hours=null);i.uiOptions.max_toil_duration_and_accrual=t.duration(t(i.request.to_date).diff(i.request.from_date)).asHours()}function l(){return h().catch(function(e){return e.length&&(i.errors=e),a.reject(e)}).then(function(e){return s.calculateToilExpiryDate(i.request.type_id,e)}).then(function(e){return i.request.toil_expiry_date=e,i.uiOptions.expiryDate=new Date(e),e})}function d(){return!!i.request.toil_to_accrue}function m(){var e=i.uiOptions.multipleDays&&!!i.request.to_date,t=!i.uiOptions.multipleDays&&!!i.request.from_date,n=t||e,a=L.from_date!==i.request.from_date||L.to_date!==i.request.to_date;return i.canDisplayToilExpirationField&&n&&k.hasExpirationFromAdminSettings&&a}function f(){return!!(i.request.from_date&&i.request.to_date&&i.request.toil_duration&&i.request.toil_to_accrue)}function p(){i.request.toil_expiry_date=!1,i.uiOptions.expiryDate=null}function h(){var e=i.uiOptions.multipleDays,t=i.request;return v({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function v(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=i.isMode("create")&&k.hasExpirationFromAdminSettings,t=k.hasPreviousExpirationDate,n=i.isLeaveType("toil"),a=i.canManage;i.canDisplayToilExpirationField=n&&(a||e||t)}function b(){i.uiOptions.toil_duration_in_hours=i.request.toil_duration/60}function y(){return k.hasPreviousExpirationDate=i.isMode("edit")&&!!i.request.toil_expiry_date,s.canExpire(i.request.type_id).then(function(e){k.hasExpirationFromAdminSettings=e})}function _(){return i.request.to_date_type=i.request.from_date_type="1",y().then(g).then(q).then(P)}function q(){i.canManage&&(i.uiOptions.expiryDate=i.convertDateFormatFromServer(i.request.toil_expiry_date))}function $(){r.$watch(function(){return i.request.toil_to_accrue},function(e,t){+e!=+t&&i.performBalanceChangeCalculation()})}function C(){r.$watch(function(){return i.uiOptions.toil_duration_in_hours},function(e,t){i.isCalculationUnit("hours")&&e!==t&&(i.request.toil_to_accrue=i.uiOptions.toil_duration_in_hours),i.request.toil_duration=i.uiOptions.toil_duration_in_hours?60*i.uiOptions.toil_duration_in_hours:null})}function w(){var e=i.uiOptions.times;e.from.time=t(i.request.from_date).format("HH:mm"),e.to.time=t(i.request.to_date).format("HH:mm"),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}function A(){["from","to"].forEach(function(e){r.$watch(function(){return i.uiOptions.times[e].time},function(e,t){e!==t&&(i.setRequestDateTimesAndDateTypes(),I(),c(),S())})})}function D(){i.isMode("view")||($(),C(),A())}function P(){return o.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){i.toilAmounts=e.sortBy(t,"value")})}function R(){return c(),S(),I()}function T(){return O(),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time),c(),M?M=!1:S(),I()}function S(){i.uiOptions.toil_duration_in_hours=i.uiOptions.max_toil_duration_and_accrual}function x(){L=e.cloneDeep(i.request.attributes())}function O(){i.uiOptions.multipleDays?["from","to"].forEach(function(e){i.uiOptions.times[e].min="00:00",i.uiOptions.times[e].max="23:45"}):(i.uiOptions.times.from.min="00:00",i.uiOptions.times.from.max="23:30",i.uiOptions.times.to.min="00:15",i.uiOptions.times.to.max="23:45")}function I(){return m()?l().catch(a.resolve):a.resolve()}function E(){i.uiOptions.expiryDate&&(i.request.toil_expiry_date=i.convertDateToServerFormat(i.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var L,M=!i.isMode("create"),k={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};i.canDisplayToilExpirationField=!1,i.calculateBalanceChange=u,i.canCalculateChange=d,i.canSubmit=f,i.clearExpiryDate=p,i.initChildController=_,i.initTimesExtended=w,i.initWatchersExtended=D,i.onDateChangeExtended=R,i.setDaysSelectionModeExtended=T,i.updateExpiryDate=E,function(){x(),O(),!i.isMode("create")&&b()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,m,f,p,h,v,g,b,y,_,q,$,C){function w(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function A(){["from","to"].forEach(w)}function D(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Te.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=P();return Le.isMode("edit")&&(e=e&&(V()||R())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function x(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function O(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==F())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function I(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){fe("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(Pe[e],function(e){return Le.requestStatuses[e]})}function F(){return Le.request?Le.request.request_type:Le.leaveType||null}function U(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Te,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Oe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Pe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Pe.awaiting_approval=e,Pe.more_information_required=e,Pe.rejected=e,Pe.approved=e,Pe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?f.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=F(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:xe}),e}function Q(){if(Ie="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Ie="admin")}).then(function(){return"staff"===Ie&&u(_.permissions.ssp.manage).then(function(e){e&&(Ie="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Ie===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){De={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:De.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){xe=e.contactId})}function le(){return Le.selectedContactId?f.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?f.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==xe})}):f.find(xe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){D(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Te[e+"_date"]})}function he(e){if(Le.absenceTypes=me(De.types,e),!Le.absenceTypes.length)return r.reject(Oe)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Te=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,x(),A(),Le.request.isValid().then(ee()&&O).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?Ae():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function we(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?fe("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var De,Pe={},Re=0,Te={},Se=[],xe="",Oe="No entitlement",Ie="",Ee=[],Le=n.assign(this,m);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=T,Le.canSubmit=S,Le.closeAlert=I,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=U,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=we,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM), +!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[m]),c[r[m]]=e[r[m]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&f(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,f),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),f.$$values=b,f.$$promises=f.$$promises||!0,delete f.$$inheritedValues,c.resolve(b))}function u(e){f.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),f=c.promise,g=f.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),f;o.$$inheritedValues&&r(b,m(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,m(o.$$values,h)),f.$$inheritedValues=m(o.$$values,h),i()):(o.$$inheritedValues&&(f.$$inheritedValues=m(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(f.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),m=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(m++,g[e].then(function(t){b[e]=t,--m||l()},c))}),m||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return f}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(m,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",m=0,f=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),f.push(g.segment),m=c.lastIndex;y=e.substring(m);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,m+_),q.length>0)for(m=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),m=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",f.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=f[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:m}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,m=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(m=e),m},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(f(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function m(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),f(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:m})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(D.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!D[r])return f(r,t.self);for(var o in R)B(R[o])&&(t[o]=R[o](t,R.$delegates[o]));return D[n]=t,!t[T]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){A.$current.navigable==t&&c(e,n)||A.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=A.$current.name.split("."),a=0,r=t.length;a=D;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=D;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.$current=t,A.current=t.self,A.params=n,V(A.params,f),A.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),A.current)}).then(null,function(a){return a===P?R:A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},A.is=function(e,t,a){a=W({relative:A.$current},a||{});var r=m(e,a.relative);return j(r)?A.$current===r&&(!t||c(r.params.$$values(t),f)):n},A.includes=function(e,t,a){if(a=W({relative:A.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=A.$current.name}var r=m(e,a.relative);if(!j(r))return n;if(!j(A.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(m&&(m.remove(),m=null),p&&(p.$destroy(),p=null),f){var e=f.data("$uiViewAnim");b.leave(f,function(){e.$$animLeave.resolve(),m=null}),m=f,f=null}}function d(s){var d,m=P(n,c,i,r),y=m&&e.$current&&e.$current.locals[m];if(s||y!==h){d=n.$new(),h=e.$current.locals[m],d.$emit("$viewContentLoading",m);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});f=_,p=d,p.$emit("$viewContentLoaded",m),p.$eval(v)}}var m,f,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function D(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=P(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var m=t.extend({},d);o[d.$$resolveAs]=m;var f=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=m),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}f(o)}}}}}function P(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function T(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function R(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function x(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function O(e,t){return{relative:R(e)||t.$current,inherit:!0}}function I(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=T(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],m=null;c.options=W(O(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var f=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),m&&m(),d&&(m=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&f(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),f(),l.clickable&&(i=x(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){m.state=t[0],m.params=t[1],m.options=t[2],m.href=e.href(m.state,m.params,m.options),f&&f(),c&&(f=c.$$addStateInfo(m.state,m.params)),m.href&&r.$set(u.attr,m.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",m={state:null,params:null,options:null,href:null},f=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=x(a,e,t,u,function(){return m}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function L(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,R(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function m(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,m){function f(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(D(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||T()})}function h(e){E.injectMonths=!0,x("injected").then(function(){T(e)}).then(function(){E.loading.calendar=!1})}function v(){O=a("LeaveCalendar"+t.capitalize(I)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(f).then(R)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return O.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function w(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return E.injectMonths&&(e=x("destroyed"),E.injectMonths=!1),e}function D(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function P(e){ +e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(A).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function T(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function R(){E.selectedMonths=[n().month()]}function S(){return E.roleOverride?r.resolve().then(function(){I=E.roleOverride}):r.all([m(i.permissions.admin.administer),m(i.permissions.ssp.manage)]).then(function(e){I=e[0]?"admin":e[1]?"manager":"staff"})}function x(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var O,I,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=P,function(){S().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),w()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function m(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?f():p()}function f(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),m(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function m(e){return U[e]}function f(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){O(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",M)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function w(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function D(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function P(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function T(){return[P(u.statusNames.approved),P(u.statusNames.adminApproved),P(u.statusNames.awaitingApproval),P(u.statusNames.moreInformationRequired)]}function R(){return W.month.loading=!0,a.all([x(),S()]).then(g).then(L).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:T()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function x(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function O(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function I(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=m(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?w(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function L(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&R())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=D(e);t&&(h(t),-1!==T().indexOf(e.status_id)&&c(e))}function B(e){return a.all(A(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=I,W.contactsList=f,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),x("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return L()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(A).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,x("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function w(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(A)}function A(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function D(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():w()}function P(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function T(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function R(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function x(e){return te.selectedAbsenceType.calculation_unit_name===e}function O(e){return te.request.request_type===e}function I(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function L(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(A).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,f(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(O("sickness")||x("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(x("hours")||O("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=A,te.isCalculationUnit=x,te.isLeaveType=O,te.isNotWorkingDay=I,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),T(),te.initChildController().then(function(){return s.all([L(),E()])}).then(!te.isMode("create")&&P).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(R).then(V).then(D).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(A).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function m(){return S.getFilesAmount()0?P.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(P.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){R[e.label]=t})})).catch(function(){R=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){P=e})}function w(e){return!e.attachment_id||S.canManage}function A(){e.forEach(T,function(e){e()})}function D(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var P=[],T=[],R={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=A,S.canRemoveAttachment=w,S.canSubmit=d,S.canUploadMore=m,S.formatDateTime=f,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,r,o,s,i,u,c,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){k(e),H.sections.other.open&&f(e,H.sections.other)}function h(){Object.values(H.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):H.refresh()}function g(t){t.dataIndex=e.indexBy(t.data,"id")}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function y(){return o.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.selectedPeriod=e.find(H.absencePeriods,function(e){return!0===e.current})})}function _(){return s.all().then(s.loadCalculationUnits).then(function(t){H.absenceTypes=t,H.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return P("approved",{status_id:F(m.statusNames.approved)})}function $(){return n.all([u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,null,!0),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.approved)]),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){H.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function C(){return i.all({contact_id:H.contactId,period_id:H.selectedPeriod.id},!0).then(function(e){H.entitlements=e}).then(function(){H.absenceTypesFiltered=H.absenceTypes.filter(function(t){var n=e.find(H.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function w(){return i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id},H.entitlements).then(function(){return E(H.entitlements)}).then(function(e){H.sections.entitlements.data=e})}function A(){return n.all([i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id,expired:!0}),D({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:E(e[0]),expiredTOILS:L(e[1].list)})}).then(function(t){ +H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function D(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function P(e,t){return D(t).then(function(t){H.sections[e].data=t.list})}function T(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(O))}function R(){return P("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function S(){return P("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function x(){return P("holidays",{public_holiday:!0})}function O(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function I(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function E(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function L(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){k(e)})}function k(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([C(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([T(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&O(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:k,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:x},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([I(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([C(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return D(n,e),e})):r.reject([])}function f(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),R(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(w)).then(function(){["from","to"].forEach(function(e){b(e),T(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(R)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&T(e,!0))})}function $(e,t){return m(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return w(e).then(function(){T(e,!0)})})}function w(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){x[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return x[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function A(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function D(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function P(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),w("from").then(function(){T("from",!0)})):r.resolve()}function T(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=x[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function R(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?w("from").then(function(){T("from",!0)}):r.resolve()}var x={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=A,s.setDaysSelectionModeExtended=P}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function m(){return!!u.request.toil_to_accrue}function f(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=k.from_date!==u.request.from_date||k.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&B.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&B.hasExpirationFromAdminSettings,t=B.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return B.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){B.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(T)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function w(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function A(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function D(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),L(),l(),x())})})}function P(){u.isMode("view")||(C(),w(),D())}function T(){return s.valuesOf("hrleaveandabsences_toil_amounts",{},!1).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function R(){return l(),x(),L()}function S(){return I(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),j?j=!1:x(),L()}function x(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function O(){k=e.cloneDeep(u.request.attributes())}function I(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function E(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",T)}function L(){return f()?d().catch(a.resolve):a.resolve()}function M(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var k,j=!u.isMode("create"),B={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=m,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=A,u.initWatchersExtended=P,u.onDateChangeExtended=R,u.openToilInDaysAccrualOptionsEditor=E,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=M,function(){O(),I(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,m,f,p,h,v,g,b,y,_,q,$,C){function w(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function A(){["from","to"].forEach(w)}function D(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Re.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=P();return Le.isMode("edit")&&(e=e&&(V()||T())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function x(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function O(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==F())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function I(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){fe("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(Pe[e],function(e){return Le.requestStatuses[e]})}function F(){return Le.request?Le.request.request_type:Le.leaveType||null}function U(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Re,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Oe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Pe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Pe.awaiting_approval=e,Pe.more_information_required=e,Pe.rejected=e,Pe.approved=e,Pe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?f.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Te++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=F(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:xe}),e}function Q(){if(Ie="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Ie="admin")}).then(function(){return"staff"===Ie&&u(_.permissions.ssp.manage).then(function(e){e&&(Ie="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Ie===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){De={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:De.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){xe=e.contactId})}function le(){return Le.selectedContactId?f.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?f.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==xe})}):f.find(xe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){D(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Re[e+"_date"]})}function he(e){if(Le.absenceTypes=me(De.types,e),!Le.absenceTypes.length)return r.reject(Oe)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Re=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,x(),A(),Le.request.isValid().then(ee()&&O).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?Ae():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Te&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Te>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function we(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?fe("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var De,Pe={},Te=0,Re={},Se=[],xe="",Oe="No entitlement",Ie="",Ee=[],Le=n.assign(this,m);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=R,Le.canSubmit=S,Le.closeAlert=I,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=U,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=we,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM), define("leave-absences/my-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/models/option-group","common/modules/dialog","common/services/check-permissions","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/my-leave/components/my-leave-container.component","leave-absences/my-leave/modules/config"],function(e){return e.module("my-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.mocks","common.models","common.services","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","my-leave.components","my-leave.config"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/my-leave":n+"/my-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/my-leave/app"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-my-leave]"),["my-leave"])})})}(CRM,require),define("my-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.js.map \ No newline at end of file From d76f3242e681ad66f26e4b59c27ffd052b63aba5 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Tue, 27 Mar 2018 17:34:20 +0100 Subject: [PATCH 098/203] PCHR-3494: PR Feedback --- .../test/services/api/option-group.spec.js | 34 ++++++++++++------- .../test/services/crm-ang.service.spec.js | 2 +- .../js/angular/dist/absence-tab.min.js | 4 +-- .../js/angular/dist/admin-dashboard.min.js | 2 +- .../js/angular/dist/manager-leave.min.js | 2 +- .../js/angular/dist/my-leave.min.js | 2 +- .../request-modal-details-toil.controller.js | 11 +++--- ...uest-modal-details-toil.controller.spec.js | 26 ++++++++++---- .../shared/models/absence-type.model.spec.js | 17 +++++----- 9 files changed, 63 insertions(+), 37 deletions(-) diff --git a/org.civicrm.reqangular/test/services/api/option-group.spec.js b/org.civicrm.reqangular/test/services/api/option-group.spec.js index 6b097366fea..803dc5f20b8 100644 --- a/org.civicrm.reqangular/test/services/api/option-group.spec.js +++ b/org.civicrm.reqangular/test/services/api/option-group.spec.js @@ -8,7 +8,7 @@ define([ 'use strict'; describe('api.option-group', function () { - var $q, methods, OptionGroupAPI; + var $q, OptionGroupAPI; beforeEach(function () { module('common.models', 'common.mocks'); @@ -23,11 +23,10 @@ define([ beforeEach(inject(function (_$q_) { $q = _$q_; - methods = Object.keys(OptionGroupAPI); })); - it('has expected interface', function () { - expect(methods).toContain('valuesOf'); + it('has the expected api', function () { + expect(Object.keys(OptionGroupAPI)).toEqual(['valuesOf']); }); describe('valuesOf()', function () { @@ -38,19 +37,30 @@ define([ }); describe('when a single option name is passed without any additional parameters', function () { + var sendGETCallArgs; + beforeEach(function () { OptionGroupAPI.valuesOf(optionGroupName); + + sendGETCallArgs = OptionGroupAPI.sendGET.calls.mostRecent().args; + }); + + it('calls sendGET with correct API entity and method', function () { + expect(sendGETCallArgs[0]).toBe('OptionValue'); + expect(sendGETCallArgs[1]).toBe('get'); }); it('calls sendGET with correct parameters', function () { - expect(OptionGroupAPI.sendGET).toHaveBeenCalledWith( - 'OptionValue', 'get', - { 'option_group_id.name': { IN: [ optionGroupName ] }, - is_active: '1', - return: [ 'option_group_id.name', 'option_group_id', 'id', 'name', - 'label', 'value', 'weight', 'is_active', 'is_reserved'] }, - undefined - ); + expect(sendGETCallArgs[2]).toEqual({ + 'option_group_id.name': { IN: [ optionGroupName ] }, + is_active: '1', + return: [ 'option_group_id.name', 'option_group_id', 'id', 'name', + 'label', 'value', 'weight', 'is_active', 'is_reserved'] + }); + }); + + it('does not tell sendGET to disable caching the API results', function () { + expect(OptionGroupAPI.sendGET.calls.mostRecent().args[3]).not.toBe(false); }); }); diff --git a/org.civicrm.reqangular/test/services/crm-ang.service.spec.js b/org.civicrm.reqangular/test/services/crm-ang.service.spec.js index a0bbd3aa6f4..be5021c2024 100644 --- a/org.civicrm.reqangular/test/services/crm-ang.service.spec.js +++ b/org.civicrm.reqangular/test/services/crm-ang.service.spec.js @@ -8,7 +8,7 @@ ], function () { 'use strict'; - describe('crmAng', function () { + describe('crmAngService', function () { var crmAngService; beforeEach(module('common.services')); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js index c94be2fb841..9d67e301981 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js @@ -1,5 +1,5 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,o){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:t(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,o,s,i){return t.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return s.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,o,s){return t.debug("WorkPatternAPI.getCalendar",n,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,o){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,o,s,i){function r(t,n){return u().then(function(a){var o=this.days[c(t).valueOf()];return!!o&&e.find(a,function(e){return e.name===n}).value===o.type}.bind(this))}function c(e){return t(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[c(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,o){return t.debug("Calendar"),n.extend({get:function(n,s,i,r){return t.debug("Calendar.get"),a.getCalendar(n,s,i,r).then(function(t){var a=t.values.map(function(e){return o.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function o(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,o,s){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return o.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",t,n,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t,n,o,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var i=a.defer();t&&n||i.reject("contact_id and period_id are mandatory");var r={contact_id:t,period_id:n,statuses:o?{IN:o}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",r,!1).then(function(e){i.resolve(e.values)}),i.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?o.reject(t(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(t){return s.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,o&&(i.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return r.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),n.all(t)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(s.permissions.admin.administer).then(function(t){return t?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,o,s,i){return n.all(this.processFilters(e),t,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,o){return n.balanceChangeByAbsenceType(e,t,a,o)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/instances/work-pattern.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("WorkPatternInstance",["$log","ModelInstance",function(e,t){return e.debug("WorkPatternInstance"),t.extend({})}])}),define("leave-absences/shared/models/work-pattern.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/work-pattern.instance"],function(e,t){"use strict";t.factory("WorkPattern",["$log","Model","WorkPatternAPI","WorkPatternInstance",function(t,n,a,o){return t.debug("WorkPattern"),n.extend({assignWorkPattern:function(e,t,n,o,s,i){return a.assignWorkPattern(e,t,n,o,s,i)},default:function(){return a.get({is_default:!0}).then(function(t){return o.init(e.first(t),!0)})},unassignWorkPattern:function(e){return a.unassignWorkPattern(e)},workPatternsOf:function(e,t,n){return a.workPatternsOf(e,t,n).then(function(e){return e.map(function(e){return o.init(e,!0)})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function u(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?c():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return o.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):i.all()}function m(e){return"me"===e?o.leaveManagees(v.contactId):"unassigned"===e?o.leaveManagees(void 0,{unassigned:!0}):o.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){r.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,u()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:i.contactId}).leaveManagees().then(function(e){i.lookupContacts=e}).then(o)}}}function o(){return t.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:i.filters.userSettings.department?i.filters.userSettings.department.value:null,level_type:i.filters.userSettings.level_type?i.filters.userSettings.level_type.value:null,location:i.filters.userSettings.location?i.filters.userSettings.location.value:null,region:i.filters.userSettings.region?i.filters.userSettings.region.value:null,id:{IN:i.filters.userSettings.contact?[i.filters.userSettings.contact.id]:i.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var i;return{init:function(e){return i=e,i.showContactName=!0,i.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function o(a,o,s,i,r,c,u,l,d,m){function f(){for(var e=[],t=n(M.selectedPeriod.start_date).clone().startOf("month"),a=n(M.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(R(t)),t.add(1,"month");M.months=e}function p(){i.$new().$watch(function(){return M.selectedMonths},function(t,n){null===n||e.equals(t,n)||I()})}function h(e){M.injectMonths=!0,S("injected").then(function(){I(e)}).then(function(){M.loading.calendar=!1})}function v(){L=a("LeaveCalendar"+t.capitalize(k)+"Controller").init(M)}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function g(){return c.all().then(function(e){M.absencePeriods=t.sortBy(e,"start_date"),M.selectedPeriod=t.find(M.absencePeriods,function(e){return!!e.current})}).then(f).then(w)}function _(){return u.all().then(u.loadCalculationUnits)}function y(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return L.loadContacts().then(function(e){M.contacts=e})}function C(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){M.filters.optionValues.regions=e.hrjc_region,M.filters.optionValues.locations=e.hrjc_location,M.filters.optionValues.levelTypes=e.hrjc_level_type,M.filters.optionValues.departments=e.hrjc_department})}function D(){return l.all()}function T(){return o.all([_(),D(),y()]).then(function(e){M.supportData.absenceTypes=e[0],M.supportData.publicHolidays=e[1],M.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,M.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,M.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,M.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function P(){var e=o.resolve();return M.injectMonths&&(e=S("destroyed"),M.injectMonths=!1),e}function R(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function A(e){e=t.includes(["contacts","period"],e)?e:"period",o.resolve().then(function(){M.loading.calendar=!0}).then(P).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function I(e){var n=M.selectedMonths.length?M.months.filter(function(e){return t.includes(M.selectedMonths,e.index)}):M.months;i.$emit("LeaveCalendar::showMonths",n,!!e)}function w(){M.selectedMonths=[n().month()]}function O(){return M.roleOverride?o.resolve().then(function(){k=M.roleOverride}):o.all([m(r.permissions.admin.administer),m(r.permissions.ssp.manage)]).then(function(e){k=e[0]?"admin":e[1]?"manager":"staff"})}function S(e){return o(function(n){var a=0,o=i.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===M.months.length&&(o(),n())})})}s.debug("Component: leave-calendar");var L,k,M=this;M.absencePeriods=[],M.contacts=[],M.contactIdsToReduceTo=null,M.injectMonths=!1,M.months=[],M.selectedMonths=null,M.selectedPeriod=null,M.showContactName=!1,M.showFilters=!1,M.supportData={},M.loading={calendar:!0,page:!0},M.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},M.labelPeriod=b,M.refresh=A,function(){O().then(p).then(v).then(P).then(g).then(function(){return o.all([q(),T()])}).then(function(){return M.showFilters?C():t.noop}).then(function(){h()}).then(function(){M.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",o]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,o){"use strict";function s(){y.calculationUnit=i(y.supportData.calculationUnits,"value",b.calculation_unit)}function i(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function r(){var e,n;return n=t(y.contactData.leaveRequest.from_date).isSame(y.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+y.calculationUnit.name+"-on-"+e+"-tooltip"}function c(){b=i(y.supportData.absenceTypes,"id",y.contactData.leaveRequest.type_id),y.contactData.leaveRequest["type_id.title"]=b.title}function u(){"days"===y.calculationUnit.name&&(g=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.from_date_type),_=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.to_date_type),y.contactData.leaveRequest["from_date_type.label"]=g.label,y.contactData.leaveRequest["to_date_type.label"]=_.label)}function l(e,t,n,a,s){e.stopPropagation(),o.openModal(t,n,a,s)}function d(){y.dates.from=new Date(y.contactData.leaveRequest.from_date),y.dates.to=new Date(y.contactData.leaveRequest.to_date)}function m(){y.contactData.isAccruedTOIL?y.label="AT":"days"===y.calculationUnit.name?f():p()}function f(){y.label=y.contactData.isAM?"AM":y.contactData.isPM?"PM":""}function p(){var e=t(y.contactData.leaveRequest.from_date).isSame(y.date,"day"),n=t(y.contactData.leaveRequest.to_date).isSame(y.date,"day");y.label=e?t(y.contactData.leaveRequest.from_date).format("HH:mm"):n?t(y.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){y.tooltipTemplate=y.contactData.isAccruedTOIL?"accrued-toil-tooltip":r()}function v(){a.$watch("day.contactData.leaveRequest",function(){y.contactData&&y.contactData.leaveRequest&&(c(),s(),u(),m(),d(),h()) })}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(e){_([e]),U(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return j[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){L(e),U(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=P(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){N.push(o.$on("LeaveCalendar::showMonths",$)),N.push(r.subscribe("LeaveRequest::new",u)),N.push(r.subscribe("LeaveRequest::edit",B)),N.push(r.subscribe("LeaveRequest::updatedByManager",B)),N.push(r.subscribe("LeaveRequest::delete",h)),N.push(r.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function D(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function T(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function P(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function R(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function A(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function I(){return[A(c.statusNames.approved),A(c.statusNames.adminApproved),A(c.statusNames.awaitingApproval),A(c.statusNames.moreInformationRequired)]}function w(){return H.month.loading=!0,a.all([S(),O()]).then(b).then(x).then(function(){F=!0}).then(function(){H.month.loading=!1})}function O(){return i.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:I()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function S(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){j=e.indexBy(t,"contact_id")})}function L(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function k(){o.$emit("LeaveCalendar::monthDestroyed"),N.map(function(e){e.remove?e.remove():e()})}function M(t,n,o){var s,i;return t.contactsData[n]=t.contactsData[n]||{},i=m(n),s=!0===o?a.resolve():a.all([i.isWeekend(p(t.date)),i.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:D(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?T(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function x(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return M(e,t.id)}))}))}function $(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!F)&&w())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=R(e);t&&(h(t),-1!==I().indexOf(e.status_id)&&u(e))}function U(e){return a.all(P(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var F=!1,N=[],j={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=k,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,i,r,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(i.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=D[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&r.publish("ManagerBadge:: Update Count"),r.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(D,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:D[e].label,isDirectAction:D[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,D={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return r.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,c.serverDateFormat).toDate()}function h(e){return t(e).format(c.serverDateFormat)}function v(e){var t;return i.resolve().then(function(){N(e),"from"===e&&F(),S("hours")&&(_(e),"from"!==e||te.uiOptions.multipleDays||_("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return i.reject("Please change date as it is not in any absence period")}).then(W).then(function(){if(t)return x()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(V(),!t)return E();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(P).finally(y)}function b(){return V(),E()}function g(){return te.uiOptions.toDate=null,N("to"),i.resolve().then(V).then(te.setDaysSelectionModeExtended).then(y).then(!te.uiOptions.multipleDays&&E)}function _(e){te.uiOptions.times[e].loading=!0}function y(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,S("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function C(){return te.request?te.request.request_type:te.leaveType||null}function D(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(j).catch(P)}function P(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function R(){return te.isMode("create")||te.forceRecalculateBalanceChange?E():T()}function A(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():i.resolve()}function I(){ee.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){Q()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){J(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",E))}function w(){te.isMode("edit")&&(te.isLeaveStatus(c.statusNames.approved)||te.isLeaveStatus(c.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function O(){o.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(K(e),V()))})}function S(e){return te.selectedAbsenceType.calculation_unit_name===e}function L(e){return te.request.request_type===e}function k(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function M(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function x(){return u.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function $(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function E(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(j).catch(P).finally(function(){te.loading.balanceChange=!1})):i.resolve()}function B(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function U(){return h(te.request.from_date)===h(te.request.to_date)}function F(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,N("to"))}function N(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),V(),z()}function j(e){te.balance.change=e,te.request.balance_change=e.amount,f(),B(),te.loading.balanceChange=!1}function W(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function H(){return!te.isMode("create")&&U()||te.isMode("create")&&(L("sickness")||S("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,i.resolve().then(te.setDaysSelectionModeExtended)}function G(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function Y(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function V(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(S("hours")||L("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function X(){e.forEach(ee,function(e){e()})}function Q(){var e,t=te.selectedAbsenceType.calculation_unit_name;return Y(),e=t!==te.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&H).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&V).then(y).then(E)}function J(e){return te.absenceTypes=e,Y(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,N("to")),G(),E()}function K(e){var t=D(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(D(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(D(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=c.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:$},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:r.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=b,te.daysSelectionModeChangeHandler=g,te.disableAndShowLoadingTimeInput=_,te.getMomentDateWithGivenTime=D,te.handleError=P,te.isCalculationUnit=S,te.isLeaveType=L,te.isNotWorkingDay=k,te.performBalanceChangeCalculation=E,te.setRequestDateTimesAndDateTypes=V,te.updateEndTimeInputMinTime=K,te.$onDestroy=X,function(){n("RequestModalDetails"+e.capitalize(C(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",te),I(),te.initChildController().then(function(){return i.all([x(),M()])}).then(!te.isMode("create")&&A).then(H).then(function(){if(!te.isMode("create"))return i.resolve().then(te.initTimesExtended).then(V)}).then(!te.isMode("create")&&W).then(w).then(G).then(R).then(O).then(!te.isMode("view")&&te.initWatchersExtended).catch(P).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l){function d(){return O.fileUploader&&O.fileUploader.queue.length>0}function m(){return O.getFilesAmount()0?A.map(function(e){return e.label}).join(", "):""}function q(){return O.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(A.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){w[e.label]=t})})).catch(function(){w=null})}function D(){return c.valuesOf("safe_file_extension").then(function(e){A=e})}function T(e){return!e.attachment_id||O.canManage}function P(){e.forEach(I,function(e){e()})}function R(e,t){O.fileUploader.queue&&O.fileUploader.queue.length>0?O.fileUploader.uploadAll({entityID:O.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var A=[],I=[],w={},O=Object.create(this);return O.filesLoaded=!1,O.fileUploader=null,O.today=Date.now(),O.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",O.userDateFormat=i.DATE_FORMAT,O.$onDestroy=P,O.canRemoveAttachment=T,O.canSubmit=d,O.canUploadMore=m,O.formatDateTime=f,O.getAuthorName=p,O.getFilesAmount=h,O.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",O),g(),a.all([D(),q()]).then(_).finally(function(){O.filesLoaded=!0})}(),O}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,o){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],s.openLeavePopup=a,function(){o=n.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,o,s,i,r,c,u,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var t=j[e.status];t?t(e.leaveRequest):W.refresh()}function b(t){t.dataIndex=e.indexBy(t.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return i.all().then(i.loadCalculationUnits).then(function(t){W.absenceTypes=t,W.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return A("approved",{status_id:N(m.statusNames.approved)})}function C(){return n.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[N(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[N(m.statusNames.awaitingApproval),N(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function D(){return r.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(t){var n=e.find(W.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function T(){return r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return M(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function P(){return n.all([r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),R({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:M(e[0]),expiredTOILS:x(e[1].list)})}).then(function(t){W.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function R(t){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function A(e,t){return R(t).then(function(t){W.sections[e].data=t.list})}function I(){return n.all(Object.values(W.sections).filter(function(e){return e.open}).map(L))}function w(){return A("other",{status_id:{in:[N(m.statusNames.rejected),N(m.statusNames.cancelled)]}})}function O(){return A("pending",{status_id:{in:[N(m.statusNames.awaitingApproval),N(m.statusNames.moreInformationRequired)]}})}function S(){return A("holidays",{public_holiday:!0})}function L(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function k(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){W.leaveRequestStatuses=e.indexBy(t,"value")})}function M(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(W.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function x(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function $(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(W.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],B(t,a))})}function B(e,t){var n=W.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function U(){W.loading.content=!0,n.all([D(),C()]).then(function(){W.loading.content=!1}).then(function(){return n.all([I(),h()])})}function F(e){var t=W.sections[e];t.open=!t.open,t.open&&!t.data.length&&L(t)}function N(t){return e.find(W.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var j={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:T},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:P},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w}},W.labelPeriod=g,W.refresh=U,W.toggleSection=F,function(){n.all([k(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return n.all([D(),C()])}).then(function(){W.loading.content=!1}),$()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report", -controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function u(){var e=i.request,t=!!e.from_date&&!!e.to_date,n=i.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return i.canCalculateChange()}function d(t,n){var a=i.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);i.uiOptions.multipleDays||("from"===t&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=i.convertDateToServerFormat(t),r.isPublicHoliday(t).then(function(n){return n?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,i.requestDayTypes).then(function(t){return t.length?t:i.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return R(n,e),e})):o.reject([])}function f(e,n){return e=t(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return o.resolve()}function v(){return C(i.uiOptions.fromDate,"from").then(function(){return C(i.uiOptions.toDate,"to")})}function b(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,t){i.isCalculationUnit("days")||+e==+t||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function g(e){var n=t(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),i.uiOptions.times[e].time=n}function _(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],t=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(T)).then(function(){["from","to"].forEach(function(e){g(e),I(e),t[e].amount=Math.min(i.request[e+"_date_amount"],t[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function y(){["from","to"].forEach(function(e){b(e),q(e)})}function q(e){s.$watch(function(){return i.uiOptions.times[e].time},function(t,n){i.isCalculationUnit("days")||t===n||(i.setRequestDateTimesAndDateTypes(),t&&I(e,!0))})}function C(e,t){return m(e,t).then(function(){i.loading[t+"DayTypes"]=!1})}function D(e){return C(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return T(e).then(function(){I(e,!0)})})}function T(e){var t=i.uiOptions[e+"Date"],n=!i.uiOptions.multipleDays;return t?i.request.getWorkDayForDate(i.convertDateToServerFormat(t)).then(function(t){S[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return S[e]={},i.handleError(t)}).finally(function(){n&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(t){var n=i.uiOptions.times[t];i["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function R(t,n){var a="request"+e.startCase(t)+"DayTypes";i[a]=n,i.isMode("create")&&(i.request[t+"_date_type"]=i[a][0].value)}function A(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),T("from").then(function(){I("from",!0)})):o.resolve()}function I(e,t){var n=i.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,c=S[a].number_of_hours?p(s,r).toString():"0";o.maxAmount=c,t&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function O(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?T("from").then(function(){I("from",!0)}):o.resolve()}var S={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=c,i.canCalculateChange=u,i.canSubmit=l,i.initChildController=h,i.initDayTypesExtended=v,i.initTimesExtended=_,i.initWatchersExtended=y,i.onAbsenceTypeUpdateExtended=O,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=A}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function i(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function r(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=i,s.initChildController=r,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=t.duration(t(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,t=!c.uiOptions.multipleDays&&!!c.request.from_date,n=t||e,a=E.from_date!==c.request.from_date||E.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&n&&U.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,t=c.request;return b({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function b(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&U.hasExpirationFromAdminSettings,t=U.hasPreviousExpirationDate,n=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=n&&(a||e||t)}function _(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function y(){return U.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){U.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",y().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function D(){o.$watch(function(){return c.request.toil_to_accrue},function(e,t){+e!=+t&&c.performBalanceChangeCalculation()})}function T(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,t){c.isCalculationUnit("hours")&&e!==t&&(c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function P(){var e=c.uiOptions.times;e.from.time=t(c.request.from_date).format("HH:mm"),e.to.time=t(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,t){e!==t&&(c.setRequestDateTimesAndDateTypes(),x(),l(),S())})})}function A(){c.isMode("view")||(D(),T(),R())}function I(){return i.valuesOf("hrleaveandabsences_toil_amounts",{},!1).then(function(t){c.toilAmounts=e.sortBy(t,"value")})}function w(){return l(),S(),x()}function O(){return k(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),B?B=!1:S(),x()}function S(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function L(){E=e.cloneDeep(c.request.attributes())}function k(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function M(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",I)}function x(){return f()?d().catch(a.resolve):a.resolve()}function $(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var E,B=!c.isMode("create"),U={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=P,c.initWatchersExtended=A,c.onDateChangeExtended=w,c.openToilInDaysAccrualOptionsEditor=M,c.setDaysSelectionModeExtended=O,c.updateExpiryDate=$,function(){L(),k(),!c.isMode("create")&&_()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,D){function T(e){"days"===xe.selectedAbsenceType.calculation_unit_name?delete xe.request[e+"_date_amount"]:delete xe.request[e+"_date_type"]}function P(){["from","to"].forEach(T)}function R(){var e=xe.requestStatuses[y.statusNames.awaitingApproval].value;we.status_id===e&&e!==xe.request.status_id&&d.publish("ManagerBadge:: Update Count")}function A(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!xe.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function O(){var e=A();return xe.isMode("edit")&&(e=e&&(G()||I())),xe.canManage&&xe.requestStatuses&&(e=e&&!!xe.getStatusFromValue(xe.newStatusOnSave)),(e=e&&!!xe.period.id)&&!xe.isMode("view")}function S(){xe.isSelfRecord?xe.request.status_id=xe.requestStatuses[y.statusNames.awaitingApproval].value:xe.canManage&&(xe.request.status_id=xe.newStatusOnSave||xe.request.status_id)}function L(){if(xe.isMode("edit")&&!xe.isRole("staff")&&"toil"!==N())return xe.request.calculateBalanceChange(xe.selectedAbsenceType.calculation_unit_name).then(function(e){if(+xe.balance.change.amount!=+e.amount)return D.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function k(){xe.errors=[]}function M(){return xe.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function x(){ee()&&!xe.isRole("staff")&&(xe.request.change_balance=!0)}function $(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return xe.request.delete().then(function(){xe.dismissModal(),d.publish("LeaveRequest::delete",xe.request)})}})}function E(){r.dismiss({$value:"cancel"})}function B(){var e=N();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return F(xe.getStatusFromValue(xe.request.status_id).name)}function F(e){return n.map(Ae[e],function(e){return xe.requestStatuses[e]})}function N(){return xe.request?xe.request.request_type:xe.leaveType||null}function j(){return!xe.request||e.equals({},xe.requestStatuses)?[]:xe.request.status_id?U():F("none")}function W(e){return n.find(xe.requestStatuses,function(t){return t.value===e})}function H(e){xe.errors=n.isArray(e)?e:[e],xe.loading.absenceTypes=!1,xe.submitting=!1}function G(){return!e.equals(we,xe.request.attributes())||xe.canManage&&xe.newStatusOnSave}function Y(){return xe.postContactSelection=!0,xe.staffMemberSelectionComplete=!1,xe.request.contact_id?o.resolve().then(re).then(ce).then(he).then(be).then(Z).then(z).then(xe.isMode("edit")?ge:n.noop).then(function(){xe.postContactSelection=!1,xe.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Le)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Ae.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Ae.awaiting_approval=e,Ae.more_information_required=e,Ae.rejected=e,Ae.approved=e,Ae.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return xe.canManage?f.find(xe.request.contact_id).then(function(e){xe.contactName=e.display_name}):o.resolve()}function X(){Oe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",xe.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Ie++})),i.$on("$destroy",De),i.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function Q(){var e,t;xe.request=xe.leaveRequest||null,e=N(),t=xe.initRequestAttributes(),"leave"===e?xe.request=_.init(t):"sickness"===e?xe.request=q.init(t):"toil"===e&&(xe.request=C.init(t))}function J(){var e={};return xe.request?e=xe.request.attributes():xe.canManage||(e={contact_id:Se}),e}function K(){if(ke="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(ke="admin")}).then(function(){return"staff"===ke&&c(y.permissions.ssp.manage).then(function(e){e&&(ke="manager")})}).finally(function(){xe.canManage=xe.isRole("manager")||xe.isRole("admin")})}function Z(){(xe.isRole("admin")||xe.isMode("create")&&xe.isRole("manager"))&&(xe.newStatusOnSave=xe.requestStatuses[y.statusNames.approved].value)}function ee(){return!xe.request.status_id||!n.includes(["cancelled","rejected"],W(xe.request.status_id).name)}function te(e){var t=xe.getStatusFromValue(xe.request.status_id);return!!t&&t.name===e}function ne(e){return xe.request&&xe.request.request_type===e}function ae(e){return xe.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return ke===e}function ie(){return h.all().then(function(e){xe.absencePeriods=e})}function re(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Re={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return xe.loading.entitlements=!0,b.all({contact_id:xe.request.contact_id,period_id:xe.period.id,type_id:{IN:Re.ids}},!0).finally(function(){xe.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Se=e.contactId})}function le(){return xe.selectedContactId?f.find(xe.selectedContactId).then(function(e){xe.managedContacts=[e]}):xe.isRole("admin")?f.all().then(function(e){xe.managedContacts=n.remove(e.list,function(e){return e.id!==Se})}):f.find(Se).then(function(e){return e.leaveManagees()}).then(function(e){xe.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){xe.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){R(),d.publish(e,xe.request),xe.errors=[],xe.dismissModal()}function pe(){["from","to"].forEach(function(e){xe.request[e+"_date"]=we[e+"_date"]})}function he(e){if(xe.absenceTypes=me(Re.types,e),!xe.absenceTypes.length)return o.reject(Le)}function ve(){xe.period=n.find(xe.absencePeriods,function(e){return xe.isMode("create")?e.current:oe(xe.request,e)})}function be(){xe.isMode("create")?(xe.selectedAbsenceType=xe.absenceTypes[0],xe.request.type_id=xe.selectedAbsenceType.id):xe.selectedAbsenceType=n.find(xe.absenceTypes,function(e){return e.id===xe.request.type_id})}function ge(){we=e.copy(xe.request.attributes())}function _e(){var e;xe.request.id?(e=[xe.requestStatuses[y.statusNames.approved].value,xe.requestStatuses[y.statusNames.adminApproved].value,xe.requestStatuses[y.statusNames.rejected].value,xe.requestStatuses[y.statusNames.cancelled].value],xe.mode="edit",xe.isRole("staff")&&e.indexOf(xe.request.status_id)>-1&&(xe.mode="view")):xe.mode="create"}function ye(){var e=xe.request.status_id;if(!xe.isMode("view")&&!xe.submitting)return xe.submitting=!0,S(),P(),xe.request.isValid().then(ee()&&L).then(x).then(!xe.request.change_balance&&pe).then(qe).then(function(){return xe.isMode("edit")?Pe():M()}).catch(function(t){xe.request.status_id=e,t&&H(t)}).finally(function(){xe.submitting=!1})}function qe(){return o.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===Ie&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return Ie>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function De(){Oe.forEach(function(e){e()})}function Te(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Pe(){return xe.request.update().then(Ce).then(function(){xe.isRole("manager")?fe("LeaveRequest::updatedByManager"):(xe.isRole("staff")||xe.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Re,Ae={},Ie=0,we={},Oe=[],Se="",Le="No entitlement",ke="",Me=[],xe=n.assign(this,m);xe.absencePeriods=[],xe.absenceTypes=[],xe.canManage=!1,xe.contactName=null,xe.errors=[],xe.loading={absenceTypes:!0,entitlements:!0},xe.managedContacts=[],xe.mode="",xe.newStatusOnSave=null,xe.period={},xe.postContactSelection=!1,xe.requestStatuses={},xe.selectedAbsenceType={},xe.staffMemberSelectionComplete=!1,xe.submitting=!1,xe.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},xe.canChangeAbsenceType=w,xe.canSubmit=O,xe.closeAlert=k,xe.deleteLeaveRequest=$,xe.dismissModal=E,xe.getStatuses=j,xe.getStatusFromValue=W,xe.initAfterContactSelection=Y,xe.initRequestAttributes=J,xe.isLeaveStatus=te,xe.isLeaveType=ne,xe.isMode=ae,xe.isRole=se,xe.submit=ye,xe.updateAbsenceType=Te,function(){xe.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),ie(),de()]).then(Q).then(_e).then(ve).then(function(){return xe.canManage&&!xe.isMode("edit")&&le()}).then(function(){if(xe.selectedContactId&&(xe.request.contact_id=xe.selectedContactId),xe.request.contact_id)return xe.initAfterContactSelection()}).catch(H).finally(function(){xe.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,i,r,c){function u(e){return r.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,i,r){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:i,forceRecalculateBalanceChange:r}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,i){function r(e){l.errorMessage=e}function c(){return i.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrjc_revision_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,i.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(r).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrjc_revision_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(),g.loading={ -workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){r.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){i.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i){function r(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,i){n=o.entitlements.slice(0,i),a=e.entitlements.slice(i+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,i;return s=e.indexBy(n,"entitlement_id.type_id"),i=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:i}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t];e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,i){o.comment&&(t=s.concat(o).concat(i),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(r).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,i,r,c,u,l,d){function m(){D.absencePeriods=t.chain(D.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){D.absenceTypes=t.filter(D.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:D.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:D.contactId,returnUrl:n})}function h(){return c.all().then(function(e){D.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:D.contactId}).then(function(e){q=e})}function g(e){i.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=D.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){D.absencePeriods=t.map(D.absencePeriods,function(e){var n=t.map(D.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

    Last updated:
    By: "+e.author_name+"
    Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
    ";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],D=this;D.absencePeriods=[],D.loading={absencePeriods:!0},D.getEditEntitlementsPageURL=p,D.openAnnualEntitlementChangeLog=g,D.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){D.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i,r){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return i.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){r.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); +controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function u(){var e=i.request,t=!!e.from_date&&!!e.to_date,n=i.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return i.canCalculateChange()}function d(t,n){var a=i.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);i.uiOptions.multipleDays||("from"===t&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=i.convertDateToServerFormat(t),r.isPublicHoliday(t).then(function(n){return n?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,i.requestDayTypes).then(function(t){return t.length?t:i.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return R(n,e),e})):o.reject([])}function f(e,n){return e=t(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return o.resolve()}function v(){return C(i.uiOptions.fromDate,"from").then(function(){return C(i.uiOptions.toDate,"to")})}function b(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,t){i.isCalculationUnit("days")||+e==+t||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function g(e){var n=t(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),i.uiOptions.times[e].time=n}function _(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],t=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(T)).then(function(){["from","to"].forEach(function(e){g(e),I(e),t[e].amount=Math.min(i.request[e+"_date_amount"],t[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function y(){["from","to"].forEach(function(e){b(e),q(e)})}function q(e){s.$watch(function(){return i.uiOptions.times[e].time},function(t,n){i.isCalculationUnit("days")||t===n||(i.setRequestDateTimesAndDateTypes(),t&&I(e,!0))})}function C(e,t){return m(e,t).then(function(){i.loading[t+"DayTypes"]=!1})}function D(e){return C(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return T(e).then(function(){I(e,!0)})})}function T(e){var t=i.uiOptions[e+"Date"],n=!i.uiOptions.multipleDays;return t?i.request.getWorkDayForDate(i.convertDateToServerFormat(t)).then(function(t){S[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return S[e]={},i.handleError(t)}).finally(function(){n&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(t){var n=i.uiOptions.times[t];i["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function R(t,n){var a="request"+e.startCase(t)+"DayTypes";i[a]=n,i.isMode("create")&&(i.request[t+"_date_type"]=i[a][0].value)}function A(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),T("from").then(function(){I("from",!0)})):o.resolve()}function I(e,t){var n=i.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,c=S[a].number_of_hours?p(s,r).toString():"0";o.maxAmount=c,t&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function O(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?T("from").then(function(){I("from",!0)}):o.resolve()}var S={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=c,i.canCalculateChange=u,i.canSubmit=l,i.initChildController=h,i.initDayTypesExtended=v,i.initTimesExtended=_,i.initWatchersExtended=y,i.onAbsenceTypeUpdateExtended=O,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=A}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function i(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function r(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=i,s.initChildController=r,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=t.duration(t(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,t=!c.uiOptions.multipleDays&&!!c.request.from_date,n=t||e,a=E.from_date!==c.request.from_date||E.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&n&&U.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,t=c.request;return b({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function b(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&U.hasExpirationFromAdminSettings,t=U.hasPreviousExpirationDate,n=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=n&&(a||e||t)}function _(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function y(){return U.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){U.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",y().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function D(){o.$watch(function(){return c.request.toil_to_accrue},function(e,t){+e!=+t&&c.performBalanceChangeCalculation()})}function T(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,t){c.isCalculationUnit("hours")&&e!==t&&(c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function P(){var e=c.uiOptions.times;e.from.time=t(c.request.from_date).format("HH:mm"),e.to.time=t(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,t){e!==t&&(c.setRequestDateTimesAndDateTypes(),x(),l(),S())})})}function A(){c.isMode("view")||(D(),T(),R())}function I(t){return i.valuesOf("hrleaveandabsences_toil_amounts",{},t).then(function(t){c.toilAmounts=e.sortBy(t,"value")})}function w(){return l(),S(),x()}function O(){return k(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),B?B=!1:S(),x()}function S(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function L(){E=e.cloneDeep(c.request.attributes())}function k(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function M(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){I(!1)})}function x(){return f()?d().catch(a.resolve):a.resolve()}function $(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var E,B=!c.isMode("create"),U={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=P,c.initWatchersExtended=A,c.onDateChangeExtended=w,c.openToilInDaysAccrualOptionsEditor=M,c.setDaysSelectionModeExtended=O,c.updateExpiryDate=$,function(){L(),k(),!c.isMode("create")&&_()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,D){function T(e){"days"===xe.selectedAbsenceType.calculation_unit_name?delete xe.request[e+"_date_amount"]:delete xe.request[e+"_date_type"]}function P(){["from","to"].forEach(T)}function R(){var e=xe.requestStatuses[y.statusNames.awaitingApproval].value;we.status_id===e&&e!==xe.request.status_id&&d.publish("ManagerBadge:: Update Count")}function A(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!xe.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function O(){var e=A();return xe.isMode("edit")&&(e=e&&(G()||I())),xe.canManage&&xe.requestStatuses&&(e=e&&!!xe.getStatusFromValue(xe.newStatusOnSave)),(e=e&&!!xe.period.id)&&!xe.isMode("view")}function S(){xe.isSelfRecord?xe.request.status_id=xe.requestStatuses[y.statusNames.awaitingApproval].value:xe.canManage&&(xe.request.status_id=xe.newStatusOnSave||xe.request.status_id)}function L(){if(xe.isMode("edit")&&!xe.isRole("staff")&&"toil"!==N())return xe.request.calculateBalanceChange(xe.selectedAbsenceType.calculation_unit_name).then(function(e){if(+xe.balance.change.amount!=+e.amount)return D.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function k(){xe.errors=[]}function M(){return xe.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function x(){ee()&&!xe.isRole("staff")&&(xe.request.change_balance=!0)}function $(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return xe.request.delete().then(function(){xe.dismissModal(),d.publish("LeaveRequest::delete",xe.request)})}})}function E(){r.dismiss({$value:"cancel"})}function B(){var e=N();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return F(xe.getStatusFromValue(xe.request.status_id).name)}function F(e){return n.map(Ae[e],function(e){return xe.requestStatuses[e]})}function N(){return xe.request?xe.request.request_type:xe.leaveType||null}function j(){return!xe.request||e.equals({},xe.requestStatuses)?[]:xe.request.status_id?U():F("none")}function W(e){return n.find(xe.requestStatuses,function(t){return t.value===e})}function H(e){xe.errors=n.isArray(e)?e:[e],xe.loading.absenceTypes=!1,xe.submitting=!1}function G(){return!e.equals(we,xe.request.attributes())||xe.canManage&&xe.newStatusOnSave}function Y(){return xe.postContactSelection=!0,xe.staffMemberSelectionComplete=!1,xe.request.contact_id?o.resolve().then(re).then(ce).then(he).then(be).then(Z).then(z).then(xe.isMode("edit")?ge:n.noop).then(function(){xe.postContactSelection=!1,xe.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Le)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Ae.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Ae.awaiting_approval=e,Ae.more_information_required=e,Ae.rejected=e,Ae.approved=e,Ae.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return xe.canManage?f.find(xe.request.contact_id).then(function(e){xe.contactName=e.display_name}):o.resolve()}function X(){Oe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",xe.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Ie++})),i.$on("$destroy",De),i.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function Q(){var e,t;xe.request=xe.leaveRequest||null,e=N(),t=xe.initRequestAttributes(),"leave"===e?xe.request=_.init(t):"sickness"===e?xe.request=q.init(t):"toil"===e&&(xe.request=C.init(t))}function J(){var e={};return xe.request?e=xe.request.attributes():xe.canManage||(e={contact_id:Se}),e}function K(){if(ke="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(ke="admin")}).then(function(){return"staff"===ke&&c(y.permissions.ssp.manage).then(function(e){e&&(ke="manager")})}).finally(function(){xe.canManage=xe.isRole("manager")||xe.isRole("admin")})}function Z(){(xe.isRole("admin")||xe.isMode("create")&&xe.isRole("manager"))&&(xe.newStatusOnSave=xe.requestStatuses[y.statusNames.approved].value)}function ee(){return!xe.request.status_id||!n.includes(["cancelled","rejected"],W(xe.request.status_id).name)}function te(e){var t=xe.getStatusFromValue(xe.request.status_id);return!!t&&t.name===e}function ne(e){return xe.request&&xe.request.request_type===e}function ae(e){return xe.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return ke===e}function ie(){return h.all().then(function(e){xe.absencePeriods=e})}function re(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Re={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return xe.loading.entitlements=!0,b.all({contact_id:xe.request.contact_id,period_id:xe.period.id,type_id:{IN:Re.ids}},!0).finally(function(){xe.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Se=e.contactId})}function le(){return xe.selectedContactId?f.find(xe.selectedContactId).then(function(e){xe.managedContacts=[e]}):xe.isRole("admin")?f.all().then(function(e){xe.managedContacts=n.remove(e.list,function(e){return e.id!==Se})}):f.find(Se).then(function(e){return e.leaveManagees()}).then(function(e){xe.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){xe.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){R(),d.publish(e,xe.request),xe.errors=[],xe.dismissModal()}function pe(){["from","to"].forEach(function(e){xe.request[e+"_date"]=we[e+"_date"]})}function he(e){if(xe.absenceTypes=me(Re.types,e),!xe.absenceTypes.length)return o.reject(Le)}function ve(){xe.period=n.find(xe.absencePeriods,function(e){return xe.isMode("create")?e.current:oe(xe.request,e)})}function be(){xe.isMode("create")?(xe.selectedAbsenceType=xe.absenceTypes[0],xe.request.type_id=xe.selectedAbsenceType.id):xe.selectedAbsenceType=n.find(xe.absenceTypes,function(e){return e.id===xe.request.type_id})}function ge(){we=e.copy(xe.request.attributes())}function _e(){var e;xe.request.id?(e=[xe.requestStatuses[y.statusNames.approved].value,xe.requestStatuses[y.statusNames.adminApproved].value,xe.requestStatuses[y.statusNames.rejected].value,xe.requestStatuses[y.statusNames.cancelled].value],xe.mode="edit",xe.isRole("staff")&&e.indexOf(xe.request.status_id)>-1&&(xe.mode="view")):xe.mode="create"}function ye(){var e=xe.request.status_id;if(!xe.isMode("view")&&!xe.submitting)return xe.submitting=!0,S(),P(),xe.request.isValid().then(ee()&&L).then(x).then(!xe.request.change_balance&&pe).then(qe).then(function(){return xe.isMode("edit")?Pe():M()}).catch(function(t){xe.request.status_id=e,t&&H(t)}).finally(function(){xe.submitting=!1})}function qe(){return o.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===Ie&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return Ie>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function De(){Oe.forEach(function(e){e()})}function Te(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Pe(){return xe.request.update().then(Ce).then(function(){xe.isRole("manager")?fe("LeaveRequest::updatedByManager"):(xe.isRole("staff")||xe.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Re,Ae={},Ie=0,we={},Oe=[],Se="",Le="No entitlement",ke="",Me=[],xe=n.assign(this,m);xe.absencePeriods=[],xe.absenceTypes=[],xe.canManage=!1,xe.contactName=null,xe.errors=[],xe.loading={absenceTypes:!0,entitlements:!0},xe.managedContacts=[],xe.mode="",xe.newStatusOnSave=null,xe.period={},xe.postContactSelection=!1,xe.requestStatuses={},xe.selectedAbsenceType={},xe.staffMemberSelectionComplete=!1,xe.submitting=!1,xe.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},xe.canChangeAbsenceType=w,xe.canSubmit=O,xe.closeAlert=k,xe.deleteLeaveRequest=$,xe.dismissModal=E,xe.getStatuses=j,xe.getStatusFromValue=W,xe.initAfterContactSelection=Y,xe.initRequestAttributes=J,xe.isLeaveStatus=te,xe.isLeaveType=ne,xe.isMode=ae,xe.isRole=se,xe.submit=ye,xe.updateAbsenceType=Te,function(){xe.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),ie(),de()]).then(Q).then(_e).then(ve).then(function(){return xe.canManage&&!xe.isMode("edit")&&le()}).then(function(){if(xe.selectedContactId&&(xe.request.contact_id=xe.selectedContactId),xe.request.contact_id)return xe.initAfterContactSelection()}).catch(H).finally(function(){xe.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,i,r,c){function u(e){return r.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,i,r){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:i,forceRecalculateBalanceChange:r}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,i){function r(e){l.errorMessage=e}function c(){return i.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrjc_revision_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,i.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(r).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrjc_revision_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e}) +}(),g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){r.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){i.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i){function r(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,i){n=o.entitlements.slice(0,i),a=e.entitlements.slice(i+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,i;return s=e.indexBy(n,"entitlement_id.type_id"),i=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:i}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t];e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,i){o.comment&&(t=s.concat(o).concat(i),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(r).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,i,r,c,u,l,d){function m(){D.absencePeriods=t.chain(D.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){D.absenceTypes=t.filter(D.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:D.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:D.contactId,returnUrl:n})}function h(){return c.all().then(function(e){D.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:D.contactId}).then(function(e){q=e})}function g(e){i.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=D.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){D.absencePeriods=t.map(D.absencePeriods,function(e){var n=t.map(D.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

    Last updated:
    By: "+e.author_name+"
    Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
    ";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],D=this;D.absencePeriods=[],D.loading={absencePeriods:!0},D.getEditEntitlementsPageURL=p,D.openAnnualEntitlementChangeLog=g,D.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){D.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i,r){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return i.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){r.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js index 2e778bd288e..21e9a9188de 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js @@ -9,6 +9,6 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),w.current)}).then(null,function(a){return a===D?S:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:S(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function M(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function L(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;aWhen All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){E.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){E.selectedMonths=[n().month()]}function T(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=D,function(){T().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",L)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([O(),T()]).then(g).then(M).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function M(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function L(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}), define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function S(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function T(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function L(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:L},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),E()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(S).then(V).then(P).then(T).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||T.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=w,T.canRemoveAttachment=A,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=h,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:E(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:L(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function E(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function M(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function L(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=M(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=h,U.getAbsenceTypeByID=v,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=x,U.refresh=k,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),O(),P(),S(),R(),I()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),S(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(S)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function S(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function T(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=T,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=k.from_date!==u.request.from_date||k.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&B.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&B.hasExpirationFromAdminSettings,t=B.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return B.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){B.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),M(),l(),O())})})} -function D(){u.isMode("view")||(C(),A(),P())}function R(){return s.valuesOf("hrleaveandabsences_toil_amounts",{},!1).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function S(){return l(),O(),M()}function T(){return x(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),j?j=!1:O(),M()}function O(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function I(){k=e.cloneDeep(u.request.attributes())}function x(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function E(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",R)}function M(){return m()?d().catch(a.resolve):a.resolve()}function L(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var k,j=!u.isMode("create"),B={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=S,u.openToilInDaysAccrualOptionsEditor=E,u.setDaysSelectionModeExtended=T,u.updateExpiryDate=L,function(){I(),x(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,r,o){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(o.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==F())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function E(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function L(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function F(){return Me.request?Me.request.request_type:Me.leaveType||null}function U(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Se,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=F(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Me.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Se[e+"_date"]})}function he(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function ve(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Se=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():E()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Ee=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=S,Me.canSubmit=T,Me.closeAlert=x,Me.deleteLeaveRequest=L,Me.dismissModal=k,Me.getStatuses=U,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(t){return t.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM), +function D(){u.isMode("view")||(C(),A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",{},t).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function S(){return l(),O(),M()}function T(){return x(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),j?j=!1:O(),M()}function O(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function I(){k=e.cloneDeep(u.request.attributes())}function x(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function E(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){R(!1)})}function M(){return m()?d().catch(a.resolve):a.resolve()}function L(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var k,j=!u.isMode("create"),B={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=S,u.openToilInDaysAccrualOptionsEditor=E,u.setDaysSelectionModeExtended=T,u.updateExpiryDate=L,function(){I(),x(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,r,o){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(o.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==F())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function E(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function L(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function F(){return Me.request?Me.request.request_type:Me.leaveType||null}function U(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Se,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=F(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Me.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Se[e+"_date"]})}function he(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function ve(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Se=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():E()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Ee=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=S,Me.canSubmit=T,Me.closeAlert=x,Me.deleteLeaveRequest=L,Me.dismissModal=k,Me.getStatuses=U,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(t){return t.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM), define("leave-absences/admin-dashboard/modules/config",["common/angular","leave-absences/admin-dashboard/modules/settings"],function(e){return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(e,t,n,a,r,o){var s={format:["DateFormat",function(e){return e.getDateFormat()}]};r.debugEnabled(o.debug),t.defaults.stripTrailingSlashes=!1,a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:s}).state("calendar",{url:"/calendar",template:'',resolve:s}).state("leave-balances",{url:"/leave-balances",template:"",resolve:s})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function t(e,t){e.debug("Component: admin-dashboard-container"),t.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",t]})}),define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/admin-dashboard":n+"/admin-dashboard"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js index f527a6844b6..32e7391923a 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js @@ -9,6 +9,6 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))h.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),h.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var v=s(u||{}),h=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+h.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,v)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,v)),m.$$inheritedValues=f(o.$$values,v),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,v)),o.then(i,u));for(var q=0,$=h.length;q<$;q+=3)a.hasOwnProperty(h[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(h[q],h[q+1],h[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(h.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(v[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return v[t]=new Y.Param(t,n,a,r),v[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},v=this.params=r?r.params.$$new():new Y.ParamSet,h=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=h}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:v,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,v=!0,h=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(v=e),v},this.defaultSquashPolicy=function(e){if(!j(e))return h;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return h=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!v.type.is(e))throw new Error("Default value ("+e+") for parameter '"+v.id+"' is not an instance of Type ("+v.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(v.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?v.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var v=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return h;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),h(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=L[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&h.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),h.update(!0),w.current)}).then(null,function(a){return a===D?S:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||h.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==v){d=n.$new(),v=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(h)}}var f,m,p,v,h=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:S(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function L(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function M(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return v.push(u),h[s]=r,function(){var e=v.indexOf(u);-1!==e&&v.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function E(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),h.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",h),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n){function a(e){e.absencePeriods&&c.absencePeriods.length&&(c.filters.period_id=o().id),e.absenceTypes&&c.absenceTypes.length&&(c.filters.type_id=s().id),(e.loggedInContactId||e.userRole)&&(c.filters.managed_by="manager"===c.userRole?c.loggedInContactId:void 0),r()&&c.submitFilters()}function r(){return e.every(c.filters,function(e){return null!==e})}function o(){return e.find(c.absencePeriods,function(e){return e.current})||c.absencePeriods.reduce(function(e,n){return t(e.end_date).isAfter(n.end_date)?e:n})}function s(){return c.absenceTypes.reduce(function(e,t){return e.title.localeCompare(t.title)?e:t})}function i(e){return e.current?"Current Period ("+e.title+")":e.title}function u(){n.$emit("LeaveBalanceFilters::update",c.filters)}var c=this;c.filters={period_id:null,type_id:null,managed_by:null},c.$onChanges=a,c.labelPeriod=i,c.submitFilters=u}n.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,t){return e.extend({all:function(e,n,a,r,o){return t.getLeaveBalances(this.processFilters(e),n,a,r,o)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){return r.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function p(){return o.all().then(o.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function v(){return s.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function h(){return n.all([m(),p(),v(),g(),q()]).catch(function(e){u.error("Error",e)})}function g(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function b(){return P.loading.report=!0,i.all(w,P.pagination,void 0,void 0,!1).then(function(e){P.report=y(e.list),P.reportCount=e.total}).catch(function(e){u.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function y(n){return n.map(function(n){return n=e.copy(n),n.absence_types=t.indexBy(n.absence_types,function(e){return e.id}),n})}function _(){a.$on("LeaveBalanceFilters::update",C),c.subscribe("LeaveRequest::new",$)}function q(){return f(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function $(e){C(e,w)}function C(e,t){w=t,P.pagination.page=1,A(),P.loadReportCurrentPage()}function A(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+w.type_id})}var w={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.loadReportCurrentPage=b,function(){_(),h().then(function(){P.loading.component=!1})}()}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(h.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(h.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=h.filters.userSettings.assignedTo.type;return f(e).then(function(e){h.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return h.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(m(),null,"display_name").then(function(e){return e.list})}function d(){return v?a.resolve(v):s.all()}function f(e){return"me"===e?r.leaveManagees(h.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function m(){return{department:h.filters.userSettings.department?h.filters.userSettings.department.value:null,level_type:h.filters.userSettings.level_type?h.filters.userSettings.level_type.value:null,location:h.filters.userSettings.location?h.filters.userSettings.location.value:null,region:h.filters.userSettings.region?h.filters.userSettings.region.value:null,id:{IN:h.filters.userSettings.contact?[h.filters.userSettings.contact.id]:h.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var v,h;return{init:function(e){return h=e,h.showContactDetailsLink=!0,h.showContactName=!0,h.showFilters=!0,h.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],h.filters.userSettings.assignedTo=h.filtersByAssignee[0],h.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(L.selectedPeriod.start_date).clone().startOf("month"),a=n(L.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");L.months=e}function p(){s.$new().$watch(function(){return L.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function v(e){L.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){L.loading.calendar=!1})}function h(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(L)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){L.absencePeriods=t.sortBy(e,"start_date"),L.selectedPeriod=t.find(L.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){L.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){L.filters.optionValues.regions=e.hrjc_region,L.filters.optionValues.locations=e.hrjc_location,L.filters.optionValues.levelTypes=e.hrjc_level_type,L.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){L.supportData.absenceTypes=e[0],L.supportData.publicHolidays=e[1],L.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,L.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,L.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,L.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return L.injectMonths&&(e=O("destroyed"),L.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){L.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){v("contacts"===e)})}function R(e){var n=L.selectedMonths.length?L.months.filter(function(e){return t.includes(L.selectedMonths,e.index)}):L.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){L.selectedMonths=[n().month()]}function T(){return L.roleOverride?r.resolve().then(function(){x=L.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===L.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,L=this;L.absencePeriods=[],L.contacts=[],L.contactIdsToReduceTo=null,L.injectMonths=!1,L.months=[],L.selectedMonths=null,L.selectedPeriod=null,L.showContactName=!1,L.showFilters=!1,L.supportData={},L.loading={calendar:!0,page:!0},L.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},L.labelPeriod=g,L.refresh=D,function(){T().then(p).then(h).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return L.showFilters?$():t.noop}).then(function(){v()}).then(function(){L.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function v(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function h(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),v())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){h()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function v(e){I(e),B(e)}function h(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",E)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",v)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?v(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([O(),T()]).then(g).then(M).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function L(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function M(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return L(e,t.id)}))}))}function E(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(v(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return L(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=h,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}), define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(v(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):v(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function v(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function h(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=h,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function v(e){return q.mode===e}function h(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=v,q.onBeforeSubmit=h,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function v(e){return t(e).format(u.serverDateFormat)}function h(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function S(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function T(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function L(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function E(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return v(te.request.from_date)===v(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?v(e.fromDate):null,te.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:E},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=v,te.dateChangeHandler=h,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),L()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(S).then(V).then(P).then(T).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||T.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=w,T.canRemoveAttachment=A,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=v,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function v(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function h(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:L(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:E(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function L(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function M(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function E(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=M(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=v,U.getAbsenceTypeByID=h,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=x,U.refresh=k,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),O(),P(),S(),R(),I()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function v(){return r.resolve()}function h(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),S(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(S)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function S(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function T(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=v,s.initDayTypesExtended=h,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=T,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){ -function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return h().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=k.from_date!==u.request.from_date||k.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&B.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function v(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function h(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&B.hasExpirationFromAdminSettings,t=B.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return B.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){B.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),M(),l(),O())})})}function D(){u.isMode("view")||(C(),A(),P())}function R(){return s.valuesOf("hrleaveandabsences_toil_amounts",{},!1).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function S(){return l(),O(),M()}function T(){return x(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),j?j=!1:O(),M()}function O(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function I(){k=e.cloneDeep(u.request.attributes())}function x(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function L(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",R)}function M(){return m()?d().catch(a.resolve):a.resolve()}function E(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var k,j=!u.isMode("create"),B={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=v,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=S,u.openToilInDaysAccrualOptionsEditor=L,u.setDaysSelectionModeExtended=T,u.updateExpiryDate=E,function(){I(),x(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function v(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function h(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?v.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([h.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([h.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,v,h,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Le.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Le.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==F())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function L(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function F(){return Me.request?Me.request.request_type:Me.leaveType||null}function U(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Se,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(ve).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(ve).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Le.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=F(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return v.all().then(function(e){Me.absencePeriods=e})}function ie(){return h.all(j()).then(h.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Se[e+"_date"]})}function ve(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function he(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Se=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():L()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Le.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Le=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=S,Me.canSubmit=T,Me.closeAlert=x,Me.deleteLeaveRequest=E,Me.dismissModal=k,Me.getStatuses=U,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(he).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){ +function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return h().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=k.from_date!==u.request.from_date||k.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&B.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function v(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function h(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&B.hasExpirationFromAdminSettings,t=B.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return B.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){B.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),M(),l(),O())})})}function D(){u.isMode("view")||(C(),A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",{},t).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function S(){return l(),O(),M()}function T(){return x(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),j?j=!1:O(),M()}function O(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function I(){k=e.cloneDeep(u.request.attributes())}function x(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function L(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){R(!1)})}function M(){return m()?d().catch(a.resolve):a.resolve()}function E(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var k,j=!u.isMode("create"),B={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=v,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=S,u.openToilInDaysAccrualOptionsEditor=L,u.setDaysSelectionModeExtended=T,u.updateExpiryDate=E,function(){I(),x(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function v(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function h(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?v.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([h.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([h.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,v,h,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Le.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Le.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==F())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function L(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function F(){return Me.request?Me.request.request_type:Me.leaveType||null}function U(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Se,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(ve).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(ve).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Le.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=F(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return v.all().then(function(e){Me.absencePeriods=e})}function ie(){return h.all(j()).then(h.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Se[e+"_date"]})}function ve(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function he(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Se=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():L()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Le.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Le=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=S,Me.canSubmit=T,Me.closeAlert=x,Me.deleteLeaveRequest=E,Me.dismissModal=k,Me.getStatuses=U,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(he).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){ return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e){define("leave-absences/manager-leave/modules/config",["common/angular","leave-absences/manager-leave/modules/settings"],function(t){return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/manager-leave/requests"),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","leave-absences/shared/ui-router","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js index cc76e0e5cab..cc41f687c67 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js @@ -9,6 +9,6 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[m]),c[r[m]]=e[r[m]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&f(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,f),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),f.$$values=b,f.$$promises=f.$$promises||!0,delete f.$$inheritedValues,c.resolve(b))}function u(e){f.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),f=c.promise,g=f.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),f;o.$$inheritedValues&&r(b,m(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,m(o.$$values,h)),f.$$inheritedValues=m(o.$$values,h),i()):(o.$$inheritedValues&&(f.$$inheritedValues=m(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(f.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),m=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(m++,g[e].then(function(t){b[e]=t,--m||l()},c))}),m||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return f}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(m,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",m=0,f=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),f.push(g.segment),m=c.lastIndex;y=e.substring(m);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,m+_),q.length>0)for(m=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),m=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",f.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=f[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:m}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,m=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(m=e),m},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(f(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function m(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),f(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:m})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(D.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!D[r])return f(r,t.self);for(var o in R)B(R[o])&&(t[o]=R[o](t,R.$delegates[o]));return D[n]=t,!t[T]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){A.$current.navigable==t&&c(e,n)||A.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=A.$current.name.split("."),a=0,r=t.length;a=D;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=D;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.$current=t,A.current=t.self,A.params=n,V(A.params,f),A.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),A.current)}).then(null,function(a){return a===P?R:A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},A.is=function(e,t,a){a=W({relative:A.$current},a||{});var r=m(e,a.relative);return j(r)?A.$current===r&&(!t||c(r.params.$$values(t),f)):n},A.includes=function(e,t,a){if(a=W({relative:A.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=A.$current.name}var r=m(e,a.relative);if(!j(r))return n;if(!j(A.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(m&&(m.remove(),m=null),p&&(p.$destroy(),p=null),f){var e=f.data("$uiViewAnim");b.leave(f,function(){e.$$animLeave.resolve(),m=null}),m=f,f=null}}function d(s){var d,m=P(n,c,i,r),y=m&&e.$current&&e.$current.locals[m];if(s||y!==h){d=n.$new(),h=e.$current.locals[m],d.$emit("$viewContentLoading",m);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});f=_,p=d,p.$emit("$viewContentLoaded",m),p.$eval(v)}}var m,f,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function D(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=P(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var m=t.extend({},d);o[d.$$resolveAs]=m;var f=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=m),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}f(o)}}}}}function P(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function T(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function R(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function x(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function O(e,t){return{relative:R(e)||t.$current,inherit:!0}}function I(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=T(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],m=null;c.options=W(O(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var f=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),m&&m(),d&&(m=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&f(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),f(),l.clickable&&(i=x(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){m.state=t[0],m.params=t[1],m.options=t[2],m.href=e.href(m.state,m.params,m.options),f&&f(),c&&(f=c.$$addStateInfo(m.state,m.params)),m.href&&r.$set(u.attr,m.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",m={state:null,params:null,options:null,href:null},f=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=x(a,e,t,u,function(){return m}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function L(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,R(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function m(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,m){function f(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(D(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||T()})}function h(e){E.injectMonths=!0,x("injected").then(function(){T(e)}).then(function(){E.loading.calendar=!1})}function v(){O=a("LeaveCalendar"+t.capitalize(I)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(f).then(R)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return O.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function w(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return E.injectMonths&&(e=x("destroyed"),E.injectMonths=!1),e}function D(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function P(e){ e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(A).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function T(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function R(){E.selectedMonths=[n().month()]}function S(){return E.roleOverride?r.resolve().then(function(){I=E.roleOverride}):r.all([m(i.permissions.admin.administer),m(i.permissions.ssp.manage)]).then(function(e){I=e[0]?"admin":e[1]?"manager":"staff"})}function x(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var O,I,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=P,function(){S().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),w()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function m(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?f():p()}function f(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),m(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function m(e){return U[e]}function f(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){O(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",M)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function w(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function D(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function P(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function T(){return[P(u.statusNames.approved),P(u.statusNames.adminApproved),P(u.statusNames.awaitingApproval),P(u.statusNames.moreInformationRequired)]}function R(){return W.month.loading=!0,a.all([x(),S()]).then(g).then(L).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:T()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function x(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function O(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function I(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=m(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?w(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function L(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&R())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=D(e);t&&(h(t),-1!==T().indexOf(e.status_id)&&c(e))}function B(e){return a.all(A(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=I,W.contactsList=f,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),x("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return L()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(A).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,x("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function w(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(A)}function A(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function D(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():w()}function P(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function T(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function R(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function x(e){return te.selectedAbsenceType.calculation_unit_name===e}function O(e){return te.request.request_type===e}function I(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function L(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(A).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,f(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(O("sickness")||x("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(x("hours")||O("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=A,te.isCalculationUnit=x,te.isLeaveType=O,te.isNotWorkingDay=I,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),T(),te.initChildController().then(function(){return s.all([L(),E()])}).then(!te.isMode("create")&&P).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(R).then(V).then(D).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(A).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function m(){return S.getFilesAmount()0?P.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(P.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){R[e.label]=t})})).catch(function(){R=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){P=e})}function w(e){return!e.attachment_id||S.canManage}function A(){e.forEach(T,function(e){e()})}function D(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var P=[],T=[],R={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=A,S.canRemoveAttachment=w,S.canSubmit=d,S.canUploadMore=m,S.formatDateTime=f,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,r,o,s,i,u,c,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){k(e),H.sections.other.open&&f(e,H.sections.other)}function h(){Object.values(H.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):H.refresh()}function g(t){t.dataIndex=e.indexBy(t.data,"id")}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function y(){return o.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.selectedPeriod=e.find(H.absencePeriods,function(e){return!0===e.current})})}function _(){return s.all().then(s.loadCalculationUnits).then(function(t){H.absenceTypes=t,H.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return P("approved",{status_id:F(m.statusNames.approved)})}function $(){return n.all([u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,null,!0),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.approved)]),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){H.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function C(){return i.all({contact_id:H.contactId,period_id:H.selectedPeriod.id},!0).then(function(e){H.entitlements=e}).then(function(){H.absenceTypesFiltered=H.absenceTypes.filter(function(t){var n=e.find(H.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function w(){return i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id},H.entitlements).then(function(){return E(H.entitlements)}).then(function(e){H.sections.entitlements.data=e})}function A(){return n.all([i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id,expired:!0}),D({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:E(e[0]),expiredTOILS:L(e[1].list)})}).then(function(t){ -H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function D(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function P(e,t){return D(t).then(function(t){H.sections[e].data=t.list})}function T(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(O))}function R(){return P("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function S(){return P("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function x(){return P("holidays",{public_holiday:!0})}function O(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function I(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function E(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function L(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){k(e)})}function k(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([C(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([T(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&O(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:k,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:x},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([I(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([C(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return D(n,e),e})):r.reject([])}function f(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),R(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(w)).then(function(){["from","to"].forEach(function(e){b(e),T(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(R)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&T(e,!0))})}function $(e,t){return m(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return w(e).then(function(){T(e,!0)})})}function w(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){x[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return x[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function A(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function D(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function P(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),w("from").then(function(){T("from",!0)})):r.resolve()}function T(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=x[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function R(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?w("from").then(function(){T("from",!0)}):r.resolve()}var x={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=A,s.setDaysSelectionModeExtended=P}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function m(){return!!u.request.toil_to_accrue}function f(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=k.from_date!==u.request.from_date||k.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&B.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&B.hasExpirationFromAdminSettings,t=B.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return B.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){B.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(T)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function w(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function A(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function D(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),L(),l(),x())})})}function P(){u.isMode("view")||(C(),w(),D())}function T(){return s.valuesOf("hrleaveandabsences_toil_amounts",{},!1).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function R(){return l(),x(),L()}function S(){return I(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),j?j=!1:x(),L()}function x(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function O(){k=e.cloneDeep(u.request.attributes())}function I(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function E(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",T)}function L(){return f()?d().catch(a.resolve):a.resolve()}function M(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var k,j=!u.isMode("create"),B={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=m,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=A,u.initWatchersExtended=P,u.onDateChangeExtended=R,u.openToilInDaysAccrualOptionsEditor=E,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=M,function(){O(),I(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,m,f,p,h,v,g,b,y,_,q,$,C){function w(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function A(){["from","to"].forEach(w)}function D(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Re.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=P();return Le.isMode("edit")&&(e=e&&(V()||T())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function x(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function O(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==F())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function I(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){fe("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(Pe[e],function(e){return Le.requestStatuses[e]})}function F(){return Le.request?Le.request.request_type:Le.leaveType||null}function U(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Re,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Oe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Pe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Pe.awaiting_approval=e,Pe.more_information_required=e,Pe.rejected=e,Pe.approved=e,Pe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?f.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Te++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=F(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:xe}),e}function Q(){if(Ie="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Ie="admin")}).then(function(){return"staff"===Ie&&u(_.permissions.ssp.manage).then(function(e){e&&(Ie="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Ie===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){De={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:De.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){xe=e.contactId})}function le(){return Le.selectedContactId?f.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?f.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==xe})}):f.find(xe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){D(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Re[e+"_date"]})}function he(e){if(Le.absenceTypes=me(De.types,e),!Le.absenceTypes.length)return r.reject(Oe)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Re=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,x(),A(),Le.request.isValid().then(ee()&&O).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?Ae():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Te&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Te>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function we(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?fe("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var De,Pe={},Te=0,Re={},Se=[],xe="",Oe="No entitlement",Ie="",Ee=[],Le=n.assign(this,m);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=R,Le.canSubmit=S,Le.closeAlert=I,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=U,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=we,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM), +H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function D(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function P(e,t){return D(t).then(function(t){H.sections[e].data=t.list})}function T(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(O))}function R(){return P("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function S(){return P("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function x(){return P("holidays",{public_holiday:!0})}function O(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function I(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function E(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function L(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){k(e)})}function k(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([C(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([T(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&O(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:k,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:x},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([I(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([C(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return D(n,e),e})):r.reject([])}function f(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),R(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(w)).then(function(){["from","to"].forEach(function(e){b(e),T(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(R)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&T(e,!0))})}function $(e,t){return m(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return w(e).then(function(){T(e,!0)})})}function w(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){x[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return x[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function A(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function D(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function P(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),w("from").then(function(){T("from",!0)})):r.resolve()}function T(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=x[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function R(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?w("from").then(function(){T("from",!0)}):r.resolve()}var x={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=A,s.setDaysSelectionModeExtended=P}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function m(){return!!u.request.toil_to_accrue}function f(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=k.from_date!==u.request.from_date||k.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&B.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&B.hasExpirationFromAdminSettings,t=B.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return B.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){B.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(T)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function w(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function A(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function D(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),L(),l(),x())})})}function P(){u.isMode("view")||(C(),w(),D())}function T(t){return s.valuesOf("hrleaveandabsences_toil_amounts",{},t).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function R(){return l(),x(),L()}function S(){return I(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),j?j=!1:x(),L()}function x(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function O(){k=e.cloneDeep(u.request.attributes())}function I(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function E(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){T(!1)})}function L(){return f()?d().catch(a.resolve):a.resolve()}function M(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var k,j=!u.isMode("create"),B={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=m,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=A,u.initWatchersExtended=P,u.onDateChangeExtended=R,u.openToilInDaysAccrualOptionsEditor=E,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=M,function(){O(),I(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,m,f,p,h,v,g,b,y,_,q,$,C){function w(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function A(){["from","to"].forEach(w)}function D(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Re.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=P();return Le.isMode("edit")&&(e=e&&(V()||T())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function x(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function O(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==F())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function I(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){fe("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(Pe[e],function(e){return Le.requestStatuses[e]})}function F(){return Le.request?Le.request.request_type:Le.leaveType||null}function U(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Re,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Oe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Pe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Pe.awaiting_approval=e,Pe.more_information_required=e,Pe.rejected=e,Pe.approved=e,Pe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?f.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Te++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=F(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:xe}),e}function Q(){if(Ie="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Ie="admin")}).then(function(){return"staff"===Ie&&u(_.permissions.ssp.manage).then(function(e){e&&(Ie="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Ie===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){De={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:De.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){xe=e.contactId})}function le(){return Le.selectedContactId?f.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?f.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==xe})}):f.find(xe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){D(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Re[e+"_date"]})}function he(e){if(Le.absenceTypes=me(De.types,e),!Le.absenceTypes.length)return r.reject(Oe)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Re=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,x(),A(),Le.request.isValid().then(ee()&&O).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?Ae():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Te&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Te>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function we(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?fe("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var De,Pe={},Te=0,Re={},Se=[],xe="",Oe="No entitlement",Ie="",Ee=[],Le=n.assign(this,m);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=R,Le.canSubmit=S,Le.closeAlert=I,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=U,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=we,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM), define("leave-absences/my-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/models/option-group","common/modules/dialog","common/services/check-permissions","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/my-leave/components/my-leave-container.component","leave-absences/my-leave/modules/config"],function(e){return e.module("my-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.mocks","common.models","common.services","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","my-leave.components","my-leave.config"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/my-leave":n+"/my-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/my-leave/app"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-my-leave]"),["my-leave"])})})}(CRM,require),define("my-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js index 36fd5d75a16..ec292edba55 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js @@ -12,7 +12,7 @@ define([ 'crmAngService', 'api.optionGroup', 'AbsenceType', 'detailsController']; function RequestModalDetailsToilController ($log, $q, $rootScope, - crmAngService, OptionGroup, AbsenceType, detailsController) { + crmAngService, OptionGroupAPI, AbsenceType, detailsController) { $log.debug('RequestModalDetailsToilController'); var initialRequestAttributes; @@ -349,10 +349,11 @@ define([ /** * Initializes leave request toil amounts * + * @param {Boolean} cache if to cache results of the API call, cache by default * @return {Promise} */ - function loadToilAmounts () { - return OptionGroup.valuesOf('hrleaveandabsences_toil_amounts', {}, false) + function loadToilAmounts (cache) { + return OptionGroupAPI.valuesOf('hrleaveandabsences_toil_amounts', {}, cache) .then(function (amounts) { detailsController.toilAmounts = _.sortBy(amounts, 'value'); }); @@ -423,7 +424,9 @@ define([ */ function openToilInDaysAccrualOptionsEditor () { crmAngService.loadForm('/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1') - .on('crmFormSuccess', loadToilAmounts); + .on('crmFormSuccess', function () { + loadToilAmounts(false); + }); } /** diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js index 3f7320d3a1b..a27f782da98 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js @@ -24,7 +24,8 @@ define([ describe('RequestModalDetailsToilController', function () { var $componentController, $provide, $q, $log, $rootScope, crmAngService, controller, - AbsenceType, AbsenceTypeAPI, leaveRequest, LeaveRequestInstance, TOILRequestInstance; + AbsenceType, AbsenceTypeAPI, leaveRequest, LeaveRequestInstance, + OptionGroupAPI, TOILRequestInstance; var date2016 = '01/12/2016'; var date2016To = '02/12/2016'; // Must be greater than `date2016` @@ -47,6 +48,10 @@ define([ $provide.value('HR_settings', _HRSettingsMock_); }])); + beforeEach(inject(['api.optionGroup', function (_optionGroupAPI_) { + OptionGroupAPI = _optionGroupAPI_; + }])); + beforeEach(inject(function ( _$componentController_, _$q_, _$log_, _$rootScope_, _AbsenceType_, _AbsenceTypeAPI_, _crmAngService_, _LeaveRequestInstance_, _TOILRequestInstance_) { @@ -64,6 +69,7 @@ define([ spyOn(AbsenceTypeAPI, 'calculateToilExpiryDate').and.callThrough(); spyOn(AbsenceType, 'canExpire').and.callThrough(); spyOn(AbsenceType, 'calculateToilExpiryDate').and.callThrough(); + spyOn(OptionGroupAPI, 'valuesOf').and.callThrough(); crmAngService.loadForm = function () { return { @@ -97,11 +103,15 @@ define([ expect(controller.isLeaveType('toil')).toBeTruthy(); }); - it('loads toil amounts', function () { + it('loads TOIL accrual options', function () { expect(Object.keys(controller.toilAmounts).length).toBeGreaterThan(0); }); - it('sorts toil amounts by value', function () { + it('caches TOIL accrual options', function () { + expect(OptionGroupAPI.valuesOf.calls.mostRecent().args[2]).not.toBe(false); + }); + + it('sorts TOIL accrual options by value', function () { expect(_.pluck(controller.toilAmounts, 'value')).toEqual( _.pluck(controller.toilAmounts, 'value').sort()); }); @@ -314,7 +324,7 @@ define([ }); }); - describe('when user opens toil accrual option group editor', function () { + describe('when user opens TOIL accrual options group editor', function () { beforeEach(function () { // flushing TOIL accrual options controller.toilAmounts = null; @@ -332,9 +342,13 @@ define([ $rootScope.$digest(); }); - it('reloads TOIL accrual values', function () { + it('reloads TOIL accrual options', function () { expect(Object.keys(controller.toilAmounts).length).toBeGreaterThan(0); }); + + it('does not cache TOIL accrual options', function () { + expect(OptionGroupAPI.valuesOf.calls.mostRecent().args[2]).toBe(false); + }); }); }); }); @@ -408,7 +422,7 @@ define([ expect(controller.request.toil_expiry_date).toEqual(oldExpiryDate); }); - it('has toil amount set by manager', function () { + it('has TOIL amount set by manager', function () { expect(controller.request.toil_to_accrue).toEqual(originalToilToAccrue.value); }); }); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/models/absence-type.model.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/models/absence-type.model.spec.js index 948f9a276f9..e24bc5f7ce2 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/models/absence-type.model.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/models/absence-type.model.spec.js @@ -10,7 +10,7 @@ define([ 'use strict'; describe('AbsenceType', function () { - var $provide, AbsenceType, AbsenceTypeAPI, OptionGroupAPI, $rootScope, $q; + var $provide, $q, $rootScope, AbsenceType, AbsenceTypeAPI, OptionGroup; beforeEach(module('leave-absences.models', 'leave-absences.mocks', function (_$provide_) { $provide = _$provide_; @@ -20,21 +20,20 @@ define([ $provide.value('AbsenceTypeAPI', _AbsenceTypeAPIMock_); })); - beforeEach(inject(['api.optionGroup.mock', 'api.optionGroup.mock', function (_OptionGroupAPI_, _OptionGroupAPIMock_) { - OptionGroupAPI = _OptionGroupAPI_; - + beforeEach(inject(['api.optionGroup.mock', function (_OptionGroupAPIMock_) { $provide.value('api.optionGroup', _OptionGroupAPIMock_); }])); - beforeEach(inject(function (_AbsenceType_, _AbsenceTypeAPI_, _$rootScope_, _$q_) { - AbsenceType = _AbsenceType_; - AbsenceTypeAPI = _AbsenceTypeAPI_; + beforeEach(inject(function (_$q_, _$rootScope_, _AbsenceType_, _AbsenceTypeAPI_, _OptionGroup_) { $q = _$q_; $rootScope = _$rootScope_; + AbsenceType = _AbsenceType_; + AbsenceTypeAPI = _AbsenceTypeAPI_; + OptionGroup = _OptionGroup_; spyOn(AbsenceTypeAPI, 'all').and.callThrough(); spyOn(AbsenceTypeAPI, 'calculateToilExpiryDate').and.callThrough(); - spyOn(OptionGroupAPI, 'valuesOf').and.callThrough(); + spyOn(OptionGroup, 'valuesOf').and.callThrough(); })); it('has expected interface', function () { @@ -156,7 +155,7 @@ define([ }); it('retrieves calculation unit option group', function () { - expect(OptionGroupAPI.valuesOf).toHaveBeenCalledWith( + expect(OptionGroup.valuesOf).toHaveBeenCalledWith( 'hrleaveandabsences_absence_type_calculation_unit'); }); From e5624e7d06b05a8e9ff8578444f21f2d8cafb139 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Wed, 28 Mar 2018 15:22:29 +0100 Subject: [PATCH 099/203] PCHR-3494: Improve caching --- .../src/common/services/api.js | 49 ++++++++---- .../test/services/api.spec.js | 78 +++++++++++++++++-- 2 files changed, 106 insertions(+), 21 deletions(-) diff --git a/org.civicrm.reqangular/src/common/services/api.js b/org.civicrm.reqangular/src/common/services/api.js index 063be50366f..3395151138f 100644 --- a/org.civicrm.reqangular/src/common/services/api.js +++ b/org.civicrm.reqangular/src/common/services/api.js @@ -7,7 +7,7 @@ define([ ], function (angular, _, apis) { 'use strict'; - apis.factory('api', ['$log', '$http', '$httpParamSerializer', '$q', '$timeout', function ($log, $http, $httpParamSerializer, $q, $timeout) { + apis.factory('api', ['$cacheFactory', '$log', '$http', '$httpParamSerializer', '$q', '$timeout', function ($cacheFactory, $log, $http, $httpParamSerializer, $q, $timeout) { $log.debug('api'); var API_ENDPOINT = '/civicrm/ajax/rest'; @@ -42,6 +42,20 @@ define([ return JSON.stringify(_.merge(defaults, params || {})); } + /** + * Constructs a GET query string exactly the same way as $http service does + * + * @param {Object} json that is passed as "params" to $http + * @return {String} query string + */ + function jsonToQueryString (json) { + return '?' + Object.keys(json).sort().map(function (key) { + return (encodeURIComponent(key) + '=' + encodeURIComponent(json[key])) + .replace(/%3A/g, ':') + .replace(/%2C/g, ','); + }).join('&'); + } + return { /** @@ -140,24 +154,33 @@ define([ /** * Sends a GET request to the backend endpoint * - * @param {string} entity - The entity the request is asking for (Contact, Appraisal, etc) - * @param {string} action - The action to perform - * @param {object} params - Any additional parameters to pass in the request - * @param {boolean} cache - If the response should be cached (default = true) + * @param {String} entity - The entity the request is asking for (Contact, Appraisal, etc) + * @param {String} action - The action to perform + * @param {Object} params - Any additional parameters to pass in the request + * @param {Boolean} returnCachedData + * - if passed as TRUE or not passed, returns data from cache (if not the first call) + * - if passed as FALSE, returns updated data from API and caches for future requests * @return {Promise} */ - sendGET: function (entity, action, params, cache) { + sendGET: function (entity, action, params, returnCachedData) { + var queryJSON = { + action: action, + entity: entity, + json: prepareParams(params), + sequential: 1 + }; + + if (returnCachedData === false) { + $cacheFactory.get('$http').remove( + API_ENDPOINT + jsonToQueryString(queryJSON)); + } + return $http({ method: 'GET', url: API_ENDPOINT, - cache: (typeof cache !== 'undefined' ? !!cache : true), + cache: true, responseType: 'json', - params: { - sequential: 1, - json: prepareParams(params), - entity: entity, - action: action - } + params: queryJSON }).then(responseHandler); }, diff --git a/org.civicrm.reqangular/test/services/api.spec.js b/org.civicrm.reqangular/test/services/api.spec.js index 2dae65bbd24..fb2dce3c798 100644 --- a/org.civicrm.reqangular/test/services/api.spec.js +++ b/org.civicrm.reqangular/test/services/api.spec.js @@ -8,23 +8,27 @@ define([ 'use strict'; describe('api', function () { - var api, $httpBackend, $httpParamSerializer, $rootScope; + var api, $cacheFactory, $httpBackend, $httpParamSerializer, $rootScope; var entity = 'entity'; var action = 'action'; beforeEach(module('common.apis')); - beforeEach(inject(function (_api_, _$httpBackend_, _$httpParamSerializer_, _$rootScope_) { + beforeEach(inject(function (_api_, _$cacheFactory_, _$httpBackend_, + _$httpParamSerializer_, _$rootScope_) { api = _api_; + $cacheFactory = _$cacheFactory_; $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; $rootScope = _$rootScope_; })); - describe('sendGET', function () { + describe('sendGET()', function () { var promise; - afterEach(function () { $httpBackend.flush(); }); + afterEach(function () { + $httpBackend.flush(); + }); describe('when the API does not return an error', function () { var returnValue = { @@ -99,26 +103,84 @@ define([ }); }); + describe('caching', function () { + var sampleResult = 'sample result'; + var sampleParams = {}; + + beforeEach(function () { + spyOn($cacheFactory.get('$http'), 'remove').and.callThrough(); + }); + + describe('when "returnCachedData" parameter is not passed', function () { + beforeEach(function () { + expectAndSendGET(sampleResult, sampleParams); + $rootScope.$digest(); + }); + + it('does not flush cache before HTTP call', function () { + expect($cacheFactory.get('$http').remove).not.toHaveBeenCalled(); + }); + + it('caches data by default', function () { + expect($cacheFactory.get('$http').info().size).toBe(1); + }); + }); + + describe('when "returnCachedData" parameter passed as TRUE', function () { + beforeEach(function () { + expectAndSendGET(sampleResult, sampleParams, true); + $rootScope.$digest(); + }); + + it('does not flush cache before HTTP call', function () { + expect($cacheFactory.get('$http').remove).not.toHaveBeenCalled(); + }); + + it('caches data', function () { + expect($cacheFactory.get('$http').info().size).toBe(1); + }); + }); + + describe('when "returnCachedData" parameter passed as FALSE', function () { + beforeEach(function () { + expectAndSendGET(sampleResult, sampleParams, false); + $rootScope.$digest(); + }); + + it('flushes cache before HTTP call', function () { + expect($cacheFactory.get('$http').remove).toHaveBeenCalledWith( + '/civicrm/ajax/rest?action=action&entity=entity&json=%7B%22options%22:%7B%22limit%22:0%7D%7D&sequential=1'); + }); + + it('caches updated data for future requests', function () { + expect($cacheFactory.get('$http').info().size).toBe(1); + }); + }); + }); + /** * Mocks and sends a fake GET request * * @param {any} returnValue - value to be returned by the GET request * @param {Object} params - params to be used in the API call + * @param {Boolean} cache * @return {Promise} */ - function expectAndSendGET (returnValue, params) { + function expectAndSendGET (returnValue, params, cache) { $httpBackend .whenGET(new RegExp('action=' + action + '&entity=' + entity)) .respond(returnValue); - return api.sendGET(entity, action, params, true); + return api.sendGET(entity, action, params, cache); } }); - describe('sendPOST', function () { + describe('sendPOST()', function () { var promise; - afterEach(function () { $httpBackend.flush(); }); + afterEach(function () { + $httpBackend.flush(); + }); describe('when the API doesnt return an error', function () { var returnValue = { From 1fd86686036ffc95631808c9979215fb66bf784a Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Wed, 28 Mar 2018 15:24:08 +0100 Subject: [PATCH 100/203] PCHR-3494: PR Feedback 2 --- org.civicrm.reqangular/dist/reqangular.min.js | 8 ++++---- .../src/common/models/option-group.js | 5 +++-- .../test/models/option-group.spec.js | 18 +++++++++++++++--- .../js/angular/dist/absence-tab.min.js | 4 ++-- .../js/angular/dist/admin-dashboard.min.js | 2 +- .../js/angular/dist/manager-leave.min.js | 2 +- .../js/angular/dist/my-leave.min.js | 2 +- .../request-modal-details-toil.controller.js | 6 +++--- ...quest-modal-details-toil.controller.spec.js | 15 ++++++--------- 9 files changed, 36 insertions(+), 26 deletions(-) diff --git a/org.civicrm.reqangular/dist/reqangular.min.js b/org.civicrm.reqangular/dist/reqangular.min.js index 29dbc56a43a..92f4e7a2f35 100644 --- a/org.civicrm.reqangular/dist/reqangular.min.js +++ b/org.civicrm.reqangular/dist/reqangular.min.js @@ -114,8 +114,8 @@ return e=os.day(e),e.setMonth(0,1),e},function(e,t){e.setFullYear(e.getFullYear( e.x=(e.x-l.x)*r[0],e.y=(l.y-e.y)*r[1]}:function(e){e.x=(e.x-d)/(p-d)*r[0],e.y=(1-(l.y?e.y/l.y:1))*r[1]}),s}var t=na.layout.hierarchy().sort(null).value(null),n=Ei,r=[1,1],i=!1;return e.separation=function(t){return arguments.length?(n=t,e):n},e.size=function(t){return arguments.length?(i=null==(r=t),e):i?null:r},e.nodeSize=function(t){return arguments.length?(i=null!=(r=t),e):i?r:null},Qr(e,t)},na.layout.treemap=function(){function e(e,t){for(var n,r,i=-1,o=e.length;++it?0:t),n.area=isNaN(r)||0>=r?0:r}function t(n){var o=n.children;if(o&&o.length){var a,s,l,u=f(n),c=[],d=o.slice(),h=1/0,m="slice"===p?u.dx:"dice"===p?u.dy:"slice-dice"===p?1&n.depth?u.dy:u.dx:Math.min(u.dx,u.dy);for(e(d,u.dx*u.dy/n.value),c.area=0;(l=d.length)>0;)c.push(a=d[l-1]),c.area+=a.area,"squarify"!==p||(s=r(c,m))<=h?(d.pop(),h=s):(c.area-=c.pop().area,i(c,m,u,!1),m=Math.min(u.dx,u.dy),c.length=c.area=0,h=1/0);c.length&&(i(c,m,u,!0),c.length=c.area=0),o.forEach(t)}}function n(t){var r=t.children;if(r&&r.length){var o,a=f(t),s=r.slice(),l=[];for(e(s,a.dx*a.dy/t.value),l.area=0;o=s.pop();)l.push(o),l.area+=o.area,null!=o.z&&(i(l,o.z?a.dx:a.dy,a,!s.length),l.length=l.area=0);r.forEach(n)}}function r(e,t){for(var n,r=e.area,i=0,o=1/0,a=-1,s=e.length;++an&&(o=n),n>i&&(i=n));return r*=r,t*=t,r?Math.max(t*i*h/r,r/(t*o*h)):1/0}function i(e,t,n,r){var i,o=-1,a=e.length,s=n.x,u=n.y,c=t?l(e.area/t):0;if(t==n.dx){for((r||c>n.dy)&&(c=n.dy);++on.dx)&&(c=n.dx);++on&&(t=1),1>n&&(e=0),function(){var n,r,i;do{n=2*Math.random()-1,r=2*Math.random()-1,i=n*n+r*r}while(!i||i>1);return e+t*n*Math.sqrt(-2*Math.log(i)/i)}},logNormal:function(){var e=na.random.normal.apply(na,arguments);return function(){return Math.exp(e())}},bates:function(e){var t=na.random.irwinHall(e);return function(){return t()/e}},irwinHall:function(e){return function(){for(var t=0,n=0;e>n;n++)t+=Math.random();return t}}},na.scale={};var ml={floor:y,ceil:y};na.scale.linear=function(){return Vi([0,1],[0,1],yr,!1)};var gl={s:1,g:1,p:1,r:1,e:1};na.scale.log=function(){return Ji(na.scale.linear().domain([0,1]),10,!0,[1,10])};var vl=na.format(".0e"),yl={floor:function(e){return-Math.ceil(-e)},ceil:function(e){return-Math.floor(-e)}};na.scale.pow=function(){return Qi(na.scale.linear(),1,[0,1])},na.scale.sqrt=function(){return na.scale.pow().exponent(.5)},na.scale.ordinal=function(){return eo([],{t:"range",a:[[]]})},na.scale.category10=function(){return na.scale.ordinal().range(bl)},na.scale.category20=function(){return na.scale.ordinal().range($l)},na.scale.category20b=function(){return na.scale.ordinal().range(wl)},na.scale.category20c=function(){return na.scale.ordinal().range(xl)};var bl=[2062260,16744206,2924588,14034728,9725885,9197131,14907330,8355711,12369186,1556175].map(be),$l=[2062260,11454440,16744206,16759672,2924588,10018698,14034728,16750742,9725885,12955861,9197131,12885140,14907330,16234194,8355711,13092807,12369186,14408589,1556175,10410725].map(be),wl=[3750777,5395619,7040719,10264286,6519097,9216594,11915115,13556636,9202993,12426809,15186514,15190932,8666169,11356490,14049643,15177372,8077683,10834324,13528509,14589654].map(be),xl=[3244733,7057110,10406625,13032431,15095053,16616764,16625259,16634018,3253076,7652470,10607003,13101504,7695281,10394312,12369372,14342891,6513507,9868950,12434877,14277081].map(be);na.scale.quantile=function(){return to([],[])},na.scale.quantize=function(){return no(0,1,[0,1])},na.scale.threshold=function(){return ro([.5],[0,1])},na.scale.identity=function(){return io([0,1])},na.svg={},na.svg.arc=function(){function e(){var e=Math.max(0,+n.apply(this,arguments)),u=Math.max(0,+r.apply(this,arguments)),c=a.apply(this,arguments)-Na,f=s.apply(this,arguments)-Na,d=Math.abs(f-c),p=c>f?0:1;if(e>u&&(h=u,u=e,e=h),d>=Oa)return t(u,p)+(e?t(e,1-p):"")+"Z";var h,m,g,v,y,b,$,w,x,C,k,E,S=0,_=0,M=[];if((v=(+l.apply(this,arguments)||0)/2)&&(g=o===Cl?Math.sqrt(e*e+u*u):+o.apply(this,arguments),p||(_*=-1),u&&(_=te(g/u*Math.sin(v))),e&&(S=te(g/e*Math.sin(v)))),u){y=u*Math.cos(c+_),b=u*Math.sin(c+_),$=u*Math.cos(f-_),w=u*Math.sin(f-_);var T=Math.abs(f-c-2*_)<=Da?0:1;if(_&&fo(y,b,$,w)===p^T){var D=(c+f)/2;y=u*Math.cos(D),b=u*Math.sin(D),$=w=null}}else y=b=0;if(e){x=e*Math.cos(f-S),C=e*Math.sin(f-S),k=e*Math.cos(c+S),E=e*Math.sin(c+S);var A=Math.abs(c-f+2*S)<=Da?0:1;if(S&&fo(x,C,k,E)===1-p^A){var O=(c+f)/2;x=e*Math.cos(O),C=e*Math.sin(O),k=E=null}}else x=C=0;if((h=Math.min(Math.abs(u-e)/2,+i.apply(this,arguments)))>.001){m=u>e^p?0:1;var N=null==k?[x,C]:null==$?[y,b]:Nn([y,b],[k,E],[$,w],[x,C]),R=y-N[0],I=b-N[1],P=$-N[0],F=w-N[1],j=1/Math.sin(Math.acos((R*P+I*F)/(Math.sqrt(R*R+I*I)*Math.sqrt(P*P+F*F)))/2),L=Math.sqrt(N[0]*N[0]+N[1]*N[1]);if(null!=$){var U=Math.min(h,(u-L)/(j+1)),H=po(null==k?[x,C]:[k,E],[y,b],u,U,p),q=po([$,w],[x,C],u,U,p);h===U?M.push("M",H[0],"A",U,",",U," 0 0,",m," ",H[1],"A",u,",",u," 0 ",1-p^fo(H[1][0],H[1][1],q[1][0],q[1][1]),",",p," ",q[1],"A",U,",",U," 0 0,",m," ",q[0]):M.push("M",H[0],"A",U,",",U," 0 1,",m," ",q[0])}else M.push("M",y,",",b);if(null!=k){var V=Math.min(h,(e-L)/(j-1)),z=po([y,b],[k,E],e,-V,p),B=po([x,C],null==$?[y,b]:[$,w],e,-V,p);h===V?M.push("L",B[0],"A",V,",",V," 0 0,",m," ",B[1],"A",e,",",e," 0 ",p^fo(B[1][0],B[1][1],z[1][0],z[1][1]),",",1-p," ",z[1],"A",V,",",V," 0 0,",m," ",z[0]):M.push("L",B[0],"A",V,",",V," 0 0,",m," ",z[0])}else M.push("L",x,",",C)}else M.push("M",y,",",b),null!=$&&M.push("A",u,",",u," 0 ",T,",",p," ",$,",",w),M.push("L",x,",",C),null!=k&&M.push("A",e,",",e," 0 ",A,",",1-p," ",k,",",E);return M.push("Z"),M.join("")}function t(e,t){return"M0,"+e+"A"+e+","+e+" 0 1,"+t+" 0,"+-e+"A"+e+","+e+" 0 1,"+t+" 0,"+e}var n=ao,r=so,i=oo,o=Cl,a=lo,s=uo,l=co;return e.innerRadius=function(t){return arguments.length?(n=Se(t),e):n},e.outerRadius=function(t){return arguments.length?(r=Se(t),e):r},e.cornerRadius=function(t){return arguments.length?(i=Se(t),e):i},e.padRadius=function(t){return arguments.length?(o=t==Cl?Cl:Se(t),e):o},e.startAngle=function(t){return arguments.length?(a=Se(t),e):a},e.endAngle=function(t){return arguments.length?(s=Se(t),e):s},e.padAngle=function(t){return arguments.length?(l=Se(t),e):l},e.centroid=function(){var e=(+n.apply(this,arguments)+ +r.apply(this,arguments))/2,t=(+a.apply(this,arguments)+ +s.apply(this,arguments))/2-Na;return[Math.cos(t)*e,Math.sin(t)*e]},e};var Cl="auto";na.svg.line=function(){return ho(y)};var kl=na.map({linear:mo,"linear-closed":go,step:vo,"step-before":yo,"step-after":bo,basis:Eo,"basis-open":So,"basis-closed":_o,bundle:Mo,cardinal:xo,"cardinal-open":$o,"cardinal-closed":wo,monotone:Ro});kl.forEach(function(e,t){t.key=e,t.closed=/-closed$/.test(e)});var El=[0,2/3,1/3,0],Sl=[0,1/3,2/3,0],_l=[0,1/6,2/3,1/6];na.svg.line.radial=function(){var e=ho(Io);return e.radius=e.x,delete e.x,e.angle=e.y,delete e.y,e},yo.reverse=bo,bo.reverse=yo,na.svg.area=function(){return Po(y)},na.svg.area.radial=function(){var e=Po(Io);return e.radius=e.x,delete e.x,e.innerRadius=e.x0,delete e.x0,e.outerRadius=e.x1,delete e.x1,e.angle=e.y,delete e.y,e.startAngle=e.y0,delete e.y0,e.endAngle=e.y1,delete e.y1,e},na.svg.chord=function(){function e(e,s){var l=t(this,o,e,s),u=t(this,a,e,s);return"M"+l.p0+r(l.r,l.p1,l.a1-l.a0)+(n(l,u)?i(l.r,l.p1,l.r,l.p0):i(l.r,l.p1,u.r,u.p0)+r(u.r,u.p1,u.a1-u.a0)+i(u.r,u.p1,l.r,l.p0))+"Z"}function t(e,t,n,r){var i=t.call(e,n,r),o=s.call(e,i,r),a=l.call(e,i,r)-Na,c=u.call(e,i,r)-Na;return{r:o,a0:a,a1:c,p0:[o*Math.cos(a),o*Math.sin(a)],p1:[o*Math.cos(c),o*Math.sin(c)]}}function n(e,t){return e.a0==t.a0&&e.a1==t.a1}function r(e,t,n){return"A"+e+","+e+" 0 "+ +(n>Da)+",1 "+t}function i(e,t,n,r){return"Q 0,0 "+r}var o=yn,a=bn,s=Fo,l=lo,u=uo;return e.radius=function(t){return arguments.length?(s=Se(t),e):s},e.source=function(t){return arguments.length?(o=Se(t),e):o},e.target=function(t){return arguments.length?(a=Se(t),e):a},e.startAngle=function(t){return arguments.length?(l=Se(t),e):l},e.endAngle=function(t){return arguments.length?(u=Se(t),e):u},e},na.svg.diagonal=function(){function e(e,i){var o=t.call(this,e,i),a=n.call(this,e,i),s=(o.y+a.y)/2,l=[o,{x:o.x,y:s},{x:a.x,y:s},a];return l=l.map(r),"M"+l[0]+"C"+l[1]+" "+l[2]+" "+l[3]}var t=yn,n=bn,r=jo;return e.source=function(n){return arguments.length?(t=Se(n),e):t},e.target=function(t){return arguments.length?(n=Se(t),e):n},e.projection=function(t){return arguments.length?(r=t,e):r},e},na.svg.diagonal.radial=function(){var e=na.svg.diagonal(),t=jo,n=e.projection;return e.projection=function(e){return arguments.length?n(Lo(t=e)):t},e},na.svg.symbol=function(){function e(e,r){return(Ml.get(t.call(this,e,r))||qo)(n.call(this,e,r))}var t=Ho,n=Uo;return e.type=function(n){return arguments.length?(t=Se(n),e):t},e.size=function(t){return arguments.length?(n=Se(t),e):n},e};var Ml=na.map({circle:qo,cross:function(e){var t=Math.sqrt(e/5)/2;return"M"+-3*t+","+-t+"H"+-t+"V"+-3*t+"H"+t+"V"+-t+"H"+3*t+"V"+t+"H"+t+"V"+3*t+"H"+-t+"V"+t+"H"+-3*t+"Z"},diamond:function(e){var t=Math.sqrt(e/(2*Dl)),n=t*Dl;return"M0,"+-t+"L"+n+",0 0,"+t+" "+-n+",0Z"},square:function(e){var t=Math.sqrt(e)/2;return"M"+-t+","+-t+"L"+t+","+-t+" "+t+","+t+" "+-t+","+t+"Z"},"triangle-down":function(e){var t=Math.sqrt(e/Tl),n=t*Tl/2;return"M0,"+n+"L"+t+","+-n+" "+-t+","+-n+"Z"},"triangle-up":function(e){var t=Math.sqrt(e/Tl),n=t*Tl/2;return"M0,"+-n+"L"+t+","+n+" "+-t+","+n+"Z"}});na.svg.symbolTypes=Ml.keys();var Tl=Math.sqrt(3),Dl=Math.tan(30*Ra);wa.transition=function(e){for(var t,n,r=Al||++Il,i=Wo(e),o=[],a=Ol||{time:Date.now(),ease:Er,delay:0,duration:250},s=-1,l=this.length;++so;o++){i.push(t=[]);for(var n=this[o],s=0,l=n.length;l>s;s++)(r=n[s])&&e.call(r,r.__data__,s,o)&&t.push(r)}return zo(i,this.namespace,this.id)},Rl.tween=function(e,t){var n=this.id,r=this.namespace;return arguments.length<2?this.node()[r][n].tween.get(e):V(this,null==t?function(t){t[r][n].tween.remove(e)}:function(i){i[r][n].tween.set(e,t)})},Rl.attr=function(e,t){function n(){this.removeAttribute(s)}function r(){this.removeAttributeNS(s.space,s.local)}function i(e){return null==e?n:(e+="",function(){var t,n=this.getAttribute(s);return n!==e&&(t=a(n,e),function(e){this.setAttribute(s,t(e))})})}function o(e){return null==e?r:(e+="",function(){var t,n=this.getAttributeNS(s.space,s.local);return n!==e&&(t=a(n,e),function(e){this.setAttributeNS(s.space,s.local,t(e))})})}if(arguments.length<2){for(t in e)this.attr(t,e[t]);return this}var a="transform"==e?Hr:yr,s=na.ns.qualify(e);return Bo(this,"attr."+e,t,s.local?o:i)},Rl.attrTween=function(e,t){function n(e,n){var r=t.call(this,e,n,this.getAttribute(i));return r&&function(e){this.setAttribute(i,r(e))}}function r(e,n){var r=t.call(this,e,n,this.getAttributeNS(i.space,i.local));return r&&function(e){this.setAttributeNS(i.space,i.local,r(e))}}var i=na.ns.qualify(e);return this.tween("attr."+e,i.local?r:n)},Rl.style=function(e,n,r){function i(){this.style.removeProperty(e)}function o(n){return null==n?i:(n+="",function(){var i,o=t(this).getComputedStyle(this,null).getPropertyValue(e);return o!==n&&(i=yr(o,n),function(t){this.style.setProperty(e,i(t),r)})})}var a=arguments.length;if(3>a){if("string"!=typeof e){2>a&&(n="");for(r in e)this.style(r,e[r],n);return this}r=""}return Bo(this,"style."+e,n,o)},Rl.styleTween=function(e,n,r){function i(i,o){var a=n.call(this,i,o,t(this).getComputedStyle(this,null).getPropertyValue(e));return a&&function(t){this.style.setProperty(e,a(t),r)}}return arguments.length<3&&(r=""),this.tween("style."+e,i)},Rl.text=function(e){return Bo(this,"text",e,Yo)},Rl.remove=function(){var e=this.namespace;return this.each("end.transition",function(){var t;this[e].count<2&&(t=this.parentNode)&&t.removeChild(this)})},Rl.ease=function(e){var t=this.id,n=this.namespace;return arguments.length<1?this.node()[n][t].ease:("function"!=typeof e&&(e=na.ease.apply(na,arguments)),V(this,function(r){r[n][t].ease=e}))},Rl.delay=function(e){var t=this.id,n=this.namespace;return arguments.length<1?this.node()[n][t].delay:V(this,"function"==typeof e?function(r,i,o){r[n][t].delay=+e.call(r,r.__data__,i,o)}:(e=+e,function(r){r[n][t].delay=e}))},Rl.duration=function(e){var t=this.id,n=this.namespace;return arguments.length<1?this.node()[n][t].duration:V(this,"function"==typeof e?function(r,i,o){r[n][t].duration=Math.max(1,e.call(r,r.__data__,i,o))}:(e=Math.max(1,e),function(r){r[n][t].duration=e}))},Rl.each=function(e,t){var n=this.id,r=this.namespace;if(arguments.length<2){var i=Ol,o=Al;try{Al=n,V(this,function(t,i,o){Ol=t[r][n],e.call(t,t.__data__,i,o)})}finally{Ol=i,Al=o}}else V(this,function(i){var o=i[r][n];(o.event||(o.event=na.dispatch("start","end","interrupt"))).on(e,t)});return this},Rl.transition=function(){for(var e,t,n,r,i=this.id,o=++Il,a=this.namespace,s=[],l=0,u=this.length;u>l;l++){s.push(e=[]);for(var t=this[l],c=0,f=t.length;f>c;c++)(n=t[c])&&(r=n[a][i],Go(n,c,a,o,{time:r.time,ease:r.ease,delay:r.delay+r.duration,duration:r.duration})),e.push(n)}return zo(s,a,o)},na.svg.axis=function(){function e(e){e.each(function(){var e,u=na.select(this),c=this.__chart__||n,f=this.__chart__=n.copy(),d=null==l?f.ticks?f.ticks.apply(f,s):f.domain():l,p=null==t?f.tickFormat?f.tickFormat.apply(f,s):y:t,h=u.selectAll(".tick").data(d,f),m=h.enter().insert("g",".domain").attr("class","tick").style("opacity",Ma),g=na.transition(h.exit()).style("opacity",Ma).remove(),v=na.transition(h.order()).style("opacity",1),b=Math.max(i,0)+a,$=ji(f),w=u.selectAll(".domain").data([0]),x=(w.enter().append("path").attr("class","domain"),na.transition(w));m.append("line"),m.append("text");var C,k,E,S,_=m.select("line"),M=v.select("line"),T=h.select("text").text(p),D=m.select("text"),A=v.select("text"),O="top"===r||"left"===r?-1:1;if("bottom"===r||"top"===r?(e=Ko,C="x",E="y",k="x2",S="y2",T.attr("dy",0>O?"0em":".71em").style("text-anchor","middle"),x.attr("d","M"+$[0]+","+O*o+"V0H"+$[1]+"V"+O*o)):(e=Zo,C="y",E="x",k="y2",S="x2",T.attr("dy",".32em").style("text-anchor",0>O?"end":"start"),x.attr("d","M"+O*o+","+$[0]+"H0V"+$[1]+"H"+O*o)),_.attr(S,O*i),D.attr(E,O*b),M.attr(k,0).attr(S,O*i),A.attr(C,0).attr(E,O*b),f.rangeBand){var N=f,R=N.rangeBand()/2;c=f=function(e){return N(e)+R}}else c.rangeBand?c=f:g.call(e,f,c);m.call(e,c,f),v.call(e,f,f)})}var t,n=na.scale.linear(),r=Pl,i=6,o=6,a=3,s=[10],l=null;return e.scale=function(t){return arguments.length?(n=t,e):n},e.orient=function(t){return arguments.length?(r=t in Fl?t+"":Pl,e):r},e.ticks=function(){return arguments.length?(s=arguments,e):s},e.tickValues=function(t){return arguments.length?(l=t,e):l},e.tickFormat=function(n){return arguments.length?(t=n,e):t},e.tickSize=function(t){var n=arguments.length;return n?(i=+t,o=+arguments[n-1],e):i},e.innerTickSize=function(t){return arguments.length?(i=+t,e):i},e.outerTickSize=function(t){return arguments.length?(o=+t,e):o},e.tickPadding=function(t){return arguments.length?(a=+t,e):a},e.tickSubdivide=function(){return arguments.length&&e},e};var Pl="bottom",Fl={top:1,right:1,bottom:1,left:1};na.svg.brush=function(){function e(t){t.each(function(){var t=na.select(this).style("pointer-events","all").style("-webkit-tap-highlight-color","rgba(0,0,0,0)").on("mousedown.brush",o).on("touchstart.brush",o),a=t.selectAll(".background").data([0]);a.enter().append("rect").attr("class","background").style("visibility","hidden").style("cursor","crosshair"),t.selectAll(".extent").data([0]).enter().append("rect").attr("class","extent").style("cursor","move");var s=t.selectAll(".resize").data(m,y);s.exit().remove(),s.enter().append("g").attr("class",function(e){return"resize "+e}).style("cursor",function(e){return jl[e]}).append("rect").attr("x",function(e){return/[ew]$/.test(e)?-3:null}).attr("y",function(e){return/^[ns]/.test(e)?-3:null}).attr("width",6).attr("height",6).style("visibility","hidden"),s.style("display",e.empty()?"none":null);var l,f=na.transition(t),d=na.transition(a);u&&(l=ji(u),d.attr("x",l[0]).attr("width",l[1]-l[0]),r(f)),c&&(l=ji(c),d.attr("y",l[0]).attr("height",l[1]-l[0]),i(f)),n(f)})}function n(e){e.selectAll(".resize").attr("transform",function(e){return"translate("+f[+/e$/.test(e)]+","+d[+/^s/.test(e)]+")"})}function r(e){e.select(".extent").attr("x",f[0]),e.selectAll(".extent,.n>rect,.s>rect").attr("width",f[1]-f[0])}function i(e){e.select(".extent").attr("y",d[0]),e.selectAll(".extent,.e>rect,.w>rect").attr("height",d[1]-d[0])}function o(){function o(){32==na.event.keyCode&&(T||(b=null,A[0]-=f[1],A[1]-=d[1],T=2),k())}function m(){32==na.event.keyCode&&2==T&&(A[0]+=f[1],A[1]+=d[1],T=0,k())}function g(){var e=na.mouse(w),t=!1;$&&(e[0]+=$[0],e[1]+=$[1]),T||(na.event.altKey?(b||(b=[(f[0]+f[1])/2,(d[0]+d[1])/2]),A[0]=f[+(e[0]c?(i=r,r=c):i=c),m[0]!=r||m[1]!=i?(n?s=null:a=null,m[0]=r,m[1]=i,!0):void 0}function y(){g(),E.style("pointer-events","all").selectAll(".resize").style("display",e.empty()?"none":null),na.select("body").style("cursor",null),O.on("mousemove.brush",null).on("mouseup.brush",null).on("touchmove.brush",null).on("touchend.brush",null).on("keydown.brush",null).on("keyup.brush",null),D(),C({type:"brushend"})}var b,$,w=this,x=na.select(na.event.target),C=l.of(w,arguments),E=na.select(w),S=x.datum(),_=!/^(n|s)$/.test(S)&&u,M=!/^(e|w)$/.test(S)&&c,T=x.classed("extent"),D=K(w),A=na.mouse(w),O=na.select(t(w)).on("keydown.brush",o).on("keyup.brush",m);if(na.event.changedTouches?O.on("touchmove.brush",g).on("touchend.brush",y):O.on("mousemove.brush",g).on("mouseup.brush",y),E.interrupt().selectAll("*").interrupt(),T)A[0]=f[0]-A[0],A[1]=d[0]-A[1];else if(S){var N=+/w$/.test(S),R=+/^n/.test(S);$=[f[1-N]-A[0],d[1-R]-A[1]],A[0]=f[N],A[1]=d[R]}else na.event.altKey&&(b=A.slice());E.style("pointer-events","none").selectAll(".resize").style("display",null),na.select("body").style("cursor",x.style("cursor")),C({type:"brushstart"}),g()}var a,s,l=S(e,"brushstart","brush","brushend"),u=null,c=null,f=[0,0],d=[0,0],p=!0,h=!0,m=Ll[0];return e.event=function(e){e.each(function(){var e=l.of(this,arguments),t={x:f,y:d,i:a,j:s},n=this.__chart__||t;this.__chart__=t,Al?na.select(this).transition().each("start.brush",function(){a=n.i,s=n.j,f=n.x,d=n.y,e({type:"brushstart"})}).tween("brush:brush",function(){var n=br(f,t.x),r=br(d,t.y);return a=s=null,function(i){f=t.x=n(i),d=t.y=r(i),e({type:"brush",mode:"resize"})}}).each("end.brush",function(){a=t.i,s=t.j,e({type:"brush",mode:"resize"}),e({type:"brushend"})}):(e({type:"brushstart"}),e({type:"brush",mode:"resize"}),e({type:"brushend"}))})},e.x=function(t){return arguments.length?(u=t,m=Ll[!u<<1|!c],e):u},e.y=function(t){return arguments.length?(c=t,m=Ll[!u<<1|!c],e):c},e.clamp=function(t){return arguments.length?(u&&c?(p=!!t[0],h=!!t[1]):u?p=!!t:c&&(h=!!t),e):u&&c?[p,h]:u?p:c?h:null},e.extent=function(t){var n,r,i,o,l;return arguments.length?(u&&(n=t[0],r=t[1],c&&(n=n[0],r=r[0]),a=[n,r],u.invert&&(n=u(n),r=u(r)),n>r&&(l=n,n=r,r=l),(n!=f[0]||r!=f[1])&&(f=[n,r])),c&&(i=t[0],o=t[1],u&&(i=i[1],o=o[1]),s=[i,o],c.invert&&(i=c(i),o=c(o)),i>o&&(l=i,i=o,o=l),(i!=d[0]||o!=d[1])&&(d=[i,o])),e):(u&&(a?(n=a[0],r=a[1]):(n=f[0],r=f[1],u.invert&&(n=u.invert(n),r=u.invert(r)),n>r&&(l=n,n=r,r=l))),c&&(s?(i=s[0],o=s[1]):(i=d[0],o=d[1],c.invert&&(i=c.invert(i),o=c.invert(o)),i>o&&(l=i,i=o,o=l))),u&&c?[[n,i],[r,o]]:u?[n,r]:c&&[i,o])},e.clear=function(){return e.empty()||(f=[0,0],d=[0,0],a=s=null),e},e.empty=function(){return!!u&&f[0]==f[1]||!!c&&d[0]==d[1]},na.rebind(e,l,"on")};var jl={n:"ns-resize",e:"ew-resize",s:"ns-resize",w:"ew-resize",nw:"nwse-resize",ne:"nesw-resize",se:"nwse-resize",sw:"nesw-resize"},Ll=[["n","e","s","w","nw","ne","se","sw"],["e","w"],["n","s"],[]],Ul=os.format=fs.timeFormat,Hl=Ul.utc,ql=Hl("%Y-%m-%dT%H:%M:%S.%LZ");Ul.iso=Date.prototype.toISOString&&+new Date("2000-01-01T00:00:00.000Z")?Jo:ql,Jo.parse=function(e){var t=new Date(e);return isNaN(t)?null:t},Jo.toString=ql.toString,os.second=Le(function(e){return new as(1e3*Math.floor(e/1e3))},function(e,t){e.setTime(e.getTime()+1e3*Math.floor(t))},function(e){return e.getSeconds()}),os.seconds=os.second.range,os.seconds.utc=os.second.utc.range,os.minute=Le(function(e){return new as(6e4*Math.floor(e/6e4))},function(e,t){e.setTime(e.getTime()+6e4*Math.floor(t))},function(e){return e.getMinutes()}),os.minutes=os.minute.range,os.minutes.utc=os.minute.utc.range,os.hour=Le(function(e){var t=e.getTimezoneOffset()/60;return new as(36e5*(Math.floor(e/36e5-t)+t))},function(e,t){e.setTime(e.getTime()+36e5*Math.floor(t))},function(e){return e.getHours()}),os.hours=os.hour.range,os.hours.utc=os.hour.utc.range,os.month=Le(function(e){return e=os.day(e),e.setDate(1),e},function(e,t){e.setMonth(e.getMonth()+t)},function(e){return e.getMonth()}),os.months=os.month.range,os.months.utc=os.month.utc.range;var Vl=[1e3,5e3,15e3,3e4,6e4,3e5,9e5,18e5,36e5,108e5,216e5,432e5,864e5,1728e5,6048e5,2592e6,7776e6,31536e6],zl=[[os.second,1],[os.second,5],[os.second,15],[os.second,30],[os.minute,1],[os.minute,5],[os.minute,15],[os.minute,30],[os.hour,1],[os.hour,3],[os.hour,6],[os.hour,12],[os.day,1],[os.day,2],[os.week,1],[os.month,1],[os.month,3],[os.year,1]],Bl=Ul.multi([[".%L",function(e){return e.getMilliseconds()}],[":%S",function(e){return e.getSeconds()}],["%I:%M",function(e){return e.getMinutes()}],["%I %p",function(e){return e.getHours()}],["%a %d",function(e){return e.getDay()&&1!=e.getDate()}],["%b %d",function(e){return 1!=e.getDate()}],["%B",function(e){return e.getMonth()}],["%Y",Mt]]),Yl={range:function(e,t,n){return na.range(Math.ceil(e/n)*n,+t,n).map(Xo)},floor:y,ceil:y};zl.year=os.year,os.scale=function(){return Qo(na.scale.linear(),zl,Bl)};var Wl=zl.map(function(e){return[e[0].utc,e[1]]}),Gl=Hl.multi([[".%L",function(e){return e.getUTCMilliseconds()}],[":%S",function(e){return e.getUTCSeconds()}],["%I:%M",function(e){return e.getUTCMinutes()}],["%I %p",function(e){return e.getUTCHours()}],["%a %d",function(e){return e.getUTCDay()&&1!=e.getUTCDate()}],["%b %d",function(e){return 1!=e.getUTCDate()}],["%B",function(e){return e.getUTCMonth()}],["%Y",Mt]]);Wl.year=os.year.utc,os.scale.utc=function(){return Qo(na.scale.linear(),Wl,Gl)},na.text=_e(function(e){return e.responseText}),na.json=function(e,t){return Me(e,"application/json",ea,t)},na.html=function(e,t){return Me(e,"text/html",ta,t)},na.xml=_e(function(e){return e.responseXML}),"function"==typeof define&&define.amd?define("common/d3",na):"object"==typeof module&&module.exports&&(module.exports=na),this.d3=na}(),function(){function e(e,t){if(e!==t){var n=null===e,r=e===$,i=e===e,o=null===t,a=t===$,s=t===t;if(e>t&&!o||!i||n&&!a&&s||r&&s)return 1;if(e=e&&9<=e&&13>=e||32==e||160==e||5760==e||6158==e||8192<=e&&(8202>=e||8232==e||8233==e||8239==e||8287==e||12288==e||65279==e)}function m(e,t){for(var n=-1,r=e.length,i=-1,o=[];++n=I&&gi&&ci?new Ue(t):null,u=t.length;l&&(a=He,s=!1,t=l);e:for(;++oa(t,l,0)&&i.push(l);return i}function st(e,t){var n=!0;return Ri(e,function(e,r,i){return n=!!t(e,r,i)}),n}function lt(e,t,n,r){var i=r,o=i;return Ri(e,function(e,a,s){a=+t(e,a,s),(n(a,i)||a===r&&a===o)&&(i=a,o=e)}),o}function ut(e,t){var n=[];return Ri(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}function ct(e,t,n,r){var i;return n(e,function(e,n,o){return t(e,n,o)?(i=r?n:e,!1):void 0}),i}function ft(e,t,n,r){r||(r=[]);for(var i=-1,o=e.length;++it&&(t=-t>i?0:i+t),n=n===$||n>i?i:+n||0,0>n&&(n+=i),i=t>n?0:n-t>>>0,t>>>=0,n=Ur(i);++r=u)break e;o=r[o],i*="asc"===o||!0===o?1:-1;break e}i=t.b-n.b}return i})}function Ot(e,t){var n=0;return Ri(e,function(e,r,i){n+=+t(e,r,i)||0}),n}function Nt(e,t){var r=-1,i=xn(),o=e.length,a=i===n,s=a&&o>=I,l=s&&gi&&ci?new Ue(void 0):null,u=[];l?(i=He,a=!1):(s=!1,l=t?[]:u);e:for(;++ri(l,f,0)&&((t||s)&&l.push(f),u.push(c))}return u}function Rt(e,t){for(var n=-1,r=t.length,i=Ur(r);++n>>1,a=e[o];(n?a<=t:ai?$:o,i=1);++r=I)return t.plant(r).value();for(var i=0,e=n?o[i].apply(this,e):r;++iarguments.length;return"function"==typeof r&&o===$&&Mo(n)?e(n,r,i,a):_t(n,$n(r,o,4),i,a,t)}}function fn(e,t,n,r,i,o,a,s,l,u){function c(){for(var b=arguments.length,w=b,k=Ur(b);w--;)k[w]=arguments[w];if(r&&(k=Ht(k,r,i)),o&&(k=qt(k,o,a)),h||v){var w=c.placeholder,E=m(k,w),b=b-E.length;if(bt?0:t)):[]}function zn(e,t,n){var r=e?e.length:0;return r?((n?An(e,t,n):null==t)&&(t=1),t=r-(+t||0),Mt(e,0,0>t?0:t)):[]}function Bn(e){return e?e[0]:$}function Yn(e,t,r){var i=e?e.length:0;if(!i)return-1;if("number"==typeof r)r=0>r?wi(i+r,0):r;else if(r)return r=Ft(e,t),rn?wi(i+n,0):n||0,"string"==typeof e||!Mo(e)&&wr(e)?n<=i&&-1t?0:+t||0,r);++n=e&&(t=$),n}}function lr(e,t,n){function r(t,n){n&&ai(n),l=d=p=$,t&&(h=ho(),u=e.apply(f,s),d||l||(s=f=$))}function i(){var e=t-(ho()-c);0>=e||e>t?r(p,l):d=fi(i,e)}function o(){r(g,d)}function a(){if(s=arguments,c=ho(),f=this,p=g&&(d||!v),!1===m)var n=v&&!d;else{l||v||(h=c);var r=m-(c-h),a=0>=r||r>m;a?(l&&(l=ai(l)),h=c,u=e.apply(f,s)):l||(l=fi(o,r))}return a&&d?d=ai(d):d||t===m||(d=fi(i,t)),n&&(a=!0,u=e.apply(f,s)),!a||d||l||(s=f=$),u}var s,l,u,c,f,d,p,h=0,m=!1,g=!0;if("function"!=typeof e)throw new Kr(j);if(t=0>t?0:+t||0,!0===n)var v=!0,g=!1;else gr(n)&&(v=!!n.leading,m="maxWait"in n&&wi(+n.maxWait||0,t),g="trailing"in n?!!n.trailing:g);return a.cancel=function(){d&&ai(d),l&&ai(l),h=0,l=d=p=$},a}function ur(e,t){function n(){var r=arguments,i=t?t.apply(this,r):r[0],o=n.cache;return o.has(i)?o.get(i):(r=e.apply(this,r),n.cache=o.set(i,r),r)}if("function"!=typeof e||t&&"function"!=typeof t)throw new Kr(j);return n.cache=new ur.Cache,n}function cr(e,t){if("function"!=typeof e)throw new Kr(j);return t=wi(t===$?e.length-1:+t||0,0),function(){for(var n=arguments,r=-1,i=wi(n.length-t,0),o=Ur(i);++rt}function dr(e){return p(e)&&Tn(e)&&ei.call(e,"callee")&&!ui.call(e,"callee")}function pr(e,t,n,r){return r=(n="function"==typeof n?Lt(n,r,3):$)?n(e,t):$,r===$?vt(e,t,n):!!r}function hr(e){return p(e)&&"string"==typeof e.message&&ni.call(e)==z}function mr(e){return gr(e)&&ni.call(e)==B}function gr(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function vr(e){return null!=e&&(mr(e)?ii.test(Xr.call(e)):p(e)&&Se.test(e))}function yr(e){return"number"==typeof e||p(e)&&ni.call(e)==Y}function br(e){var t;if(!p(e)||ni.call(e)!=W||dr(e)||!(ei.call(e,"constructor")||"function"!=typeof(t=e.constructor)||t instanceof t))return!1;var n;return dt(e,function(e,t){n=t}),n===$||ei.call(e,n)}function $r(e){return gr(e)&&ni.call(e)==G}function wr(e){return"string"==typeof e||p(e)&&ni.call(e)==K}function xr(e){return p(e)&&Rn(e.length)&&!!Ne[ni.call(e)]}function Cr(e,t){return e(t=+t)||!e||!bi(t))return n;do{t%2&&(n+=e),t=vi(t/2),e+=e}while(t);return n}function Or(e,t,n){var r=e;return(e=i(e))?(n?An(r,t,n):null==t)?e.slice(g(e),v(e)+1):(t+="",e.slice(o(e,t),a(e,t)+1)):e}function Nr(e,t,n){return n&&An(e,t,n)&&(t=$),e=i(e),e.match(t||Ae)||[]}function Rr(e,t,n){return n&&An(e,t,n)&&(t=$),p(e)?Pr(e):rt(e,t)}function Ir(e){return e}function Pr(e){return $t(it(e,!0))}function Fr(e,t,n){if(null==n){var r=gr(t),i=r?Lo(t):$;((i=i&&i.length?mt(t,i):$)?i.length:r)||(i=!1,n=t,t=e,e=this)}i||(i=mt(t,Lo(t)));var o=!0,r=-1,a=mr(e),s=i.length;!1===n?o=!1:gr(n)&&"chain"in n&&(o=n.chain);for(;++r=N)return n}else e=0;return ji(n,r)}}(),qi=cr(function(e,t){return p(e)&&Tn(e)?at(e,ft(t,!1,!0)):[]}),Vi=en(),zi=en(!0),Bi=cr(function(e){for(var t=e.length,r=t,i=Ur(c),o=xn(),a=o===n,s=[];r--;){var l=e[r]=Tn(l=e[r])?l:[];i[r]=a&&120<=l.length&&gi&&ci?new Ue(r&&l):null}var a=e[0],u=-1,c=a?a.length:0,f=i[0];e:for(;++u(f?He(f,l):o(s,l,0))){for(r=t;--r;){var d=i[r];if(0>(d?He(d,l):o(e[r],l,0)))continue e}f&&f.push(l),s.push(l)}return s}),Yi=cr(function(t,n){n=ft(n);var r=tt(t,n);return Et(t,n.sort(e)),r}),Wi=mn(),Gi=mn(!0),Ki=cr(function(e){return Nt(ft(e,!1,!0))}),Zi=cr(function(e,t){return Tn(e)?at(e,t):[]}),Ji=cr(Zn),Qi=cr(function(e){var t=e.length,n=2--e?t.apply(this,arguments):void 0}},Ie.ary=function(e,t,n){return n&&An(e,t,n)&&(t=$),t=e&&null==t?e.length:wi(+t||0,0),gn(e,T,$,$,$,$,t)},Ie.assign=Do,Ie.at=eo,Ie.before=sr,Ie.bind=mo,Ie.bindAll=go,Ie.bindKey=vo,Ie.callback=Rr,Ie.chain=Xn,Ie.chunk=function(e,t,n){t=(n?An(e,t,n):null==t)?1:wi(vi(t)||1,1),n=0;for(var r=e?e.length:0,i=-1,o=Ur(mi(r/t));nn&&(n=-n>i?0:i+n),r=r===$||r>i?i:+r||0,0>r&&(r+=i),i=n>r?0:r>>>0,n>>>=0;nt?0:t)):[]},Ie.takeRight=function(e,t,n){var r=e?e.length:0;return r?((n?An(e,t,n):null==t)&&(t=1),t=r-(+t||0),Mt(e,0>t?0:t)):[]},Ie.takeRightWhile=function(e,t,n){return e&&e.length?It(e,$n(t,n,3),!1,!0):[]},Ie.takeWhile=function(e,t,n){return e&&e.length?It(e,$n(t,n,3)):[]},Ie.tap=function(e,t,n){return t.call(n,e),e},Ie.throttle=function(e,t,n){var r=!0,i=!0;if("function"!=typeof e)throw new Kr(j);return!1===n?r=!1:gr(n)&&(r="leading"in n?!!n.leading:r,i="trailing"in n?!!n.trailing:i),lr(e,t,{leading:r,maxWait:+t,trailing:i})},Ie.thru=er,Ie.times=function(e,t,n){if(1>(e=vi(e))||!bi(e))return[];var r=-1,i=Ur(xi(e,4294967295));for(t=Lt(t,n,1);++rr?i[r]=t(r):t(r);return i},Ie.toArray=kr,Ie.toPlainObject=Er,Ie.transform=function(e,t,n,r){var i=Mo(e)||xr(e);return t=$n(t,r,4),null==n&&(i||gr(e)?(r=e.constructor,n=i?Mo(e)?new r:[]:Ni(mr(r)?r.prototype:$)):n={}),(i?Ve:pt)(e,function(e,r,i){return t(n,e,r,i)}),n},Ie.union=Ki,Ie.uniq=Kn,Ie.unzip=Zn,Ie.unzipWith=Jn,Ie.values=Tr,Ie.valuesIn=function(e){return Rt(e,_r(e))},Ie.where=function(e,t){return nr(e,$t(t))},Ie.without=Zi,Ie.wrap=function(e,t){return t=null==t?Ir:t,gn(t,_,$,[e],[])},Ie.xor=function(){for(var e=-1,t=arguments.length;++en?0:+n||0,r),0<=(n-=t.length)&&e.indexOf(t,n)==n},Ie.escape=function(e){return(e=i(e))&&de.test(e)?e.replace(ce,u):e},Ie.escapeRegExp=function(e){return(e=i(e))&&$e.test(e)?e.replace(be,c):e||"(?:)"},Ie.every=tr,Ie.find=no,Ie.findIndex=Vi,Ie.findKey=No,Ie.findLast=ro,Ie.findLastIndex=zi,Ie.findLastKey=Ro,Ie.findWhere=function(e,t){return no(e,$t(t))},Ie.first=Bn,Ie.floor=ea,Ie.get=function(e,t,n){return e=null==e?$:gt(e,Hn(t),t+""),e===$?n:e},Ie.gt=fr,Ie.gte=function(e,t){return e>=t},Ie.has=function(e,t){if(null==e)return!1;var n=ei.call(e,t);if(!n&&!On(t)){if(t=Hn(t),null==(e=1==t.length?e:gt(e,Mt(t,0,-1))))return!1;t=Wn(t),n=ei.call(e,t)}return n||Rn(e.length)&&Dn(t,e.length)&&(Mo(e)||dr(e))},Ie.identity=Ir,Ie.includes=rr,Ie.indexOf=Yn,Ie.inRange=function(e,t,n){return t=+t||0,n===$?(n=t,t=0):n=+n||0,e>=xi(t,n)&&en?wi(r+n,0):xi(n||0,r-1))+1;else if(n)return i=Ft(e,t,!0)-1,e=e[i],(t===t?t===e:e!==e)?i:-1;if(t!==t)return d(e,i,!0);for(;i--;)if(e[i]===t)return i;return-1},Ie.lt=Cr,Ie.lte=function(e,t){return e<=t},Ie.max=ta,Ie.min=na,Ie.noConflict=function(){return Ye._=ri,this},Ie.noop=jr,Ie.now=ho,Ie.pad=function(e,t,n){e=i(e),t=+t;var r=e.length;return rn?0:+n||0,e.length), e.lastIndexOf(t,n)==n},Ie.sum=function(e,t,n){if(n&&An(e,t,n)&&(t=$),t=$n(t,n,3),1==t.length){e=Mo(e)?e:Ln(e),n=e.length;for(var r=0;n--;)r+=+t(e[n])||0;e=r}else e=Ot(e,t);return e},Ie.template=function(e,t,n){var r=Ie.templateSettings;n&&An(e,t,n)&&(t=n=$),e=i(e),t=Xe(et({},n||t),r,Qe),n=Xe(et({},t.imports),r.imports,Qe);var o,a,s=Lo(n),l=Rt(n,s),u=0;n=t.interpolate||Te;var c="__p+='";n=Wr((t.escape||Te).source+"|"+n.source+"|"+(n===me?Ce:Te).source+"|"+(t.evaluate||Te).source+"|$","g");var d="sourceURL"in t?"//# sourceURL="+t.sourceURL+"\n":"";if(e.replace(n,function(t,n,r,i,s,l){return r||(r=i),c+=e.slice(u,l).replace(De,f),n&&(o=!0,c+="'+__e("+n+")+'"),s&&(a=!0,c+="';"+s+";\n__p+='"),r&&(c+="'+((__t=("+r+"))==null?'':__t)+'"),u=l+t.length,t}),c+="';",(t=t.variable)||(c="with(obj){"+c+"}"),c=(a?c.replace(ae,""):c).replace(se,"$1").replace(le,"$1;"),c="function("+(t||"obj")+"){"+(t?"":"obj||(obj={});")+"var __t,__p=''"+(o?",__e=_.escape":"")+(a?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+c+"return __p}",t=Zo(function(){return Vr(s,d+"return "+c).apply($,l)}),t.source=c,hr(t))throw t;return t},Ie.trim=Or,Ie.trimLeft=function(e,t,n){var r=e;return(e=i(e))?e.slice((n?An(r,t,n):null==t)?g(e):o(e,t+"")):e},Ie.trimRight=function(e,t,n){var r=e;return(e=i(e))?(n?An(r,t,n):null==t)?e.slice(0,v(e)+1):e.slice(0,a(e,t+"")+1):e},Ie.trunc=function(e,t,n){n&&An(e,t,n)&&(t=$);var r=A;if(n=O,null!=t)if(gr(t)){var o="separator"in t?t.separator:o,r="length"in t?+t.length||0:r;n="omission"in t?i(t.omission):n}else r=+t||0;if(e=i(e),r>=e.length)return e;if(1>(r-=n.length))return n;if(t=e.slice(0,r),null==o)return t+n;if($r(o)){if(e.slice(r).search(o)){var a,s=e.slice(0,r);for(o.global||(o=Wr(o.source,(ke.exec(o)||"")+"g")),o.lastIndex=0;e=o.exec(s);)a=e.index;t=t.slice(0,null==a?r:a)}}else e.indexOf(o,r)!=r&&-1<(o=t.lastIndexOf(o))&&(t=t.slice(0,o));return t+n},Ie.unescape=function(e){return(e=i(e))&&fe.test(e)?e.replace(ue,y):e},Ie.uniqueId=function(e){var t=++ti;return i(e)+t},Ie.words=Nr,Ie.all=tr,Ie.any=ar,Ie.contains=rr,Ie.eq=pr,Ie.detect=no,Ie.foldl=co,Ie.foldr=fo,Ie.head=Bn,Ie.include=rr,Ie.inject=co,Fr(Ie,function(){var e={};return pt(Ie,function(t,n){Ie.prototype[n]||(e[n]=t)}),e}(),!1),Ie.sample=or,Ie.prototype.sample=function(e){return this.__chain__||null!=e?this.thru(function(t){return or(t,e)}):or(this.value())},Ie.VERSION=w,Ve("bind bindKey curry curryRight partial partialRight".split(" "),function(e){Ie[e].placeholder=Ie}),Ve(["drop","take"],function(e,t){je.prototype[e]=function(n){var r=this.__filtered__;if(r&&!t)return new je(this);n=null==n?1:wi(vi(n)||0,0);var i=this.clone();return r?i.__takeCount__=xi(i.__takeCount__,n):i.__views__.push({size:n,type:e+(0>i.__dir__?"Right":"")}),i},je.prototype[e+"Right"]=function(t){return this.reverse()[e](t).reverse()}}),Ve(["filter","map","takeWhile"],function(e,t){var n=t+1,r=n!=F;je.prototype[e]=function(e,t){var i=this.clone();return i.__iteratees__.push({iteratee:$n(e,t,1),type:n}),i.__filtered__=i.__filtered__||r,i}}),Ve(["first","last"],function(e,t){var n="take"+(t?"Right":"");je.prototype[e]=function(){return this[n](1).value()[0]}}),Ve(["initial","rest"],function(e,t){var n="drop"+(t?"":"Right");je.prototype[e]=function(){return this.__filtered__?new je(this):this[n](1)}}),Ve(["pluck","where"],function(e,t){var n=t?"filter":"map",r=t?$t:Lr;je.prototype[e]=function(e){return this[n](r(e))}}),je.prototype.compact=function(){return this.filter(Ir)},je.prototype.reject=function(e,t){return e=$n(e,t,1),this.filter(function(t){return!e(t)})},je.prototype.slice=function(e,t){e=null==e?0:+e||0;var n=this;return n.__filtered__&&(0t)?new je(n):(0>e?n=n.takeRight(-e):e&&(n=n.drop(e)),t!==$&&(t=+t||0,n=0>t?n.dropRight(-t):n.take(t-e)),n)},je.prototype.takeRightWhile=function(e,t){return this.reverse().takeWhile(e,t).reverse()},je.prototype.toArray=function(){return this.take(_i)},pt(je.prototype,function(e,t){var n=/^(?:filter|map|reject)|While$/.test(t),r=/^(?:first|last)$/.test(t),i=Ie[r?"take"+("last"==t?"Right":""):t];i&&(Ie.prototype[t]=function(){function t(e){return r&&a?i(e,1)[0]:i.apply($,Ke([e],o))}var o=r?[1]:arguments,a=this.__chain__,s=this.__wrapped__,l=!!this.__actions__.length,u=s instanceof je,c=o[0],f=u||Mo(s);return f&&n&&"function"==typeof c&&1!=c.length&&(u=f=!1),c={func:er,args:[t],thisArg:$},l=u&&!l,r&&!a?l?(s=s.clone(),s.__actions__.push(c),e.call(s)):i.call($,this.value())[0]:!r&&f?(s=l?s:new je(this),s=e.apply(s,o),s.__actions__.push(c),new Fe(s,a)):this.thru(t)})}),Ve("join pop push replace shift sort splice split unshift".split(" "),function(e){var t=(/^(?:replace|split)$/.test(e)?Qr:Zr)[e],n=/^(?:push|sort|unshift)$/.test(e)?"tap":"thru",r=/^(?:join|pop|replace|shift)$/.test(e);Ie.prototype[e]=function(){var e=arguments;return r&&!this.__chain__?t.apply(this.value(),e):this[n](function(n){return t.apply(n,e)})}}),pt(je.prototype,function(e,t){var n=Ie[t];if(n){var r=n.name+"";(Oi[r]||(Oi[r]=[])).push({name:t,func:n})}}),Oi[fn($,C).name]=[{name:"wrapper",func:$}],je.prototype.clone=function(){var e=new je(this.__wrapped__);return e.__actions__=qe(this.__actions__),e.__dir__=this.__dir__,e.__filtered__=this.__filtered__,e.__iteratees__=qe(this.__iteratees__),e.__takeCount__=this.__takeCount__,e.__views__=qe(this.__views__),e},je.prototype.reverse=function(){if(this.__filtered__){var e=new je(this);e.__dir__=-1,e.__filtered__=!0}else e=this.clone(),e.__dir__*=-1;return e},je.prototype.value=function(){var e,t=this.__wrapped__.value(),n=this.__dir__,r=Mo(t),i=0>n,o=r?t.length:0;e=o;for(var a=this.__views__,s=0,l=-1,u=a.length;++l"'`]/g,fe=RegExp(ue.source),de=RegExp(ce.source),pe=/<%-([\s\S]+?)%>/g,he=/<%([\s\S]+?)%>/g,me=/<%=([\s\S]+?)%>/g,ge=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/,ve=/^\w*$/,ye=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g,be=/^[:!,]|[\\^$.*+?()[\]{}|\/]|(^[0-9a-fA-Fnrtuvx])|([\n\r\u2028\u2029])/g,$e=RegExp(be.source),we=/[\u0300-\u036f\ufe20-\ufe23]/g,xe=/\\(\\)?/g,Ce=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,ke=/\w*$/,Ee=/^0[xX]/,Se=/^\[object .+?Constructor\]$/,_e=/^\d+$/,Me=/[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g,Te=/($^)/,De=/['\n\r\u2028\u2029\\]/g,Ae=RegExp("[A-Z\\xc0-\\xd6\\xd8-\\xde]+(?=[A-Z\\xc0-\\xd6\\xd8-\\xde][a-z\\xdf-\\xf6\\xf8-\\xff]+)|[A-Z\\xc0-\\xd6\\xd8-\\xde]?[a-z\\xdf-\\xf6\\xf8-\\xff]+|[A-Z\\xc0-\\xd6\\xd8-\\xde]+|[0-9]+","g"),Oe="Array ArrayBuffer Date Error Float32Array Float64Array Function Int8Array Int16Array Int32Array Math Number Object RegExp Set String _ clearTimeout isFinite parseFloat parseInt setTimeout TypeError Uint8Array Uint8ClampedArray Uint16Array Uint32Array WeakMap".split(" "),Ne={};Ne[J]=Ne[Q]=Ne[X]=Ne[ee]=Ne[te]=Ne[ne]=Ne[re]=Ne[ie]=Ne[oe]=!0,Ne[U]=Ne[H]=Ne[Z]=Ne[q]=Ne[V]=Ne[z]=Ne[B]=Ne["[object Map]"]=Ne[Y]=Ne[W]=Ne[G]=Ne["[object Set]"]=Ne[K]=Ne["[object WeakMap]"]=!1;var Re={};Re[U]=Re[H]=Re[Z]=Re[q]=Re[V]=Re[J]=Re[Q]=Re[X]=Re[ee]=Re[te]=Re[Y]=Re[W]=Re[G]=Re[K]=Re[ne]=Re[re]=Re[ie]=Re[oe]=!0,Re[z]=Re[B]=Re["[object Map]"]=Re["[object Set]"]=Re["[object WeakMap]"]=!1;var Ie={"À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","Ç":"C","ç":"c","Ð":"D","ð":"d","È":"E","É":"E","Ê":"E","Ë":"E","è":"e","é":"e","ê":"e","ë":"e","Ì":"I","Í":"I","Î":"I","Ï":"I","ì":"i","í":"i","î":"i","ï":"i","Ñ":"N","ñ":"n","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","Ù":"U","Ú":"U","Û":"U","Ü":"U","ù":"u","ú":"u","û":"u","ü":"u","Ý":"Y","ý":"y","ÿ":"y","Æ":"Ae","æ":"ae","Þ":"Th","þ":"th","ß":"ss"},Pe={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},Fe={"&":"&","<":"<",">":">",""":'"',"'":"'","`":"`"},je={function:!0,object:!0},Le={0:"x30",1:"x31",2:"x32",3:"x33",4:"x34",5:"x35",6:"x36",7:"x37",8:"x38",9:"x39",A:"x41",B:"x42",C:"x43",D:"x44",E:"x45",F:"x46",a:"x61",b:"x62",c:"x63",d:"x64",e:"x65",f:"x66",n:"x6e",r:"x72",t:"x74",u:"x75",v:"x76",x:"x78"},Ue={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},He=je[typeof exports]&&exports&&!exports.nodeType&&exports,qe=je[typeof module]&&module&&!module.nodeType&&module,Ve=je[typeof self]&&self&&self.Object&&self,ze=je[typeof window]&&window&&window.Object&&window,Be=qe&&qe.exports===He&&He,Ye=He&&qe&&"object"==typeof global&&global&&global.Object&&global||ze!==(this&&this.window)&&ze||Ve||this,We=b();"function"==typeof define&&"object"==typeof define.amd&&define.amd?(Ye._=We,define("common/lodash",[],function(){return We})):He&&qe?Be?(qe.exports=We)._=We:He._=We:Ye._=We}.call(this),function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define("common/moment",t):e.moment=t()}(this,function(){"use strict";function e(){return Yn.apply(null,arguments)}function t(e){return"[object Array]"===Object.prototype.toString.call(e)}function n(e){return e instanceof Date||"[object Date]"===Object.prototype.toString.call(e)}function r(e,t){var n,r=[];for(n=0;n0)for(n in Gn)r=Gn[n],i=t[r],f(i)||(e[r]=i);return e}function p(t){d(this,t),this._d=new Date(null!=t._d?t._d.getTime():NaN),!1===Kn&&(Kn=!0,e.updateOffset(this),Kn=!1)}function h(e){return e instanceof p||null!=e&&null!=e._isAMomentObject}function m(e){return 0>e?Math.ceil(e):Math.floor(e)}function g(e){var t=+e,n=0;return 0!==t&&isFinite(t)&&(n=m(t)),n}function v(e,t,n){var r,i=Math.min(e.length,t.length),o=Math.abs(e.length-t.length),a=0;for(r=0;i>r;r++)(n&&e[r]!==t[r]||!n&&g(e[r])!==g(t[r]))&&a++;return a+o}function y(){}function b(e){return e?e.toLowerCase().replace("_","-"):e}function $(e){for(var t,n,r,i,o=0;o0;){if(r=w(i.slice(0,t).join("-")))return r;if(n&&n.length>=t&&v(i,n,!0)>=t-1)break;t--}o++}return null}function w(e){var t=null;if(!Zn[e]&&"undefined"!=typeof module&&module&&module.exports)try{t=Wn._abbr,require("./locale/"+e),x(t)}catch(e){}return Zn[e]}function x(e,t){var n;return e&&(n=f(t)?k(e):C(e,t))&&(Wn=n),Wn._abbr}function C(e,t){return null!==t?(t.abbr=e,Zn[e]=Zn[e]||new y,Zn[e].set(t),x(e),Zn[e]):(delete Zn[e],null)}function k(e){var n;if(e&&e._locale&&e._locale._abbr&&(e=e._locale._abbr),!e)return Wn;if(!t(e)){if(n=w(e))return n;e=[e]}return $(e)}function E(e,t){var n=e.toLowerCase();Jn[n]=Jn[n+"s"]=Jn[t]=e}function S(e){return"string"==typeof e?Jn[e]||Jn[e.toLowerCase()]:void 0}function _(e){var t,n,r={};for(n in e)i(e,n)&&(t=S(n))&&(r[t]=e[n]);return r}function M(e){return e instanceof Function||"[object Function]"===Object.prototype.toString.call(e)}function T(t,n){return function(r){return null!=r?(A(this,t,r),e.updateOffset(this,n),this):D(this,t)}}function D(e,t){return e.isValid()?e._d["get"+(e._isUTC?"UTC":"")+t]():NaN}function A(e,t,n){e.isValid()&&e._d["set"+(e._isUTC?"UTC":"")+t](n)}function O(e,t){var n;if("object"==typeof e)for(n in e)this.set(n,e[n]);else if(e=S(e),M(this[e]))return this[e](t);return this}function N(e,t,n){var r=""+Math.abs(e),i=t-r.length;return(e>=0?n?"+":"":"-")+Math.pow(10,Math.max(0,i)).toString().substr(1)+r}function R(e,t,n,r){var i=r;"string"==typeof r&&(i=function(){return this[r]()}),e&&(tr[e]=i),t&&(tr[t[0]]=function(){return N(i.apply(this,arguments),t[1],t[2])}),n&&(tr[n]=function(){return this.localeData().ordinal(i.apply(this,arguments),e)})}function I(e){return e.match(/\[[\s\S]/)?e.replace(/^\[|\]$/g,""):e.replace(/\\/g,"")}function P(e){var t,n,r=e.match(Qn);for(t=0,n=r.length;n>t;t++)tr[r[t]]?r[t]=tr[r[t]]:r[t]=I(r[t]);return function(i){var o="";for(t=0;n>t;t++)o+=r[t]instanceof Function?r[t].call(i,e):r[t];return o}}function F(e,t){return e.isValid()?(t=j(t,e.localeData()),er[t]=er[t]||P(t),er[t](e)):e.localeData().invalidDate()}function j(e,t){function n(e){return t.longDateFormat(e)||e}var r=5;for(Xn.lastIndex=0;r>=0&&Xn.test(e);)e=e.replace(Xn,n),Xn.lastIndex=0,r-=1;return e}function L(e,t,n){br[e]=M(t)?t:function(e,r){return e&&n?n:t}}function U(e,t){return i(br,e)?br[e](t._strict,t._locale):new RegExp(H(e))}function H(e){return q(e.replace("\\","").replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g,function(e,t,n,r,i){return t||n||r||i}))}function q(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}function V(e,t){var n,r=t;for("string"==typeof e&&(e=[e]),"number"==typeof t&&(r=function(e,n){n[t]=g(e)}),n=0;nr;r++){if(i=a([2e3,r]),n&&!this._longMonthsParse[r]&&(this._longMonthsParse[r]=new RegExp("^"+this.months(i,"").replace(".","")+"$","i"),this._shortMonthsParse[r]=new RegExp("^"+this.monthsShort(i,"").replace(".","")+"$","i")),n||this._monthsParse[r]||(o="^"+this.months(i,"")+"|^"+this.monthsShort(i,""),this._monthsParse[r]=new RegExp(o.replace(".",""),"i")),n&&"MMMM"===t&&this._longMonthsParse[r].test(e))return r;if(n&&"MMM"===t&&this._shortMonthsParse[r].test(e))return r;if(!n&&this._monthsParse[r].test(e))return r}}function Z(e,t){var n;return e.isValid()?"string"==typeof t&&"number"!=typeof(t=e.localeData().monthsParse(t))?e:(n=Math.min(e.date(),Y(e.year(),t)),e._d["set"+(e._isUTC?"UTC":"")+"Month"](t,n),e):e}function J(t){return null!=t?(Z(this,t),e.updateOffset(this,!0),this):D(this,"Month")}function Q(){return Y(this.year(),this.month())}function X(e){return this._monthsParseExact?(i(this,"_monthsRegex")||te.call(this),e?this._monthsShortStrictRegex:this._monthsShortRegex):this._monthsShortStrictRegex&&e?this._monthsShortStrictRegex:this._monthsShortRegex}function ee(e){return this._monthsParseExact?(i(this,"_monthsRegex")||te.call(this),e?this._monthsStrictRegex:this._monthsRegex):this._monthsStrictRegex&&e?this._monthsStrictRegex:this._monthsRegex}function te(){function e(e,t){return t.length-e.length}var t,n,r=[],i=[],o=[];for(t=0;12>t;t++)n=a([2e3,t]),r.push(this.monthsShort(n,"")),i.push(this.months(n,"")),o.push(this.months(n,"")),o.push(this.monthsShort(n,""));for(r.sort(e),i.sort(e),o.sort(e),t=0;12>t;t++)r[t]=q(r[t]),i[t]=q(i[t]),o[t]=q(o[t]);this._monthsRegex=new RegExp("^("+o.join("|")+")","i"),this._monthsShortRegex=this._monthsRegex,this._monthsStrictRegex=new RegExp("^("+i.join("|")+")$","i"),this._monthsShortStrictRegex=new RegExp("^("+r.join("|")+")$","i")}function ne(e){var t,n=e._a;return n&&-2===l(e).overflow&&(t=n[xr]<0||n[xr]>11?xr:n[Cr]<1||n[Cr]>Y(n[wr],n[xr])?Cr:n[kr]<0||n[kr]>24||24===n[kr]&&(0!==n[Er]||0!==n[Sr]||0!==n[_r])?kr:n[Er]<0||n[Er]>59?Er:n[Sr]<0||n[Sr]>59?Sr:n[_r]<0||n[_r]>999?_r:-1,l(e)._overflowDayOfYear&&(wr>t||t>Cr)&&(t=Cr),l(e)._overflowWeeks&&-1===t&&(t=Mr),l(e)._overflowWeekday&&-1===t&&(t=Tr),l(e).overflow=t),e}function re(t){!1===e.suppressDeprecationWarnings&&"undefined"!=typeof console&&console.warn&&console.warn("Deprecation warning: "+t)}function ie(e,t){var n=!0;return o(function(){return n&&(re(e+"\nArguments: "+Array.prototype.slice.call(arguments).join(", ")+"\n"+(new Error).stack),n=!1),t.apply(this,arguments)},t)}function oe(e,t){Ir[e]||(re(t),Ir[e]=!0)}function ae(e){var t,n,r,i,o,a,s=e._i,u=Pr.exec(s)||Fr.exec(s);if(u){for(l(e).iso=!0,t=0,n=Lr.length;n>t;t++)if(Lr[t][1].exec(u[1])){i=Lr[t][0],r=!1!==Lr[t][2];break}if(null==i)return void(e._isValid=!1);if(u[3]){for(t=0,n=Ur.length;n>t;t++)if(Ur[t][1].exec(u[3])){o=(u[2]||" ")+Ur[t][0];break}if(null==o)return void(e._isValid=!1)}if(!r&&null!=o)return void(e._isValid=!1);if(u[4]){if(!jr.exec(u[4]))return void(e._isValid=!1);a="Z"}e._f=i+(o||"")+(a||""),we(e)}else e._isValid=!1}function se(t){var n=Hr.exec(t._i);return null!==n?void(t._d=new Date(+n[1])):(ae(t),void(!1===t._isValid&&(delete t._isValid,e.createFromInputFallback(t))))}function le(e,t,n,r,i,o,a){var s=new Date(e,t,n,r,i,o,a);return 100>e&&e>=0&&isFinite(s.getFullYear())&&s.setFullYear(e),s}function ue(e){var t=new Date(Date.UTC.apply(null,arguments));return 100>e&&e>=0&&isFinite(t.getUTCFullYear())&&t.setUTCFullYear(e),t}function ce(e){return fe(e)?366:365}function fe(e){return e%4==0&&e%100!=0||e%400==0}function de(){return fe(this.year())}function pe(e,t,n){var r=7+t-n;return-(7+ue(e,0,r).getUTCDay()-t)%7+r-1}function he(e,t,n,r,i){var o,a,s=(7+n-r)%7,l=pe(e,r,i),u=1+7*(t-1)+s+l;return 0>=u?(o=e-1,a=ce(o)+u):u>ce(e)?(o=e+1,a=u-ce(e)):(o=e,a=u),{year:o,dayOfYear:a}}function me(e,t,n){var r,i,o=pe(e.year(),t,n),a=Math.floor((e.dayOfYear()-o-1)/7)+1;return 1>a?(i=e.year()-1,r=a+ge(i,t,n)):a>ge(e.year(),t,n)?(r=a-ge(e.year(),t,n),i=e.year()+1):(i=e.year(),r=a),{week:r,year:i}}function ge(e,t,n){var r=pe(e,t,n),i=pe(e+1,t,n);return(ce(e)-r+i)/7}function ve(e,t,n){return null!=e?e:null!=t?t:n}function ye(t){var n=new Date(e.now());return t._useUTC?[n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate()]:[n.getFullYear(),n.getMonth(),n.getDate()]}function be(e){var t,n,r,i,o=[];if(!e._d){for(r=ye(e),e._w&&null==e._a[Cr]&&null==e._a[xr]&&$e(e),e._dayOfYear&&(i=ve(e._a[wr],r[wr]),e._dayOfYear>ce(i)&&(l(e)._overflowDayOfYear=!0),n=ue(i,0,e._dayOfYear),e._a[xr]=n.getUTCMonth(),e._a[Cr]=n.getUTCDate()),t=0;3>t&&null==e._a[t];++t)e._a[t]=o[t]=r[t];for(;7>t;t++)e._a[t]=o[t]=null==e._a[t]?2===t?1:0:e._a[t];24===e._a[kr]&&0===e._a[Er]&&0===e._a[Sr]&&0===e._a[_r]&&(e._nextDay=!0,e._a[kr]=0),e._d=(e._useUTC?ue:le).apply(null,o),null!=e._tzm&&e._d.setUTCMinutes(e._d.getUTCMinutes()-e._tzm),e._nextDay&&(e._a[kr]=24)}}function $e(e){var t,n,r,i,o,a,s,u;t=e._w,null!=t.GG||null!=t.W||null!=t.E?(o=1,a=4,n=ve(t.GG,e._a[wr],me(Te(),1,4).year),r=ve(t.W,1),(1>(i=ve(t.E,1))||i>7)&&(u=!0)):(o=e._locale._week.dow,a=e._locale._week.doy,n=ve(t.gg,e._a[wr],me(Te(),o,a).year),r=ve(t.w,1),null!=t.d?(0>(i=t.d)||i>6)&&(u=!0):null!=t.e?(i=t.e+o,(t.e<0||t.e>6)&&(u=!0)):i=o),1>r||r>ge(n,o,a)?l(e)._overflowWeeks=!0:null!=u?l(e)._overflowWeekday=!0:(s=he(n,r,i,o,a),e._a[wr]=s.year,e._dayOfYear=s.dayOfYear)}function we(t){if(t._f===e.ISO_8601)return void ae(t);t._a=[],l(t).empty=!0;var n,r,i,o,a,s=""+t._i,u=s.length,c=0;for(i=j(t._f,t._locale).match(Qn)||[],n=0;n0&&l(t).unusedInput.push(a),s=s.slice(s.indexOf(r)+r.length),c+=r.length),tr[o]?(r?l(t).empty=!1:l(t).unusedTokens.push(o),B(o,r,t)):t._strict&&!r&&l(t).unusedTokens.push(o);l(t).charsLeftOver=u-c,s.length>0&&l(t).unusedInput.push(s),!0===l(t).bigHour&&t._a[kr]<=12&&t._a[kr]>0&&(l(t).bigHour=void 0),t._a[kr]=xe(t._locale,t._a[kr],t._meridiem),be(t),ne(t)}function xe(e,t,n){var r;return null==n?t:null!=e.meridiemHour?e.meridiemHour(t,n):null!=e.isPM?(r=e.isPM(n),r&&12>t&&(t+=12),r||12!==t||(t=0),t):t}function Ce(e){var t,n,r,i,a;if(0===e._f.length)return l(e).invalidFormat=!0,void(e._d=new Date(NaN));for(i=0;ia)&&(r=a,n=t));o(e,n||t)}function ke(e){if(!e._d){var t=_(e._i);e._a=r([t.year,t.month,t.day||t.date,t.hour,t.minute,t.second,t.millisecond],function(e){return e&&parseInt(e,10)}),be(e)}}function Ee(e){var t=new p(ne(Se(e)));return t._nextDay&&(t.add(1,"d"),t._nextDay=void 0),t}function Se(e){var r=e._i,i=e._f;return e._locale=e._locale||k(e._l),null===r||void 0===i&&""===r?c({nullInput:!0}):("string"==typeof r&&(e._i=r=e._locale.preparse(r)),h(r)?new p(ne(r)):(t(i)?Ce(e):i?we(e):n(r)?e._d=r:_e(e),u(e)||(e._d=null),e))}function _e(i){var o=i._i;void 0===o?i._d=new Date(e.now()):n(o)?i._d=new Date(+o):"string"==typeof o?se(i):t(o)?(i._a=r(o.slice(0),function(e){return parseInt(e,10)}),be(i)):"object"==typeof o?ke(i):"number"==typeof o?i._d=new Date(o):e.createFromInputFallback(i)}function Me(e,t,n,r,i){var o={};return"boolean"==typeof n&&(r=n,n=void 0),o._isAMomentObject=!0,o._useUTC=o._isUTC=i,o._l=n,o._i=e,o._f=t,o._strict=r,Ee(o)}function Te(e,t,n,r){return Me(e,t,n,r,!1)}function De(e,n){var r,i;if(1===n.length&&t(n[0])&&(n=n[0]),!n.length)return Te();for(r=n[0],i=1;ie&&(e=-e,n="-"),n+N(~~(e/60),2)+t+N(~~e%60,2)})}function Pe(e,t){var n=(t||"").match(e)||[],r=n[n.length-1]||[],i=(r+"").match(Yr)||["-",0,0],o=60*i[1]+g(i[2]);return"+"===i[0]?o:-o}function Fe(t,r){var i,o;return r._isUTC?(i=r.clone(),o=(h(t)||n(t)?+t:+Te(t))-+i,i._d.setTime(+i._d+o),e.updateOffset(i,!1),i):Te(t).local()}function je(e){return 15*-Math.round(e._d.getTimezoneOffset()/15)}function Le(t,n){var r,i=this._offset||0;return this.isValid()?null!=t?("string"==typeof t?t=Pe(gr,t):Math.abs(t)<16&&(t*=60),!this._isUTC&&n&&(r=je(this)),this._offset=t,this._isUTC=!0,null!=r&&this.add(r,"m"),i!==t&&(!n||this._changeInProgress?tt(this,Ze(t-i,"m"),1,!1):this._changeInProgress||(this._changeInProgress=!0,e.updateOffset(this,!0),this._changeInProgress=null)),this):this._isUTC?i:je(this):null!=t?this:NaN}function Ue(e,t){return null!=e?("string"!=typeof e&&(e=-e),this.utcOffset(e,t),this):-this.utcOffset()}function He(e){return this.utcOffset(0,e)}function qe(e){return this._isUTC&&(this.utcOffset(0,e),this._isUTC=!1,e&&this.subtract(je(this),"m")),this}function Ve(){return this._tzm?this.utcOffset(this._tzm):"string"==typeof this._i&&this.utcOffset(Pe(mr,this._i)),this}function ze(e){return!!this.isValid()&&(e=e?Te(e).utcOffset():0,(this.utcOffset()-e)%60==0)}function Be(){return this.utcOffset()>this.clone().month(0).utcOffset()||this.utcOffset()>this.clone().month(5).utcOffset()}function Ye(){if(!f(this._isDSTShifted))return this._isDSTShifted;var e={};if(d(e,this),e=Se(e),e._a){var t=e._isUTC?a(e._a):Te(e._a);this._isDSTShifted=this.isValid()&&v(e._a,t.toArray())>0}else this._isDSTShifted=!1;return this._isDSTShifted}function We(){return!!this.isValid()&&!this._isUTC}function Ge(){return!!this.isValid()&&this._isUTC}function Ke(){return!!this.isValid()&&(this._isUTC&&0===this._offset)}function Ze(e,t){var n,r,o,a=e,s=null;return Re(e)?a={ms:e._milliseconds,d:e._days,M:e._months}:"number"==typeof e?(a={},t?a[t]=e:a.milliseconds=e):(s=Wr.exec(e))?(n="-"===s[1]?-1:1,a={y:0,d:g(s[Cr])*n,h:g(s[kr])*n,m:g(s[Er])*n,s:g(s[Sr])*n,ms:g(s[_r])*n}):(s=Gr.exec(e))?(n="-"===s[1]?-1:1,a={y:Je(s[2],n),M:Je(s[3],n),d:Je(s[4],n),h:Je(s[5],n),m:Je(s[6],n),s:Je(s[7],n),w:Je(s[8],n)}):null==a?a={}:"object"==typeof a&&("from"in a||"to"in a)&&(o=Xe(Te(a.from),Te(a.to)),a={},a.ms=o.milliseconds,a.M=o.months),r=new Ne(a),Re(e)&&i(e,"_locale")&&(r._locale=e._locale),r}function Je(e,t){var n=e&&parseFloat(e.replace(",","."));return(isNaN(n)?0:n)*t}function Qe(e,t){var n={milliseconds:0,months:0};return n.months=t.month()-e.month()+12*(t.year()-e.year()),e.clone().add(n.months,"M").isAfter(t)&&--n.months,n.milliseconds=+t-+e.clone().add(n.months,"M"),n}function Xe(e,t){var n;return e.isValid()&&t.isValid()?(t=Fe(t,e),e.isBefore(t)?n=Qe(e,t):(n=Qe(t,e),n.milliseconds=-n.milliseconds,n.months=-n.months),n):{milliseconds:0,months:0}}function et(e,t){return function(n,r){var i,o;return null===r||isNaN(+r)||(oe(t,"moment()."+t+"(period, number) is deprecated. Please use moment()."+t+"(number, period)."),o=n,n=r,r=o),n="string"==typeof n?+n:n,i=Ze(n,r),tt(this,i,e),this}}function tt(t,n,r,i){var o=n._milliseconds,a=n._days,s=n._months;t.isValid()&&(i=null==i||i,o&&t._d.setTime(+t._d+o*r),a&&A(t,"Date",D(t,"Date")+a*r),s&&Z(t,D(t,"Month")+s*r),i&&e.updateOffset(t,a||s))}function nt(e,t){var n=e||Te(),r=Fe(n,this).startOf("day"),i=this.diff(r,"days",!0),o=-6>i?"sameElse":-1>i?"lastWeek":0>i?"lastDay":1>i?"sameDay":2>i?"nextDay":7>i?"nextWeek":"sameElse",a=t&&(M(t[o])?t[o]():t[o]);return this.format(a||this.localeData().calendar(o,this,Te(n)))}function rt(){return new p(this)}function it(e,t){var n=h(e)?e:Te(e);return!(!this.isValid()||!n.isValid())&&(t=S(f(t)?"millisecond":t),"millisecond"===t?+this>+n:+n<+this.clone().startOf(t))}function ot(e,t){var n=h(e)?e:Te(e);return!(!this.isValid()||!n.isValid())&&(t=S(f(t)?"millisecond":t),"millisecond"===t?+n>+this:+this.clone().endOf(t)<+n)}function at(e,t,n){return this.isAfter(e,n)&&this.isBefore(t,n)}function st(e,t){var n,r=h(e)?e:Te(e);return!(!this.isValid()||!r.isValid())&&(t=S(t||"millisecond"),"millisecond"===t?+this==+r:(n=+r,+this.clone().startOf(t)<=n&&n<=+this.clone().endOf(t)))}function lt(e,t){return this.isSame(e,t)||this.isAfter(e,t)}function ut(e,t){return this.isSame(e,t)||this.isBefore(e,t)}function ct(e,t,n){var r,i,o,a;return this.isValid()?(r=Fe(e,this),r.isValid()?(i=6e4*(r.utcOffset()-this.utcOffset()),t=S(t),"year"===t||"month"===t||"quarter"===t?(a=ft(this,r),"quarter"===t?a/=3:"year"===t&&(a/=12)):(o=this-r,a="second"===t?o/1e3:"minute"===t?o/6e4:"hour"===t?o/36e5:"day"===t?(o-i)/864e5:"week"===t?(o-i)/6048e5:o),n?a:m(a)):NaN):NaN}function ft(e,t){var n,r,i=12*(t.year()-e.year())+(t.month()-e.month()),o=e.clone().add(i,"months");return 0>t-o?(n=e.clone().add(i-1,"months"),r=(t-o)/(o-n)):(n=e.clone().add(i+1,"months"),r=(t-o)/(n-o)),-(i+r)}function dt(){return this.clone().locale("en").format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ")}function pt(){var e=this.clone().utc();return 0o&&(t=o),Lt.call(this,e,t,n,r,i))}function Lt(e,t,n,r,i){var o=he(e,t,n,r,i),a=ue(o.year,0,o.dayOfYear);return this.year(a.getUTCFullYear()),this.month(a.getUTCMonth()), -this.date(a.getUTCDate()),this}function Ut(e){return null==e?Math.ceil((this.month()+1)/3):this.month(3*(e-1)+this.month()%3)}function Ht(e){return me(e,this._week.dow,this._week.doy).week}function qt(){return this._week.dow}function Vt(){return this._week.doy}function zt(e){var t=this.localeData().week(this);return null==e?t:this.add(7*(e-t),"d")}function Bt(e){var t=me(this,1,4).week;return null==e?t:this.add(7*(e-t),"d")}function Yt(e,t){return"string"!=typeof e?e:isNaN(e)?(e=t.weekdaysParse(e),"number"==typeof e?e:null):parseInt(e,10)}function Wt(e,n){return t(this._weekdays)?this._weekdays[e.day()]:this._weekdays[this._weekdays.isFormat.test(n)?"format":"standalone"][e.day()]}function Gt(e){return this._weekdaysShort[e.day()]}function Kt(e){return this._weekdaysMin[e.day()]}function Zt(e,t,n){var r,i,o;for(this._weekdaysParse||(this._weekdaysParse=[],this._minWeekdaysParse=[],this._shortWeekdaysParse=[],this._fullWeekdaysParse=[]),r=0;7>r;r++){if(i=Te([2e3,1]).day(r),n&&!this._fullWeekdaysParse[r]&&(this._fullWeekdaysParse[r]=new RegExp("^"+this.weekdays(i,"").replace(".",".?")+"$","i"),this._shortWeekdaysParse[r]=new RegExp("^"+this.weekdaysShort(i,"").replace(".",".?")+"$","i"),this._minWeekdaysParse[r]=new RegExp("^"+this.weekdaysMin(i,"").replace(".",".?")+"$","i")),this._weekdaysParse[r]||(o="^"+this.weekdays(i,"")+"|^"+this.weekdaysShort(i,"")+"|^"+this.weekdaysMin(i,""),this._weekdaysParse[r]=new RegExp(o.replace(".",""),"i")),n&&"dddd"===t&&this._fullWeekdaysParse[r].test(e))return r;if(n&&"ddd"===t&&this._shortWeekdaysParse[r].test(e))return r;if(n&&"dd"===t&&this._minWeekdaysParse[r].test(e))return r;if(!n&&this._weekdaysParse[r].test(e))return r}}function Jt(e){if(!this.isValid())return null!=e?this:NaN;var t=this._isUTC?this._d.getUTCDay():this._d.getDay();return null!=e?(e=Yt(e,this.localeData()),this.add(e-t,"d")):t}function Qt(e){if(!this.isValid())return null!=e?this:NaN;var t=(this.day()+7-this.localeData()._week.dow)%7;return null==e?t:this.add(e-t,"d")}function Xt(e){return this.isValid()?null==e?this.day()||7:this.day(this.day()%7?e:e-7):null!=e?this:NaN}function en(e){var t=Math.round((this.clone().startOf("day")-this.clone().startOf("year"))/864e5)+1;return null==e?t:this.add(e-t,"d")}function tn(){return this.hours()%12||12}function nn(e,t){R(e,0,0,function(){return this.localeData().meridiem(this.hours(),this.minutes(),t)})}function rn(e,t){return t._meridiemParse}function on(e){return"p"===(e+"").toLowerCase().charAt(0)}function an(e,t,n){return e>11?n?"pm":"PM":n?"am":"AM"}function sn(e,t){t[_r]=g(1e3*("0."+e))}function ln(){return this._isUTC?"UTC":""}function un(){return this._isUTC?"Coordinated Universal Time":""}function cn(e){return Te(1e3*e)}function fn(){return Te.apply(null,arguments).parseZone()}function dn(e,t,n){var r=this._calendar[e];return M(r)?r.call(t,n):r}function pn(e){var t=this._longDateFormat[e],n=this._longDateFormat[e.toUpperCase()];return t||!n?t:(this._longDateFormat[e]=n.replace(/MMMM|MM|DD|dddd/g,function(e){return e.slice(1)}),this._longDateFormat[e])}function hn(){return this._invalidDate}function mn(e){return this._ordinal.replace("%d",e)}function gn(e){return e}function vn(e,t,n,r){var i=this._relativeTime[n];return M(i)?i(e,t,n,r):i.replace(/%d/i,e)}function yn(e,t){var n=this._relativeTime[e>0?"future":"past"];return M(n)?n(t):n.replace(/%s/i,t)}function bn(e){var t,n;for(n in e)t=e[n],M(t)?this[n]=t:this["_"+n]=t;this._ordinalParseLenient=new RegExp(this._ordinalParse.source+"|"+/\d{1,2}/.source)}function $n(e,t,n,r){var i=k(),o=a().set(r,t);return i[n](o,e)}function wn(e,t,n,r,i){if("number"==typeof e&&(t=e,e=void 0),e=e||"",null!=t)return $n(e,t,n,i);var o,a=[];for(o=0;r>o;o++)a[o]=$n(e,o,n,i);return a}function xn(e,t){return wn(e,t,"months",12,"month")}function Cn(e,t){return wn(e,t,"monthsShort",12,"month")}function kn(e,t){return wn(e,t,"weekdays",7,"day")}function En(e,t){return wn(e,t,"weekdaysShort",7,"day")}function Sn(e,t){return wn(e,t,"weekdaysMin",7,"day")}function _n(){var e=this._data;return this._milliseconds=gi(this._milliseconds),this._days=gi(this._days),this._months=gi(this._months),e.milliseconds=gi(e.milliseconds),e.seconds=gi(e.seconds),e.minutes=gi(e.minutes),e.hours=gi(e.hours),e.months=gi(e.months),e.years=gi(e.years),this}function Mn(e,t,n,r){var i=Ze(t,n);return e._milliseconds+=r*i._milliseconds,e._days+=r*i._days,e._months+=r*i._months,e._bubble()}function Tn(e,t){return Mn(this,e,t,1)}function Dn(e,t){return Mn(this,e,t,-1)}function An(e){return 0>e?Math.floor(e):Math.ceil(e)}function On(){var e,t,n,r,i,o=this._milliseconds,a=this._days,s=this._months,l=this._data;return o>=0&&a>=0&&s>=0||0>=o&&0>=a&&0>=s||(o+=864e5*An(Rn(s)+a),a=0,s=0),l.milliseconds=o%1e3,e=m(o/1e3),l.seconds=e%60,t=m(e/60),l.minutes=t%60,n=m(t/60),l.hours=n%24,a+=m(n/24),i=m(Nn(a)),s+=i,a-=An(Rn(i)),r=m(s/12),s%=12,l.days=a,l.months=s,l.years=r,this}function Nn(e){return 4800*e/146097}function Rn(e){return 146097*e/4800}function In(e){var t,n,r=this._milliseconds;if("month"===(e=S(e))||"year"===e)return t=this._days+r/864e5,n=this._months+Nn(t),"month"===e?n:n/12;switch(t=this._days+Math.round(Rn(this._months)),e){case"week":return t/7+r/6048e5;case"day":return t+r/864e5;case"hour":return 24*t+r/36e5;case"minute":return 1440*t+r/6e4;case"second":return 86400*t+r/1e3;case"millisecond":return Math.floor(864e5*t)+r;default:throw new Error("Unknown unit "+e)}}function Pn(){return this._milliseconds+864e5*this._days+this._months%12*2592e6+31536e6*g(this._months/12)}function Fn(e){return function(){return this.as(e)}}function jn(e){return e=S(e),this[e+"s"]()}function Ln(e){return function(){return this._data[e]}}function Un(){return m(this.days()/7)}function Hn(e,t,n,r,i){return i.relativeTime(t||1,!!n,e,r)}function qn(e,t,n){var r=Ze(e).abs(),i=Oi(r.as("s")),o=Oi(r.as("m")),a=Oi(r.as("h")),s=Oi(r.as("d")),l=Oi(r.as("M")),u=Oi(r.as("y")),c=i=o&&["m"]||o=a&&["h"]||a=s&&["d"]||s=l&&["M"]||l=u&&["y"]||["yy",u];return c[2]=t,c[3]=+e>0,c[4]=n,Hn.apply(null,c)}function Vn(e,t){return void 0!==Ni[e]&&(void 0===t?Ni[e]:(Ni[e]=t,!0))}function zn(e){var t=this.localeData(),n=qn(this,!e,t);return e&&(n=t.pastFuture(+this,n)),t.postformat(n)}function Bn(){var e,t,n,r=Ri(this._milliseconds)/1e3,i=Ri(this._days),o=Ri(this._months);e=m(r/60),t=m(e/60),r%=60,e%=60,n=m(o/12),o%=12;var a=n,s=o,l=i,u=t,c=e,f=r,d=this.asSeconds();return d?(0>d?"-":"")+"P"+(a?a+"Y":"")+(s?s+"M":"")+(l?l+"D":"")+(u||c||f?"T":"")+(u?u+"H":"")+(c?c+"M":"")+(f?f+"S":""):"P0D"}var Yn,Wn,Gn=e.momentProperties=[],Kn=!1,Zn={},Jn={},Qn=/(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,Xn=/(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g,er={},tr={},nr=/\d/,rr=/\d\d/,ir=/\d{3}/,or=/\d{4}/,ar=/[+-]?\d{6}/,sr=/\d\d?/,lr=/\d\d\d\d?/,ur=/\d\d\d\d\d\d?/,cr=/\d{1,3}/,fr=/\d{1,4}/,dr=/[+-]?\d{1,6}/,pr=/\d+/,hr=/[+-]?\d+/,mr=/Z|[+-]\d\d:?\d\d/gi,gr=/Z|[+-]\d\d(?::?\d\d)?/gi,vr=/[+-]?\d+(\.\d{1,3})?/,yr=/[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i,br={},$r={},wr=0,xr=1,Cr=2,kr=3,Er=4,Sr=5,_r=6,Mr=7,Tr=8;R("M",["MM",2],"Mo",function(){return this.month()+1}),R("MMM",0,0,function(e){return this.localeData().monthsShort(this,e)}),R("MMMM",0,0,function(e){return this.localeData().months(this,e)}),E("month","M"),L("M",sr),L("MM",sr,rr),L("MMM",function(e,t){return t.monthsShortRegex(e)}),L("MMMM",function(e,t){return t.monthsRegex(e)}),V(["M","MM"],function(e,t){t[xr]=g(e)-1}),V(["MMM","MMMM"],function(e,t,n,r){var i=n._locale.monthsParse(e,r,n._strict);null!=i?t[xr]=i:l(n).invalidMonth=e});var Dr=/D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?/,Ar="January_February_March_April_May_June_July_August_September_October_November_December".split("_"),Or="Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),Nr=yr,Rr=yr,Ir={};e.suppressDeprecationWarnings=!1;var Pr=/^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/,Fr=/^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/,jr=/Z|[+-]\d\d(?::?\d\d)?/,Lr=[["YYYYYY-MM-DD",/[+-]\d{6}-\d\d-\d\d/],["YYYY-MM-DD",/\d{4}-\d\d-\d\d/],["GGGG-[W]WW-E",/\d{4}-W\d\d-\d/],["GGGG-[W]WW",/\d{4}-W\d\d/,!1],["YYYY-DDD",/\d{4}-\d{3}/],["YYYY-MM",/\d{4}-\d\d/,!1],["YYYYYYMMDD",/[+-]\d{10}/],["YYYYMMDD",/\d{8}/],["GGGG[W]WWE",/\d{4}W\d{3}/],["GGGG[W]WW",/\d{4}W\d{2}/,!1],["YYYYDDD",/\d{7}/]],Ur=[["HH:mm:ss.SSSS",/\d\d:\d\d:\d\d\.\d+/],["HH:mm:ss,SSSS",/\d\d:\d\d:\d\d,\d+/],["HH:mm:ss",/\d\d:\d\d:\d\d/],["HH:mm",/\d\d:\d\d/],["HHmmss.SSSS",/\d\d\d\d\d\d\.\d+/],["HHmmss,SSSS",/\d\d\d\d\d\d,\d+/],["HHmmss",/\d\d\d\d\d\d/],["HHmm",/\d\d\d\d/],["HH",/\d\d/]],Hr=/^\/?Date\((\-?\d+)/i;e.createFromInputFallback=ie("moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to https://github.com/moment/moment/issues/1407 for more info.",function(e){e._d=new Date(e._i+(e._useUTC?" UTC":""))}),R("Y",0,0,function(){var e=this.year();return 9999>=e?""+e:"+"+e}),R(0,["YY",2],0,function(){return this.year()%100}),R(0,["YYYY",4],0,"year"),R(0,["YYYYY",5],0,"year"),R(0,["YYYYYY",6,!0],0,"year"),E("year","y"),L("Y",hr),L("YY",sr,rr),L("YYYY",fr,or),L("YYYYY",dr,ar),L("YYYYYY",dr,ar),V(["YYYYY","YYYYYY"],wr),V("YYYY",function(t,n){n[wr]=2===t.length?e.parseTwoDigitYear(t):g(t)}),V("YY",function(t,n){n[wr]=e.parseTwoDigitYear(t)}),V("Y",function(e,t){t[wr]=parseInt(e,10)}),e.parseTwoDigitYear=function(e){return g(e)+(g(e)>68?1900:2e3)};var qr=T("FullYear",!1);e.ISO_8601=function(){};var Vr=ie("moment().min is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548",function(){var e=Te.apply(null,arguments);return this.isValid()&&e.isValid()?this>e?this:e:c()}),zr=ie("moment().max is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548",function(){var e=Te.apply(null,arguments);return this.isValid()&&e.isValid()?e>this?this:e:c()}),Br=function(){return Date.now?Date.now():+new Date};Ie("Z",":"),Ie("ZZ",""),L("Z",gr),L("ZZ",gr),V(["Z","ZZ"],function(e,t,n){n._useUTC=!0,n._tzm=Pe(gr,e)});var Yr=/([\+\-]|\d\d)/gi;e.updateOffset=function(){};var Wr=/(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/,Gr=/^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/;Ze.fn=Ne.prototype;var Kr=et(1,"add"),Zr=et(-1,"subtract");e.defaultFormat="YYYY-MM-DDTHH:mm:ssZ";var Jr=ie("moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.",function(e){return void 0===e?this.localeData():this.locale(e)});R(0,["gg",2],0,function(){return this.weekYear()%100}),R(0,["GG",2],0,function(){return this.isoWeekYear()%100}),Nt("gggg","weekYear"),Nt("ggggg","weekYear"),Nt("GGGG","isoWeekYear"),Nt("GGGGG","isoWeekYear"),E("weekYear","gg"),E("isoWeekYear","GG"),L("G",hr),L("g",hr),L("GG",sr,rr),L("gg",sr,rr),L("GGGG",fr,or),L("gggg",fr,or),L("GGGGG",dr,ar),L("ggggg",dr,ar),z(["gggg","ggggg","GGGG","GGGGG"],function(e,t,n,r){t[r.substr(0,2)]=g(e)}),z(["gg","GG"],function(t,n,r,i){n[i]=e.parseTwoDigitYear(t)}),R("Q",0,"Qo","quarter"),E("quarter","Q"),L("Q",nr),V("Q",function(e,t){t[xr]=3*(g(e)-1)}),R("w",["ww",2],"wo","week"),R("W",["WW",2],"Wo","isoWeek"),E("week","w"),E("isoWeek","W"),L("w",sr),L("ww",sr,rr),L("W",sr),L("WW",sr,rr),z(["w","ww","W","WW"],function(e,t,n,r){t[r.substr(0,1)]=g(e)});var Qr={dow:0,doy:6};R("D",["DD",2],"Do","date"),E("date","D"),L("D",sr),L("DD",sr,rr),L("Do",function(e,t){return e?t._ordinalParse:t._ordinalParseLenient}),V(["D","DD"],Cr),V("Do",function(e,t){t[Cr]=g(e.match(sr)[0],10)});var Xr=T("Date",!0);R("d",0,"do","day"),R("dd",0,0,function(e){return this.localeData().weekdaysMin(this,e)}),R("ddd",0,0,function(e){return this.localeData().weekdaysShort(this,e)}),R("dddd",0,0,function(e){return this.localeData().weekdays(this,e)}),R("e",0,0,"weekday"),R("E",0,0,"isoWeekday"),E("day","d"),E("weekday","e"),E("isoWeekday","E"),L("d",sr),L("e",sr),L("E",sr),L("dd",yr),L("ddd",yr),L("dddd",yr),z(["dd","ddd","dddd"],function(e,t,n,r){var i=n._locale.weekdaysParse(e,r,n._strict);null!=i?t.d=i:l(n).invalidWeekday=e}),z(["d","e","E"],function(e,t,n,r){t[r]=g(e)});var ei="Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),ti="Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),ni="Su_Mo_Tu_We_Th_Fr_Sa".split("_");R("DDD",["DDDD",3],"DDDo","dayOfYear"),E("dayOfYear","DDD"),L("DDD",cr),L("DDDD",ir),V(["DDD","DDDD"],function(e,t,n){n._dayOfYear=g(e)}),R("H",["HH",2],0,"hour"),R("h",["hh",2],0,tn),R("hmm",0,0,function(){return""+tn.apply(this)+N(this.minutes(),2)}),R("hmmss",0,0,function(){return""+tn.apply(this)+N(this.minutes(),2)+N(this.seconds(),2)}),R("Hmm",0,0,function(){return""+this.hours()+N(this.minutes(),2)}),R("Hmmss",0,0,function(){return""+this.hours()+N(this.minutes(),2)+N(this.seconds(),2)}),nn("a",!0),nn("A",!1),E("hour","h"),L("a",rn),L("A",rn),L("H",sr),L("h",sr),L("HH",sr,rr),L("hh",sr,rr),L("hmm",lr),L("hmmss",ur),L("Hmm",lr),L("Hmmss",ur),V(["H","HH"],kr),V(["a","A"],function(e,t,n){n._isPm=n._locale.isPM(e),n._meridiem=e}),V(["h","hh"],function(e,t,n){t[kr]=g(e),l(n).bigHour=!0}),V("hmm",function(e,t,n){var r=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r)),l(n).bigHour=!0}),V("hmmss",function(e,t,n){var r=e.length-4,i=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r,2)),t[Sr]=g(e.substr(i)),l(n).bigHour=!0}),V("Hmm",function(e,t,n){var r=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r))}),V("Hmmss",function(e,t,n){var r=e.length-4,i=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r,2)),t[Sr]=g(e.substr(i))});var ri=/[ap]\.?m?\.?/i,ii=T("Hours",!0);R("m",["mm",2],0,"minute"),E("minute","m"),L("m",sr),L("mm",sr,rr),V(["m","mm"],Er);var oi=T("Minutes",!1);R("s",["ss",2],0,"second"),E("second","s"),L("s",sr),L("ss",sr,rr),V(["s","ss"],Sr);var ai=T("Seconds",!1);R("S",0,0,function(){return~~(this.millisecond()/100)}),R(0,["SS",2],0,function(){return~~(this.millisecond()/10)}),R(0,["SSS",3],0,"millisecond"),R(0,["SSSS",4],0,function(){return 10*this.millisecond()}),R(0,["SSSSS",5],0,function(){return 100*this.millisecond()}),R(0,["SSSSSS",6],0,function(){return 1e3*this.millisecond()}),R(0,["SSSSSSS",7],0,function(){return 1e4*this.millisecond()}),R(0,["SSSSSSSS",8],0,function(){return 1e5*this.millisecond()}),R(0,["SSSSSSSSS",9],0,function(){return 1e6*this.millisecond()}),E("millisecond","ms"),L("S",cr,nr),L("SS",cr,rr),L("SSS",cr,ir);var si;for(si="SSSS";si.length<=9;si+="S")L(si,pr);for(si="S";si.length<=9;si+="S")V(si,sn);var li=T("Milliseconds",!1);R("z",0,0,"zoneAbbr"),R("zz",0,0,"zoneName");var ui=p.prototype;ui.add=Kr,ui.calendar=nt,ui.clone=rt,ui.diff=ct,ui.endOf=xt,ui.format=ht,ui.from=mt,ui.fromNow=gt,ui.to=vt,ui.toNow=yt,ui.get=O,ui.invalidAt=At,ui.isAfter=it,ui.isBefore=ot,ui.isBetween=at,ui.isSame=st,ui.isSameOrAfter=lt,ui.isSameOrBefore=ut,ui.isValid=Tt,ui.lang=Jr,ui.locale=bt,ui.localeData=$t,ui.max=zr,ui.min=Vr,ui.parsingFlags=Dt,ui.set=O,ui.startOf=wt,ui.subtract=Zr,ui.toArray=St,ui.toObject=_t,ui.toDate=Et,ui.toISOString=pt,ui.toJSON=Mt,ui.toString=dt,ui.unix=kt,ui.valueOf=Ct,ui.creationData=Ot,ui.year=qr,ui.isLeapYear=de,ui.weekYear=Rt,ui.isoWeekYear=It,ui.quarter=ui.quarters=Ut,ui.month=J,ui.daysInMonth=Q,ui.week=ui.weeks=zt,ui.isoWeek=ui.isoWeeks=Bt,ui.weeksInYear=Ft,ui.isoWeeksInYear=Pt,ui.date=Xr,ui.day=ui.days=Jt,ui.weekday=Qt,ui.isoWeekday=Xt,ui.dayOfYear=en,ui.hour=ui.hours=ii,ui.minute=ui.minutes=oi,ui.second=ui.seconds=ai,ui.millisecond=ui.milliseconds=li,ui.utcOffset=Le,ui.utc=He,ui.local=qe,ui.parseZone=Ve,ui.hasAlignedHourOffset=ze,ui.isDST=Be,ui.isDSTShifted=Ye,ui.isLocal=We,ui.isUtcOffset=Ge,ui.isUtc=Ke,ui.isUTC=Ke,ui.zoneAbbr=ln,ui.zoneName=un,ui.dates=ie("dates accessor is deprecated. Use date instead.",Xr),ui.months=ie("months accessor is deprecated. Use month instead",J),ui.years=ie("years accessor is deprecated. Use year instead",qr),ui.zone=ie("moment().zone is deprecated, use moment().utcOffset instead. https://github.com/moment/moment/issues/1779",Ue);var ci=ui,fi={sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"},di={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},pi=/\d{1,2}/,hi={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},mi=y.prototype;mi._calendar=fi,mi.calendar=dn,mi._longDateFormat=di,mi.longDateFormat=pn,mi._invalidDate="Invalid date",mi.invalidDate=hn,mi._ordinal="%d",mi.ordinal=mn,mi._ordinalParse=pi,mi.preparse=gn,mi.postformat=gn,mi._relativeTime=hi,mi.relativeTime=vn,mi.pastFuture=yn,mi.set=bn,mi.months=W,mi._months=Ar,mi.monthsShort=G,mi._monthsShort=Or,mi.monthsParse=K,mi._monthsRegex=Rr,mi.monthsRegex=ee,mi._monthsShortRegex=Nr,mi.monthsShortRegex=X,mi.week=Ht,mi._week=Qr,mi.firstDayOfYear=Vt,mi.firstDayOfWeek=qt,mi.weekdays=Wt,mi._weekdays=ei,mi.weekdaysMin=Kt,mi._weekdaysMin=ni,mi.weekdaysShort=Gt,mi._weekdaysShort=ti,mi.weekdaysParse=Zt,mi.isPM=on,mi._meridiemParse=ri,mi.meridiem=an,x("en",{ordinalParse:/\d{1,2}(th|st|nd|rd)/,ordinal:function(e){var t=e%10;return e+(1===g(e%100/10)?"th":1===t?"st":2===t?"nd":3===t?"rd":"th")}}),e.lang=ie("moment.lang is deprecated. Use moment.locale instead.",x),e.langData=ie("moment.langData is deprecated. Use moment.localeData instead.",k);var gi=Math.abs,vi=Fn("ms"),yi=Fn("s"),bi=Fn("m"),$i=Fn("h"),wi=Fn("d"),xi=Fn("w"),Ci=Fn("M"),ki=Fn("y"),Ei=Ln("milliseconds"),Si=Ln("seconds"),_i=Ln("minutes"),Mi=Ln("hours"),Ti=Ln("days"),Di=Ln("months"),Ai=Ln("years"),Oi=Math.round,Ni={s:45,m:45,h:22,d:26,M:11},Ri=Math.abs,Ii=Ne.prototype;return Ii.abs=_n,Ii.add=Tn,Ii.subtract=Dn,Ii.as=In,Ii.asMilliseconds=vi,Ii.asSeconds=yi,Ii.asMinutes=bi,Ii.asHours=$i,Ii.asDays=wi,Ii.asWeeks=xi,Ii.asMonths=Ci,Ii.asYears=ki,Ii.valueOf=Pn,Ii._bubble=On,Ii.get=jn,Ii.milliseconds=Ei,Ii.seconds=Si,Ii.minutes=_i,Ii.hours=Mi,Ii.days=Ti,Ii.weeks=Un,Ii.months=Di,Ii.years=Ai,Ii.humanize=zn,Ii.toISOString=Bn,Ii.toString=Bn,Ii.toJSON=Bn,Ii.locale=bt,Ii.localeData=$t,Ii.toIsoString=ie("toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)",Bn),Ii.lang=Jr,R("X",0,0,"unix"),R("x",0,0,"valueOf"),L("x",hr),L("X",vr),V("X",function(e,t,n){n._d=new Date(1e3*parseFloat(e,10))}),V("x",function(e,t,n){n._d=new Date(g(e))}),e.version="2.11.1",function(e){Yn=e}(Te),e.fn=ci,e.min=Ae,e.max=Oe,e.now=Br,e.utc=a,e.unix=cn,e.months=xn,e.isDate=n,e.locale=x,e.invalid=c,e.duration=Ze,e.isMoment=h,e.weekdays=kn,e.parseZone=fn,e.localeData=k,e.isDuration=Re,e.monthsShort=Cn,e.weekdaysMin=Sn,e.defineLocale=C,e.weekdaysShort=En,e.normalizeUnits=S,e.relativeTimeThreshold=Vn,e.prototype=ci,e}),define("common/bundles/vendors",["common/require","common/angular","common/angularAnimate","common/angularBootstrap","common/angular-file-upload","common/angularMocks","common/angularResource","common/angularRoute","common/angularXeditable","common/text-angular","common/ui-select","common/d3","common/lodash","common/moment"],function(){}),define("common/modules/apis",["common/angular"],function(e){"use strict";return e.module("common.apis",[])}),define("common/services/api",["common/angular","common/lodash","common/modules/apis"],function(e,t,n){"use strict";n.factory("api",["$log","$http","$httpParamSerializer","$q","$timeout",function(n,r,i,o,a){function s(e){return e.data.is_error?(n.error(e.data),o.reject(e.data.error_message)):e.data}function l(e){var n={options:{limit:0}};return JSON.stringify(t.merge(n,e||{}))}n.debug("api");return{extend:function(t){return e.extend(Object.create(this),t)},getAll:function(e,r,i,a,s,l,u){return n.debug("api.all"),r=r||{},l=l||"get",o.all([function(){var n=t.assign({},r,s||{},{options:t.assign({},r.options,{sort:a||"id DESC"})});return i&&(n.options.offset=(i.page-1)*i.size,n.options.limit=i.size),this.sendGET(e,l,n,u)}.bind(this)(),function(){if(!i)return o.resolve();var n=t.assign({},r,{return:"id"});return n=t.omit(n,function(e,n){return t.startsWith(n,"api.")}),this.sendGET(e,l,n,u)}.bind(this)()]).then(function(e){var n=e[0],r=i?e[1]:n;return{list:n.values,total:r.count,allIds:t.compact(r.values.map(function(e){return e.id})).join(",")}})},mockGET:function(e,t){var n=o.defer();return a(function(){n.resolve(e)},t||0),n.promise},mockPOST:function(e,t){return this.mockGET.apply(this,arguments)},sendGET:function(e,t,n,i){return r({method:"GET",url:"/civicrm/ajax/rest",cache:void 0===i||!!i,responseType:"json",params:{sequential:1,json:l(n),entity:e,action:t}}).then(s)},sendPOST:function(e,t,o){return n.debug("api.sendPOST"),r({method:"POST",url:"/civicrm/ajax/rest",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},responseType:"json",data:{json:l(o),sequential:1,entity:e,action:t},transformRequest:i}).then(s)}}}])}),define("common/services/api/appraisal",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.appraisal",["$log","api",function(e,t){return e.debug("api.appraisal"),t.extend({all:function(t,n,r){return e.debug("api.appraisal.api"),this.getAll("Appraisal",t,n,r)},create:function(t){return e.debug("api.appraisal.create"),this.sendPOST("Appraisal","create",t).then(function(e){return e.values[0]})},find:function(t){return e.debug("api.appraisal.find"),this.sendGET("Appraisal","get",{id:""+t},!1).then(function(e){return e.values[0]})}})}])}),define("common/services/api/option-group",["common/lodash","common/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("api.optionGroup",["$log","api",function(t,n){function r(t){return t.values.map(function(t){var n=e.clone(t);return n.option_group_name=n["option_group_id.name"],delete n["option_group_id.name"],n})}function i(t){return e.transform(t,function(e,t){var n=t.option_group_name;e[n]=e[n]||[],e[n].push(t)})}return t.debug("api.optionGroup"),n.extend({valuesOf:function(t,n,o){var a=e.isArray(t);return this.sendGET("OptionValue","get",e.assign({"option_group_id.name":{IN:a?t:[t]},is_active:"1",return:["option_group_id.name","option_group_id","id","name","label","value","weight","is_active","is_reserved"]},n),o).then(r).then(function(e){return a?i(e):e})}})}])}),define("common/services/api/appraisal-cycle",["common/lodash","common/modules/apis","common/services/api","common/services/api/option-group"],function(e,t){"use strict";t.factory("api.appraisal-cycle",["$q","$log","api","api.optionGroup",function(t,n,r,i){return n.debug("api.appraisal-cycle"),r.extend({all:function(e,t,r){return n.debug("api.appraisal-cycle.all"),this.getAll("AppraisalCycle",e,t,r,{"api.AppraisalCycle.getappraisalsperstep":{}})},create:function(t){return n.debug("api.appraisal-cycle.create"),this.sendPOST("AppraisalCycle","create",e.assign(t,{"api.AppraisalCycle.getappraisalsperstep":{}})).then(function(e){return e.values[0]})},find:function(e){n.debug("api.appraisal-cycle.find");var t={id:""+e,"api.AppraisalCycle.getappraisalsperstep":{}};return this.sendGET("AppraisalCycle","get",t,!1).then(function(e){return e.values[0]})},grades:function(){return n.debug("grades"),this.mockGET([{label:1,value:17},{label:2,value:74},{label:3,value:90},{label:4,value:30}])},statuses:function(){return n.debug("api.appraisal-cycle.statuses"),i.valuesOf("appraisal_status")},statusOverview:function(e){return n.debug("api.appraisal-cycle.statusOverview"),this.sendGET("AppraisalCycle","getstatusoverview",e).then(function(e){return e.values})},update:function(t){return n.debug("api.appraisal-cycle.update"),this.sendPOST("AppraisalCycle","create",e.assign(t,{"api.AppraisalCycle.getappraisalsperstep":{}})).then(function(e){return e.values[0]})},total:function(e){return n.debug("api.appraisal-cycle.total"),this.sendGET("AppraisalCycle","getcount",e||{}).then(function(e){return e.result})},types:function(){return n.debug("api.appraisal-cycle.types"),i.valuesOf("appraisal_cycle_type")}})}])}),define("common/services/api/contact-job-role-api.api",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("ContactJobRoleAPI",["$log","api",function(e,t){return e.debug("ContactJobRoleAPI"),t.extend({all:function(t,n,r,i){return e.debug("ContactJobRoleAPI.all()"),this.getAll("ContactHrJobRoles",t,n,r,i)}})}])}),define("common/bundles/apis",["common/services/api/appraisal","common/services/api/appraisal-cycle","common/services/api/contact-job-role-api.api","common/services/api/option-group"],function(){}),define("common/modules/services",["common/angular","common/angular-file-upload"],function(e){"use strict";return e.module("common.services",["angularFileUpload"])}),define("common/services/before-hash-query-params.service",["common/lodash","common/modules/services"],function(e,t){"use strict";t.factory("beforeHashQueryParams",["$log","$window",function(t,n){function r(e){var t=e||n.location.href,r=o(t);return-1===r.indexOf("?")?{}:i(a(r))}function i(t){return t.length?e.transform(t,function(e,t){var n=t.split("=");n[0]&&(e[n[0]]=n[1]?decodeURI(n[1]):null)},{}):{}}function o(e){var t=e.indexOf("#");return e.substring(0,-1!==t?t:e.length)}function a(e){var t=e.indexOf("?");return e.substr(t+1).split("&")}return t.debug("Service: beforeHashQueryParams"),{parse:r}}])}),function(e){define("common/services/check-permissions",["common/lodash","common/modules/services"],function(t,n){"use strict";n.factory("checkPermissions",["$q",function(n){return function(r){return r=t.isArray(r)?r:[r],n.resolve(r.every(function(t){return e.checkPerm(t)}))}}])})}(CRM),function(e){define("common/services/crm-ang.service",["common/lodash","common/modules/services"],function(t,n){"use strict";function r(t,n){return e.loadForm(t,n)}n.factory("crmAngService",function(){return{loadForm:r}})})}(CRM),define("common/services/detect-device.service",["common/modules/services"],function(e){"use strict";e.factory("detectDevice",[function(){return{isMobile:function(){return document.getElementsByTagName("body")[0].classList.contains("mobile")}}}])}),define("common/services/dom-event-trigger",["common/modules/services"],function(e){"use strict";!function(t){e.factory("DOMEventTrigger",function(){return function(e,n){t(document).trigger(e,n)}})}(CRM.$)}),define("common/services/file-mime-types",["common/lodash","common/modules/services"],function(e,t){"use strict";t.factory("fileMimeTypes",["$q",function(e){var t={txt:"plain",png:"png",jpeg:"jpeg",bmp:"bmp",gif:"gif",pdf:"pdf",doc:"msword",docx:"vnd.openxmlformats-officedocument.wordprocessingml.document",xls:"vnd.ms-excel",xlsx:"vnd.openxmlformats-officedocument.spreadsheetml.sheet",ppt:"vnd.ms-powerpoint",pptx:"vnd.openxmlformats-officedocument.presentationml.presentation"};return{getMimeTypeFor:function(n){return e.resolve(t[n])}}}])}),define("common/services/file-upload",["common/modules/services","common/lodash","common/angular-file-upload"],function(e,t){"use strict";e.factory("FileUpload",["$q","$log","FileUploader",function(e,n,r){function i(e){throw new Error(e+" missing from parameter")}function o(e,t,r,i){n.error(" ===== Item Error: "+r+" ======"),n.error(" ===== - item ======"),n.error(e),n.error(" ===== - response ======"),n.error(t),n.error(" ===== - headers ======"),n.error(i)}function a(e){return t.defaults(e,{allowedMimeTypes:{txt:"plain",png:"png",jpeg:"jpeg",bmp:"bmp",gif:"gif",pdf:"pdf"},url:"/civicrm/ajax/attachment",queueLimit:1})}return{uploader:function(n){var s,l,u,c=[];return n?(n=a(n),s=new r({url:n.url,queueLimit:+n.queueLimit,onCompleteItem:function(e,t){c.push(t)},onCompleteAll:function(){u.resolve(c)},onErrorItem:function(e){o.apply(null,arguments),u.reject("Could not upload file: "+e.file.name)},formData:[{entity_table:n.entityTable||i("entityTable"),crm_attachment_token:n.crmAttachmentToken||i("crmAttachmentToken")}],filters:[{name:"fileFormatFilter",fn:function(e){var r=e.type.slice(e.type.lastIndexOf("/")+1);return t.includes(t.values(n.allowedMimeTypes),r)}}]}),s.uploadAll=function(){return l=s.uploadAll,function(n){return u=e.defer(),s.onBeforeUploadItem=function(e){t.each(n,function(n,r){var i={};i[t.snakeCase(r)]=n,e.formData.push(i)})},l.apply(s),u.promise}}(),s):i("custom settings")}}}])}),define("common/services/file.service",["common/modules/services"],function(e){"use strict";e.factory("fileService",["$http","$window","$log",function(e,t,n){return n.debug("Service: fileService"),{openFile:function(n){return e.get(n.url,{responseType:"arraybuffer"}).success(function(e){var r=new Blob([e],{type:n.fileType});t.navigator.msSaveOrOpenBlob?t.navigator.msSaveOrOpenBlob(r,n.name):t.open(URL.createObjectURL(r),"_blank")})}}}])}),define("common/services/hr-settings",["common/modules/services"],function(e){"use strict";e.factory("HR_settings",function(){return{DATE_FORMAT:null}})}),function(e){define("common/services/notification.service",["common/lodash","common/modules/services"],function(t,n){"use strict";n.factory("notificationService",function(){return t(["alert","success","info","error"]).map(function(t){return[t,function(n,r,i){return e.alert(r,n,t,i)}]}).zipObject().value()})})}(CRM),define("common/services/pub-sub",["common/modules/services"],function(e){"use strict";var t=Object.create(null);e.factory("pubSub",["$rootScope",function(e){return{subscribe:function(n,r){var i;return t[n]=t[n]||[],r.$rootScope=e,i=t[n].push(r)-1,{remove:function(){delete t[n][i]}}},publish:function(e,n){t[e]&&(n=void 0!=n?n:{},t[e].forEach(function(e){e.$rootScope.$applyAsync(function(){e(n)})}))}}}])}),define("common/bundles/services",["common/services/before-hash-query-params.service","common/services/check-permissions","common/services/crm-ang.service","common/services/detect-device.service","common/services/dom-event-trigger","common/services/file-mime-types","common/services/file-upload","common/services/file.service","common/services/hr-settings","common/services/notification.service","common/services/pub-sub"],function(){}),define("common/modules/components",["common/angular"],function(e){return e.module("common.components",[])}),define("common/components/heatmap.component",["common/lodash","common/moment","common/modules/components"],function(e,t,n){function r(){function n(e){e.values&&(u(),l(),c())}function r(){return Object.values(d.values).filter(function(e){return!1!==e})}function i(e,t){return e.reduce(function(e,n){return Math.abs(n.value-t)');r(n,t),e.after(n)}function r(e,n){function r(){n.isOpen=!0,n.$apply()}t.isMobile()||(e.on("click",r),n.$on("$destroy",function(){e.off("click",r)}))}var i=e[0],o=i.compile;return i.compile=function(){var e=o.apply(this,arguments);return function(t,i,o){e.apply(this,arguments),n(i,t),r(i,t)}},e}]}),define("common/decorators/uib-datepicker-mobile-version.decorator",["common/moment","common/services/detect-device.service"],function(e){"use strict";return["$delegate","detectDevice",function(t,n){function r(t){return t?e(t).format("Y-MM-DD"):""}var i=t[0],o=i.compile;return i.require=["ngModel","uibDatepickerPopup"],i.compile=function(){var e=o.apply(this,arguments);return function(t,i,o,a){n.isMobile()?(i.prop("type","date"),o.ngReadonly=!1,a[0].$formatters.push(function(e){return r(e)}),t.$watch("datepickerOptions.minDate",function(e){o.$set("min",r(e))}),t.$watch("datepickerOptions.maxDate",function(e){o.$set("max",r(e))})):e.apply(this,arguments)}},t}]}),define("common/decorators/xeditable-disable-calendar-icon.decorator",[],function(){"use strict";return["$delegate",function(e){var t=e[0],n=t.compile;return t.compile=function(){var e=n.apply(this,arguments);return function(t,n,r){e.apply(this,arguments),r.eShowCalendarButton=!1}},e}]}),define("common/decorators/ui-bootstrap/uib-tabset",[],function(){"use strict";return["$delegate",function(e){return e[0].bindToController.customHeaderClass="@",e}]}),define("common/decorators/ui-bootstrap/uib-modal.decorator",["common/angular"],function(e){"use strict";return["$delegate","$document",function(t,n){function r(){var t,r=[{item:e.element(n[0].body),styles:[{name:"overflow",old:null,new:"hidden"},{name:"height",old:null,new:"100%"},{name:"width",old:null,new:"100%"}]},{item:e.element(n[0].getElementsByTagName("html")[0]),styles:[{name:"overflow",old:null,new:"hidden"},{name:"height",old:null,new:"100%"},{name:"width",old:null,new:"100%"}]}];return r.forEach(function(e){e.styles.forEach(function(t){t.old=e.item.css(t.name),e.item.css(t.name,t.new)})}),t=i.apply(this,arguments),t.closed.then(function(){r.forEach(function(e){e.styles.forEach(function(t){e.item.css(t.name,t.old)})})}),t}var i=t.open;return t.open=r,t}]}),define("common/modules/templates",["common/angular"],function(e){"use strict";return e.module("common.templates",[]).run(["$templateCache",function(e){e.put("dialog.html",'\n\n\n'),e.put("help-text.html",'\n'),e.put("loading.html",'
    \n
    \n
    \n
    \n'),e.put("time-amount-picker.html",'
    \n
    \n \n \n
    \n h\n
    \n \n \n
    \n m\n
    \n'),e.put("timepicker-select.html",'\n\n'),e.put("civihr-ui-select/choices.tpl.html",'
      \n
    • \n
      \n
        \n
      • \n
        \n
      • \n
      \n
    • \n
    \n'),e.put("civihr-ui-select/match-multiple.tpl.html",'\n
  • \n \n \n
  • \n\n'),e.put("civihr-ui-select/match.tpl.html",'\n {{$select.contactList ? \'-select-\' : $select.placeholder}}\n \n \n \n\n'),e.put("civihr-ui-select/select-contacts-multiple.tpl.html",'
    \n
    \n
      \n \n
    • \n \n
    • \n
    \n\n \n\n \n
    \n
    \n'),e.put("civihr-ui-select/select-contacts.tpl.html",'
    \n
    \n \n
    \n'),e.put("civihr-ui-select/select-multiple.tpl.html",'
    \n
    \n
      \n \n
    • \n \n
    • \n
    \n \n
    \n
    \n'),e.put("civihr-ui-select/select.tpl.html",'
    \n
    \n \n
    \n'),e.put("components/heatmap.html",'
      \n
    • \n {{day.name.short}}\n
    • \n
    \n'),e.put("contact-actions/contact-actions.html",'
    \n \n \n
    \n'),e.put("contact-actions/modals/form.html",'
    \n \n \n \n
    \n')}])}),define("common/modules/controllers",["common/angular","common/angularBootstrap","common/modules/apis"],function(e){"use strict";return e.module("common.controllers",["ui.bootstrap","common.apis"])}),define("common/modules/directives",["common/angular","common/decorators/ui-select-focus.decorator","common/decorators/uib-datepicker-calendar-icon.decorator","common/decorators/uib-datepicker-mobile-version.decorator","common/decorators/xeditable-disable-calendar-icon.decorator","common/decorators/ui-bootstrap/uib-tabset","common/decorators/ui-bootstrap/uib-modal.decorator","common/angularBootstrap","common/angularXeditable","common/ui-select","common/modules/templates","common/modules/controllers","common/modules/services","common/modules/apis"],function(e,t,n,r,i,o,a){"use strict";return e.module("common.directives",["common.templates","common.controllers","ui.select","ui.bootstrap","xeditable"]).config(["$provide",function(e){e.decorator("uibDatepickerPopupDirective",r),e.decorator("uibDatepickerPopupDirective",n),e.decorator("uibTabsetDirective",o),e.decorator("$uibModal",a),e.decorator("editableBsdateDirective",i),e.decorator("uiSelectDirective",t)}]).run(["$templateCache",function(e){var t="uib/template/tabs/tabset.html",n=jQuery(e.get(t));n.find("ul").addClass("{{tabset.customHeaderClass}}"),e.put(t,n.wrap("
    ").parent().html())}])}),define("common/services/api/contact-actions",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.contactActions",["$q","api",function(e,t){function n(e,n){return t.sendGET(e,"getoptions",{field:n,context:"search"}).then(function(e){return e.values})}function r(e){return t.sendGET("UFField","get",{uf_group_id:e,is_active:!0}).then(function(e){return e.values})}function i(n,r){return e(function(e,i){if(r.contact_type=n,r.email)return t.sendGET("CustomField","get",{return:["id"],custom_group_id:"Emergency_Contacts",name:"email"}).then(function(t){r["custom_"+t.id]=r.email,delete r.email,e()});e()}).then(function(){return t.sendPOST("Contact","create",r).then(function(e){return e.values[0]})})}return t.extend({getOptions:{forContactType:function(){return n.call(this,"Contact","contact_type")},forGroup:function(){return n.call(this,"GroupContact","group_id")},forTag:function(){return n.call(this,"EntityTag","tag_id")},forStateProvince:function(){return n.call(this,"Address","state_province_id")},forCountry:function(){return n.call(this,"Address","country_id")},forGender:function(){return n.call(this,"Contact","gender_id")},forDeceased:function(){return n.call(this,"Contact","is_deceased")}},save:{newIndividual:function(e){return i.call(this,"Individual",e)},newOrganization:function(e){return i.call(this,"Organization",e)},newHousehold:function(e){return i.call(this,"Household",e)}},getFormFields:{forNewIndividual:function(){return r.call(this,"new_individual")},forNewOrganization:function(){return r.call(this,"new_organization")},forNewHousehold:function(){return r.call(this,"new_household")}}})}])}),define("common/controllers/contact-actions/modal-ctrl",[],function(){"use strict";return function(e,t){this.errorMsg="",this.loading=!0,this.formFields=[],this.init=function(e){e().then(function(e){this.loading=!1,this.formFields=e}.bind(this)).catch(function(){this.loading=!1,this.errorMsg="Error while loading form fields"}.bind(this))},this.cancel=function(){t.dismiss("cancel")},this.save=function(n,r){this.loading=!0,n(this.formFields.reduce(function(e,t){return e[t.field_name]=t.value,e},{})).then(function(n){this.loading=!1,e.$broadcast(r,n),t.dismiss("cancel")}.bind(this)).catch(function(){this.loading=!1,this.errorMsg="Error while saving data"}.bind(this))}}}),define("common/controllers/contact-actions/new-individual-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Individual",i.init(r.getFormFields.forNewIndividual),i.submit=function(){i.save(r.save.newIndividual,"newIndividualCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewIndividualModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/new-household-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Household",i.init(r.getFormFields.forNewHousehold),i.submit=function(){i.save(r.save.newHousehold,"newHouseholdCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewHouseholdModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/new-organization-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Organization",i.init(r.getFormFields.forNewOrganization),i.submit=function(){i.save(r.save.newOrganization,"newOrganizationCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewOrganizationModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/contact-actions-ctrl",["common/modules/controllers","common/services/api/contact-actions","common/controllers/contact-actions/new-individual-ctrl","common/controllers/contact-actions/new-household-ctrl","common/controllers/contact-actions/new-organization-ctrl"],function(e){"use strict";e.controller("ContactActionsCtrl",["$scope","$rootElement","$uibModal","api.contactActions",function(e,t,n,r){var i=this;e.$watch(function(){return i.refineSearch.selected},function(t,n){t!==n&&e.$emit("contactRefineSearch",{field:t.field?t.field.label:null,option:t.option?t.option.value:null})},!0),i.refineSearch={selected:{field:null,option:null},availableFields:[{label:"Contact Type",getOptions:r.getOptions.forContactType},{label:"Group",getOptions:r.getOptions.forGroup},{label:"Tag",getOptions:r.getOptions.forTag},{label:"State / Province",getOptions:r.getOptions.forStateProvince},{label:"Country",getOptions:r.getOptions.forCountry},{label:"Gender",getOptions:r.getOptions.forGender},{label:"Deceased",getOptions:r.getOptions.forDeceased}],availableOptions:{refresh:function(){i.refineSearch.selected.field?(this.options=null,i.refineSearch.selected.field.getOptions().then(function(e){this.options=e}.bind(this))):this.options=[]},options:[]}},i.showNewIndividualModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewIndividualModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})},i.showNewHouseholdModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewHouseholdModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})},i.showNewOrganizationModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewOrganizationModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})}}])}),define("common/directives/prevent-animations",["common/modules/directives"],function(e){"use strict";e.directive("preventAnimations",["$animate",function(e){return{restrict:"A",link:function(t,n,r){e.enabled(n,!1)}}}])}),define("common/directives/loading",["common/modules/directives","common/directives/prevent-animations"],function(e){"use strict";e.directive("crmLoading",["$templateCache",function(e){return{scope:{show:"="},restrict:"E",replace:!0,transclude:!0,template:e.get("loading.html")}}])}),define("common/directives/contact-actions/contact-actions",["common/modules/directives","common/controllers/contact-actions/contact-actions-ctrl","common/directives/loading"],function(e){"use strict";e.directive("contactActions",[function(){return{restrict:"E",templateUrl:"contact-actions/contact-actions.html",controller:"ContactActionsCtrl",controllerAs:"$ctrl",link:function(e,t,n){e.$ctrl.refineSearchVisible=t.parent().parent()[0].hasAttribute("refine-search")}}}])}),define("common/directives/help-text.directive",["common/lodash","common/moment","common/modules/directives","common/services/notification.service"],function(e,t,n){function r(e,t){function n(){var n=e.getHelpText();t.info(e.title||r,n)}var r="Help";this.displayHelpText=n}function i(e,t,n){function r(){return t.find(".help-text").html()}e.getHelpText=r}n.directive("helpText",["$templateCache",function(e){return{restrict:"E",scope:{title:"@?"},transclude:!0,controller:r,controllerAs:"helpText",template:e.get("help-text.html"),link:i}}]),r.$inject=["$scope","notificationService"]}),define("common/directives/scroll-shadows.directive",["common/angular","common/modules/directives"],function(e,t){"use strict";function n(t,n,r){function i(){u(),a(),l(),s()}function o(){var e=f.width(),t=p+"__shadows--show-left",n=p+"__shadows--show-right",r=d.scrollLeft(),i=d.width();if(e<=i)return void d.removeClass(t+" "+n);d[r>0?"addClass":"removeClass"](t),d[r
    ').parent(),d=f.wrap('
    ').parent(),d.wrap('
    ')}var f,d,p="chr_scroll-shadows";!function(){c(),i(),o()}()}t.directive("scrollShadows",[function(){return{restrict:"A",controller:n}}]),n.$inject=["$element","$scope","$window"]}),define("common/directives/timepicker-select.directive",["common/moment","common/modules/directives"],function(e,t){"use strict";function n(t){function n(){var n=+t.timepickerSelectInterval||1,i=e.duration(t.timepickerSelectTimeFrom||"00:00"),o=e.duration(t.timepickerSelectTimeTo||"23:59");for(r.options=[];i.asMinutes()<=o.asMinutes();){var a=e.utc(i.asMilliseconds());r.options.push(a.format("HH:mm")),i.add(n,"minutes")}}var r=this;r.placeholder=t.timepickerSelectPlaceholder,r.options=[],t.$watchGroup(["timepickerSelectTimeFrom","timepickerSelectTimeTo","timepickerSelectInterval"],function(){n()})}t.directive("timepickerSelect",["$templateCache",function(e){return{scope:{timepickerSelectPlaceholder:"@",timepickerSelectTimeFrom:"<",timepickerSelectTimeTo:"<",timepickerSelectInterval:"<"},restrict:"A",controllerAs:"selector",controller:["$scope",n],template:e.get("timepicker-select.html")}}]),n.$inject=["$scope"]}),define("common/directives/time-amount-picker.directive",["common/lodash","common/modules/directives"],function(e,t){"use strict";function n(t){function n(){var e=Math.floor(c);for(d.hoursOptions=[];e<=f;)d.hoursOptions.push(e),e++}function r(){var e,t,n,r=0;for(d.minutesOptions=[];r<60;)t=+d.selectedHours===Math.floor(c)&&rf%1*60,e=t||n,!e&&d.minutesOptions.push(r),r+=u;l()}function i(){u=+t.interval||1,c=isNaN(+t.minAmount)?0:+t.minAmount,f=isNaN(+t.maxAmount)?24:+t.maxAmount,n(),r()}function o(){""!==d.selectedHours&&""!==d.selectedMinutes&&(t.value=+d.selectedHours+d.selectedMinutes/60)}function a(){t.$watch("disabled",function(e){d.disabled=e}),t.$watch("value",function(){s()}),t.$watchGroup(["minAmount","maxAmount","interval"],function(){i()})}function s(){void 0!==t.value&&(d.selectedHours=""+Math.floor(t.value),d.selectedMinutes=""+Math.floor(t.value%1*60)),o()}function l(){d.selectedMinutese.last(d.minutesOptions)&&(d.selectedMinutes=""+e.last(d.minutesOptions))}var u,c,f,d=this;d.hoursOptions=[],d.minutesOptions=[],d.selectedHours="",d.selectedMinutes="",d.buildMinutesOptions=r,d.calculateSelectedValue=o,function(){s(),a()}()}t.directive("timeAmountPicker",["$templateCache",function(e){return{scope:{minAmount:".75?Math.floor(.25*Math.ceil(e/.25))+"h":"",n=e%1&&e%1<=.75&&e%1>0?.25*Math.ceil(e%1/.25)*60+"m":"",r+t+(t&&n?" ":"")+n)}};return function(t,n){var r=void 0===t?0:parseFloat(t);if(isNaN(r))throw new Error("Value must be a number or a numeric string: "+t);return e[n](r)}})}),define("common/bundles/filters",["common/filters/time-unit-applier.filter"],function(){}),define("common/decorators/angular-date/datepicker-popup",["common/lodash"],function(e){return["$delegate","HR_settings",function(t,n){"use strict";var r=t[0].link;return t[0].compile=function(){return function(t,i,o,a){o.uibDatepickerPopup=o.uibDatepickerPopup||n.DATE_FORMAT||"yyyy-MM-dd",o.showButtonBar=o.showButtonBar||!1,t.datepickerOptions=e.assign({formatDayHeader:"E",showWeeks:!1,startingDay:1},t.datepickerOptions),r.apply(this,arguments)}},t}] -}),define("common/decorators/angular-date/date-filter",[],function(){"use strict";return["$delegate",function(e){var t=e;return function(){if("E"===arguments[1]){var e=Array.prototype.slice.call(arguments);return e[1]="EEE",t.apply(this,e)[0]}return t.apply(this,arguments)}}]}),function(e){define("common/modules/angular-date",["common/angular","common/decorators/angular-date/datepicker-popup","common/decorators/angular-date/date-filter","common/modules/services","common/angularBootstrap","common/modules/templates"],function(t,n,r){"use strict";function i(t){var n="uib/template/datepicker/"+t+".html",r=o.get(n);r=r.replace(/glyphicon glyphicon-chevron-(left|right)/gm,"fa fa-chevron-$1"),"day"===t&&(r=function(t){return e(t).find('th[ng-if="showWeeks"]').parent().css({"border-top":"1px solid #DDD"}),e(t).prop("outerHTML")}(e.parseHTML(r))),o.put(n,r)}var o;return t.module("common.angularDate",["common.services","ui.bootstrap","common.templates"]).config(["$provide",function(e){e.decorator("uibDatepickerPopupDirective",n),e.decorator("dateFilter",r)}]).run(["$templateCache",function(e){o=e,["day","month","year"].forEach(i)}])})}(CRM.$),define("common/services/angular-date/date-format",["common/angular","common/modules/angular-date","common/services/hr-settings"],function(e,t){"use strict";t.factory("DateFormat",["$q","HR_settings",function(e,t){return{dateFormat:null,getDateFormat:function(){return this.dateFormat?e.when(this.dateFormat):e.when("dd/MM/yyyy").catch(function(){return"yyyy-MM-dd"}).then(function(e){return t.DATE_FORMAT=e,this.dateFormat=e,e}.bind(this))}}}])}),define("common/filters/angular-date/format-date",["common/moment","common/modules/angular-date","common/services/hr-settings"],function(e,t){"use strict";t.filter("formatDate",["HR_settings",function(t){var n=["DD-MM-YYYY","DD-MM-YYYY HH:mm:ss","YYYY-MM-DD","YYYY-MM-DD HH:mm:ss","DD/MM/YYYY","x","YYYY-MM-DD HH:mm:ss"];return function(r,i,o){var a,s=i||t.DATE_FORMAT||"YYYY-MM-DD",l=e(0);return r instanceof Date&&(r=e(r).format("YYYY-MM-DD HH:mm:ss")),a=e(r,n,!0),a.isValid()&&!a.isSame(l)?i===Date?a.toDate():a.format(s.toUpperCase())+("hours"===o?" "+a.format("HH:mm"):""):"Unspecified"}}])}),define("common/directives/angular-date/date-input",["common/modules/angular-date","common/filters/angular-date/format-date"],function(e){"use strict";e.directive("dateInput",["$filter",function(e){return{require:"ngModel",link:function(t,n,r,i){function o(t){var n=e("formatDate")(t);return n="Unspecified"==n?"":n}i.$formatters.push(o),i.$parsers=[]}}}])}),define("common/bundles/angular-date",["common/services/angular-date/date-format","common/filters/angular-date/format-date","common/directives/angular-date/date-input"],function(){}),define("common/modules/routers/compu-ng-route",["common/angular","common/angularRoute"],function(e){"use strict";return e.module("compuNgRoute",["ngRoute"]).config(["$routeProvider",function(t){var n=t.when;t.resolveForAll=function(e){return t.commonResolve=e,t},t.when=function(r,i){return e.extend(i.resolve||{},t.commonResolve||{}),n.call(t,r,i)}}])}),"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function r(e,t){return L(new(L(function(){},{prototype:e})),t)}function i(e){return j(arguments,function(t){t!==e&&j(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var r in e.path){if(e.path[r]!==t.path[r])break;n.push(e.path[r])}return n}function a(e){if(Object.keys)return Object.keys(e);var t=[];return j(e,function(e,n){t.push(n)}),t}function s(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,r=Number(arguments[2])||0;for(0>(r=0>r?Math.ceil(r):Math.floor(r))&&(r+=n);n>r;r++)if(r in e&&e[r]===t)return r;return-1}function l(e,t,n,r){var i,l=o(n,r),u={},c=[];for(var f in l)if(l[f].params&&(i=a(l[f].params),i.length))for(var d in i)s(c,i[d])>=0||(c.push(i[d]),u[i[d]]=e[i[d]]);return L({},u,t)}function u(e,t,n){if(!n){n=[];for(var r in e)n.push(r)}for(var i=0;i "));if(y[n]=r,I(e))g.push(n,[function(){return t.get(e)}],u);else{var i=t.annotate(e);j(i,function(e){e!==n&&l.hasOwnProperty(e)&&p(l[e],e)}),g.push(n,e,i)}v.pop(),y[n]=o}}function h(e){return P(e)&&e.then&&e.$$promises}if(!P(l))throw new Error("'invocables' must be an object");var m=a(l||{}),g=[],v=[],y={};return j(l,p),l=v=y=null,function(r,o,a){function s(){--b||($||i(y,o.$$values),p.$$values=y,p.$$promises=p.$$promises||!0,delete p.$$inheritedValues,u.resolve(y))}function l(e){p.$$failure=e,u.reject(e)}if(h(r)&&a===n&&(a=o,o=r,r=null),r){if(!P(r))throw new Error("'locals' must be an object")}else r=c;if(o){if(!h(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=f;var u=e.defer(),p=u.promise,v=p.$$promises={},y=L({},r),b=1+g.length/3,$=!1;if(N(o.$$failure))return l(o.$$failure),p;o.$$inheritedValues&&i(y,d(o.$$inheritedValues,m)),L(v,o.$$promises),o.$$values?($=i(y,d(o.$$values,m)),p.$$inheritedValues=d(o.$$values,m),s()):(o.$$inheritedValues&&(p.$$inheritedValues=d(o.$$inheritedValues,m)),o.then(s,l));for(var w=0,x=g.length;x>w;w+=3)r.hasOwnProperty(g[w])?s():function(n,i,o){function u(e){f.reject(e),l(e)}function c(){if(!N(p.$$failure))try{f.resolve(t.invoke(i,a,y)),f.promise.then(function(e){y[n]=e,s()},u)}catch(e){u(e)}}var f=e.defer(),d=0;j(o,function(e){v.hasOwnProperty(e)&&!r.hasOwnProperty(e)&&(d++,v[e].then(function(t){y[e]=t,--d||c()},u))}),d||c(),v[n]=f.promise}(g[w],g[w+1],g[w+2]);return p}},this.resolve=function(e,t,n,r){return this.study(e)(t,n,r)}}function g(e,t,n){this.fromConfig=function(e,t,n){return N(e.template)?this.fromString(e.template,t):N(e.templateUrl)?this.fromUrl(e.templateUrl,t):N(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return R(e)?e(t):e},this.fromUrl=function(n,r){return R(n)&&(n=n(r)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,r){return n.invoke(e,null,r||{params:t})}}function v(e,t,i){function o(t,n,r,i){if(g.push(t),h[t])return h[t];if(!/^\w+(-+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(m[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return m[t]=new H.Param(t,n,r,i),m[t]}function a(e,t,n,r){var i=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:i=["(",")"+(r?"?":"")];break;case!0:i=["?(",")?"];break;default:i=["("+n+"|",")?"]}return o+i[0]+t+i[1]}function s(i,o){var a,s,l,u,c;return a=i[2]||i[3],c=t.params[a],l=e.substring(d,i.index),s=o?i[4]:i[4]||("*"==i[1]?".*":null),u=H.type(s||"string")||r(H.type("string"),{pattern:new RegExp(s,t.caseInsensitive?"i":n)}),{id:a,regexp:s,segment:l,type:u,cfg:c}}t=L({params:{}},P(t)?t:{});var l,u=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,c=/([:]?)([\w\[\]-]+)|\{([\w\[\]-]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,f="^",d=0,p=this.segments=[],h=i?i.params:{},m=this.params=i?i.params.$$new():new H.ParamSet,g=[];this.source=e;for(var v,y,b;(l=u.exec(e))&&(v=s(l,!1),!(v.segment.indexOf("?")>=0));)y=o(v.id,v.type,v.cfg,"path"),f+=a(v.segment,y.type.pattern.source,y.squash,y.isOptional),p.push(v.segment),d=u.lastIndex;b=e.substring(d);var $=b.indexOf("?");if($>=0){var w=this.sourceSearch=b.substring($);if(b=b.substring(0,$),this.sourcePath=e.substring(0,d+$),w.length>0)for(d=0;l=c.exec(w);)v=s(l,!0),y=o(v.id,v.type,v.cfg,"search"),d=u.lastIndex}else this.sourcePath=e,this.sourceSearch="";f+=a(b)+(!1===t.strict?"/?":"")+"$",p.push(b),this.regexp=new RegExp(f,t.caseInsensitive?"i":n),this.prefix=p[0],this.$$paramNames=g}function y(e){L(this,e)}function b(){function e(e){return null!=e?e.toString().replace(/\//g,"%2F"):e}function i(e){return null!=e?e.toString().replace(/%2F/g,"/"):e}function o(){return{strict:m,caseInsensitive:d}}function l(e){return R(e)||F(e)&&R(e[e.length-1])}function u(){for(;x.length;){var e=x.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend($[e.name],f.invoke(e.def))}}function c(e){L(this,e||{})}H=this;var f,d=!1,m=!0,g=!1,$={},w=!0,x=[],C={string:{encode:e,decode:i,is:function(e){return null==e||!N(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return N(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};b.$$getDefaultValue=function(e){if(!l(e.value))return e.value;if(!f)throw new Error("Injectable functions cannot be called at configuration time");return f.invoke(e.value)},this.caseInsensitive=function(e){return N(e)&&(d=e),d},this.strictMode=function(e){return N(e)&&(m=e),m},this.defaultSquashPolicy=function(e){if(!N(e))return g;if(!0!==e&&!1!==e&&!I(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return g=e,e},this.compile=function(e,t){return new v(e,L(o(),t))},this.isMatcher=function(e){if(!P(e))return!1;var t=!0;return j(v.prototype,function(n,r){R(n)&&(t=t&&N(e[r])&&R(e[r]))}),t},this.type=function(e,t,n){if(!N(t))return $[e];if($.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return $[e]=new y(L({name:e},t)),n&&(x.push({name:e,def:n}),w||u()),this},j(C,function(e,t){$[t]=new y(L({name:t},e))}),$=r($,{}),this.$get=["$injector",function(e){return f=e,w=!1,u(),j(C,function(e,t){$[t]||($[t]=new y(e))}),this}],this.Param=function(e,t,r,i){function o(){if(!f)throw new Error("Injectable functions cannot be called at configuration time");var e=f.invoke(r.$$fn);if(null!==e&&e!==n&&!d.type.is(e))throw new Error("Default value ("+e+") for parameter '"+d.id+"' is not an instance of Type ("+d.type.name+")");return e}function u(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=h(p(d.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),N(e)?d.type.$normalize(e):o()}function c(){return"{Param:"+e+" "+t+" squash: '"+b+"' optional: "+v+"}"}var d=this;r=function(e){var t=P(e)?a(e):[];return-1===s(t,"value")&&-1===s(t,"type")&&-1===s(t,"squash")&&-1===s(t,"array")&&(e={value:e}),e.$$fn=l(e.value)?e.value:function(){return e.value},e}(r),t=function(t,n,r){if(t.type&&n)throw new Error("Param '"+e+"' has two type configurations.");return n||(t.type?t.type instanceof y?t.type:new y(t.type):"config"===r?$.any:$.string)}(r,t,i);var m=function(){var t={array:"search"===i&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return L(t,n,r).array}();t=m?t.$asArray(m,"search"===i):t,"string"!==t.name||m||"path"!==i||r.value!==n||(r.value="");var v=r.value!==n,b=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!N(n)||null==n)return g;if(!0===n||I(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,v),w=function(e,t,r,i){var o,a,l=[{from:"",to:r||t?n:""},{from:null,to:r||t?n:""}];return o=F(e.replace)?e.replace:[],I(i)&&o.push({from:i,to:n}),a=h(o,function(e){return e.from}),p(l,function(e){return-1===s(a,e.from)}).concat(o)}(r,m,v,b);L(this,{id:e,type:t,location:i,array:m,squash:b,replace:w,isOptional:v,value:u,dynamic:n,config:r,toString:c})},c.prototype={$$new:function(){return r(this,L(new c,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,r=a(c.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),j(t,function(t){j(a(t),function(t){-1===s(e,t)&&-1===s(r,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return j(n.$$keys(),function(r){t[r]=n[r].value(e&&e[r])}),t},$$equals:function(e,t){var n=!0,r=this;return j(r.$$keys(),function(i){var o=e&&e[i],a=t&&t[i];r[i].type.equals(o,a)||(n=!1)}),n},$$validates:function(e){var r,i,o,a,s,l=this.$$keys();for(r=0;ri;i++)if(t(u[i]))return;c&&t(c)}}function p(){return l=l||i.$on("$locationChangeSuccess",d)}var h,m=a.baseHref(),g=r.url();return f||p(),{sync:function(){d()},listen:function(){return p()},update:function(e){return e?void(g=r.url()):void(r.url()!==g&&(r.url(g),r.replace()))},push:function(e,t,i){var o=e.format(t||{});null!==o&&t&&t["#"]&&(o+="#"+t["#"]),r.url(o),h=i&&i.$$avoidResync?r.url():n,i&&i.replace&&r.replace()},href:function(n,i,o){if(!n.validates(i))return null;var a=e.html5Mode();t.isObject(a)&&(a=a.enabled);var l=n.format(i);if(o=o||{},a||null===l||(l="#"+e.hashPrefix()+l),null!==l&&i&&i["#"]&&(l+="#"+i["#"]),l=s(l,a,o.absolute),!o.absolute||!l)return l;var u=!a&&l?"/":"",c=r.port();return c=80===c||443===c?"":":"+c,[r.protocol(),"://",r.host(),c,u,l].join("")}}}var l,u=[],c=null,f=!1;this.rule=function(e){if(!R(e))throw new Error("'rule' must be a function");return u.push(e),this},this.otherwise=function(e){if(I(e)){var t=e;e=function(){return t}}else if(!R(e))throw new Error("'rule' must be a function");return c=e,this},this.when=function(e,t){var n,s=I(t);if(I(e)&&(e=r.compile(e)),!s&&!R(t)&&!F(t))throw new Error("invalid 'handler' in when()");var l={matcher:function(e,t){return s&&(n=r.compile(t),t=["$match",function(e){return n.format(e)}]),L(function(n,r){return a(n,t,e.exec(r.path(),r.search()))},{prefix:I(e.prefix)?e.prefix:""})},regex:function(e,t){if(e.global||e.sticky)throw new Error("when() RegExp must not be global or sticky");return s&&(n=t,t=["$match",function(e){return o(n,e)}]),L(function(n,r){return a(n,t,e.exec(r.path()))},{prefix:i(e)})}},u={matcher:r.isMatcher(e),regex:e instanceof RegExp};for(var c in u)if(u[c])return this.rule(l[c](e,t));throw new Error("invalid 'what' in when()")},this.deferIntercept=function(e){e===n&&(e=!0),f=e},this.$get=s,s.$inject=["$location","$rootScope","$injector","$browser"]}function w(e,i){function o(e){return 0===e.indexOf(".")||0===e.indexOf("^")}function d(e,t){if(!e)return n;var r=I(e),i=r?e:e.name;if(o(i)){if(!t)throw new Error("No reference point given for path '"+i+"'");t=d(t);for(var a=i.split("."),s=0,l=a.length,u=t;l>s;s++)if(""!==a[s]||0!==s){if("^"!==a[s])break;if(!u.parent)throw new Error("Path '"+i+"' not valid for state '"+t.name+"'");u=u.parent}else u=t;a=a.slice(s).join("."),i=u.name+(u.name&&a?".":"")+a}var c=E[i];return!c||!r&&(r||c!==e&&c.self!==e)?n:c}function p(e,t){S[e]||(S[e]=[]),S[e].push(t)}function m(e){for(var t=S[e]||[];t.length;)g(t.shift())}function g(t){t=r(t,{self:t,resolve:t.resolve||{},toString:function(){return this.name}});var n=t.name;if(!I(n)||n.indexOf("@")>=0)throw new Error("State must have a valid name");if(E.hasOwnProperty(n))throw new Error("State '"+n+"'' is already defined");var i=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):I(t.parent)?t.parent:P(t.parent)&&I(t.parent.name)?t.parent.name:"";if(i&&!E[i])return p(i,t.self);for(var o in M)R(M[o])&&(t[o]=M[o](t,M.$delegates[o]));return E[n]=t,!t[_]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){k.$current.navigable==t&&u(e,n)||k.transitionTo(t,e,{inherit:!0,location:!1})}]),m(n),t}function v(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=k.$current.name.split("."),r=0,i=t.length;i>r;r++)"*"===t[r]&&(n[r]="*");return"**"===t[0]&&(n=n.slice(s(n,t[1])),n.unshift("**")),"**"===t[t.length-1]&&(n.splice(s(n,t[t.length-2])+1,Number.MAX_VALUE),n.push("**")),t.length==n.length&&n.join("")===t.join("")}function b(e,t){return I(e)&&!N(t)?M[e]:R(t)&&I(e)?(M[e]&&!M.$delegates[e]&&(M.$delegates[e]=M[e]),M[e]=t,this):this}function $(e,t){return P(e)?t=e:t.name=e,g(t),this}function w(e,i,o,s,f,p,m,g,b){function $(t,n,r,o){var a=e.$broadcast("$stateNotFound",t,n,r);if(a.defaultPrevented)return m.update(),T;if(!a.retry)return null;if(o.$retry)return m.update(),D;var s=k.transition=i.when(a.retry);return s.then(function(){return s!==k.transition?S:(t.options.$retry=!0,k.transitionTo(t.to,t.toParams,t.options))},function(){return T}),m.update(),s}function w(e,n,r,a,l,u){function d(){var n=[];return j(e.views,function(r,i){var a=r.resolve&&r.resolve!==e.resolve?r.resolve:{};a.$template=[function(){return o.load(i,{view:r,locals:l.globals,params:p,notify:u.notify})||""}],n.push(f.resolve(a,l.globals,l.resolve,e).then(function(n){if(R(r.controllerProvider)||F(r.controllerProvider)){var o=t.extend({},a,l.globals);n.$$controller=s.invoke(r.controllerProvider,null,o)}else n.$$controller=r.controller;n.$$state=e,n.$$controllerAs=r.controllerAs,l[i]=n}))}),i.all(n).then(function(){return l.globals})}var p=r?n:c(e.params.$$keys(),n),h={$stateParams:p};l.resolve=f.resolve(e.resolve,h,l.resolve,e);var m=[l.resolve.then(function(e){l.globals=e})];return a&&m.push(a),i.all(m).then(d).then(function(e){return l})}var S=i.reject(new Error("transition superseded")),M=i.reject(new Error("transition prevented")),T=i.reject(new Error("transition aborted")),D=i.reject(new Error("transition failed"));return C.locals={resolve:null,globals:{$stateParams:{}}},k={params:{},current:C.self,$current:C,transition:null},k.reload=function(e){return k.transitionTo(k.current,p,{reload:e||!0,inherit:!1,notify:!0})},k.go=function(e,t,n){return k.transitionTo(e,t,L({inherit:!0,relative:k.$current},n))},k.transitionTo=function(t,n,o){n=n||{},o=L({location:!0,inherit:!1,relative:null,notify:!0,reload:!1,$retry:!1},o||{});var a,u=k.$current,f=k.params,h=u.path,g=d(t,o.relative),v=n["#"];if(!N(g)){var y={to:t,toParams:n,options:o},b=$(y,u.self,f,o);if(b)return b;if(t=y.to,n=y.toParams,o=y.options,g=d(t,o.relative),!N(g)){if(!o.relative)throw new Error("No such state '"+t+"'");throw new Error("Could not resolve '"+t+"' from state '"+o.relative+"'")}}if(g[_])throw new Error("Cannot transition to abstract state '"+t+"'");if(o.inherit&&(n=l(p,n||{},k.$current,g)),!g.params.$$validates(n))return D;n=g.params.$$values(n),t=g;var E=t.path,T=0,A=E[T],O=C.locals,R=[];if(o.reload){if(I(o.reload)||P(o.reload)){if(P(o.reload)&&!o.reload.name)throw new Error("Invalid reload state object");var F=!0===o.reload?h[0]:d(o.reload);if(o.reload&&!F)throw new Error("No such reload state '"+(I(o.reload)?o.reload:o.reload.name)+"'");for(;A&&A===h[T]&&A!==F;)O=R[T]=A.locals,T++,A=E[T]}}else for(;A&&A===h[T]&&A.ownParams.$$equals(n,f);)O=R[T]=A.locals,T++,A=E[T];if(x(t,n,u,f,O,o))return v&&(n["#"]=v),k.params=n,U(k.params,p),o.location&&t.navigable&&t.navigable.url&&(m.push(t.navigable.url,n,{$$avoidResync:!0,replace:"replace"===o.location}),m.update(!0)),k.transition=null,i.when(k.current);if(n=c(t.params.$$keys(),n||{}),o.notify&&e.$broadcast("$stateChangeStart",t.self,n,u.self,f).defaultPrevented)return e.$broadcast("$stateChangeCancel",t.self,n,u.self,f),m.update(),M;for(var j=i.when(O),H=T;H=T;r--)a=h[r],a.self.onExit&&s.invoke(a.self.onExit,a.self,a.locals.globals),a.locals=null;for(r=T;r=0?i:i+"@"+(o?o.state.name:"")}function _(e,t){var n,r=e.match(/^\s*({[^}]*})\s*$/);if(r&&(e=t+"("+r[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function M(e){var t=e.parent().inheritedData("$uiView");return t&&t.state&&t.state.name?t.state:void 0}function T(e,n){var r=["location","inherit","reload","absolute"];return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(i,o,a,s){var l=_(a.uiSref,e.current.name),u=null,c=M(o)||e.$current,f="[object SVGAnimatedString]"===Object.prototype.toString.call(o.prop("href"))?"xlink:href":"href",d=null,p="A"===o.prop("tagName").toUpperCase(),h="FORM"===o[0].nodeName,m=h?"action":f,g=!0,v={relative:c,inherit:!0},y=i.$eval(a.uiSrefOpts)||{};t.forEach(r,function(e){e in y&&(v[e]=y[e])});var b=function(n){if(n&&(u=t.copy(n)),g){d=e.href(l.state,u,v);var r=s[1]||s[0];return r&&r.$$addStateInfo(l.state,u),null===d?(g=!1,!1):void a.$set(m,d)}};l.paramExpr&&(i.$watch(l.paramExpr,function(e,t){e!==u&&b(e)},!0),u=t.copy(i.$eval(l.paramExpr))),b(),h||o.bind("click",function(t){if(!((t.which||t.button)>1||t.ctrlKey||t.metaKey||t.shiftKey||o.attr("target"))){var r=n(function(){e.go(l.state,u,v)});t.preventDefault();var i=p&&!d?1:0;t.preventDefault=function(){i--<=0&&n.cancel(r)}}})}}}function D(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs",function(t,r,i){function o(){a()?r.addClass(l):r.removeClass(l)}function a(){for(var e=0;er;r++){o=a[r];var c=this.params[o],f=n[r+1];for(i=0;ir;r++)o=a[r],u[o]=this.params[o].value(t[o]);return u},v.prototype.parameters=function(e){return N(e)?this.params[e]||null:this.$$paramNames},v.prototype.validates=function(e){return this.params.$$validates(e)},v.prototype.format=function(e){function t(e){return encodeURIComponent(e).replace(/-/g,function(e){return"%5C%"+e.charCodeAt(0).toString(16).toUpperCase()})}e=e||{};var n=this.segments,r=this.parameters(),i=this.params;if(!this.validates(e))return null;var o,a=!1,s=n.length-1,l=r.length,u=n[0];for(o=0;l>o;o++){var c=s>o,f=r[o],d=i[f],p=d.value(e[f]),m=d.isOptional&&d.type.equals(d.value(),p),g=!!m&&d.squash,v=d.type.encode(p);if(c){var y=n[o+1];if(!1===g)null!=v&&(u+=F(v)?h(v,t).join("-"):encodeURIComponent(v)),u+=y;else if(!0===g){var b=u.match(/\/$/)?/\/?(.*)/:/(.*)/;u+=y.match(b)[1]}else I(g)&&(u+=g+y)}else{if(null==v||m&&!1!==g)continue;F(v)||(v=[v]),v=h(v,encodeURIComponent).join("&"+f+"="),u+=(a?"&":"?")+f+"="+v,a=!0}}return u},y.prototype.is=function(e,t){return!0},y.prototype.encode=function(e,t){return e},y.prototype.decode=function(e,t){return e},y.prototype.equals=function(e,t){return e==t},y.prototype.$subPattern=function(){var e=this.pattern.toString();return e.substr(1,e.length-2)},y.prototype.pattern=/.*/,y.prototype.toString=function(){return"{Type:"+this.name+"}"},y.prototype.$normalize=function(e){return this.is(e)?e:this.decode(e)},y.prototype.$asArray=function(e,t){function r(e,t){function r(e,t){return function(){return e[t].apply(e,arguments)}}function i(e){return F(e)?e:N(e)?[e]:[]}function o(e){switch(e.length){case 0:return n;case 1:return"auto"===t?e[0]:e;default:return e}}function a(e){return!e}function s(e,t){return function(n){n=i(n);var r=h(n,e);return!0===t?0===p(r,a).length:o(r)}}this.encode=s(r(e,"encode")),this.decode=s(r(e,"decode")),this.is=s(r(e,"is"),!0),this.equals=function(e){return function(t,n){var r=i(t),o=i(n);if(r.length!==o.length)return!1;for(var a=0;a=":n(e.from)}:{"<=":n(e.to)}}function o(e){return e.in?{IN:e.in}:{"NOT IN":e.nin}}return{extend:function(t){return e.assign(Object.create(this),t)},compactFilters:function(t){return t?e.pick(t,function(e){return 0===e||!1===e||!!e}):null},processFilters:function(t){return t?(t=this.compactFilters(t),e.transform(t,function(e,t,n){t.from||t.to?e[n]=i(t):t.in||t.nin?e[n]=o(t):e[n]=t},{})):null}}})}),define("common/models/contact-job-role.model",["common/modules/models","common/models/model","common/instances/contact-job-role-instance.instance","common/services/api/contact-job-role-api.api"],function(e){"use strict";e.factory("ContactJobRole",["$log","Model","ContactJobRoleAPI","ContactJobRoleInstance",function(e,t,n,r){return e.debug("ContactJobRole"),t.extend({all:function(e){return n.all(e).then(function(e){return e.list.map(function(e){return r.init(e,!0)})})}})}])}),define("common/models/instances/group-instance",["common/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("GroupInstance",["ModelInstance",function(e){var t=["id","name","title","description"];return e.extend({fromAPIFilter:function(e,n,r){_.includes(t,r)&&(e[r]=this[r])}})}])}),define("common/mocks/module",["common/angular"],function(e){"use strict";return e.module("common.mocks",[])}),define("common/mocks/services/api/group-mock",["common/lodash","common/mocks/module"],function(e,t){"use strict";t.factory("api.group.mock",["$q",function(t){function n(e){var n=t.defer();return n.resolve(e),n.promise}return{all:function(e,t,r){var i,o,a;return i=r||this.mockedGroups().list,e&&(i=i.filter(function(t){return Object.keys(e).every(function(n){return t[n]===e[n]})})),t&&(o=(t.page-1)*t.size,a=o+t.size,i=i.slice(o,a)),n({list:i,total:i.length,allIds:i.map(function(e){return e.id}).join(",")})},find:function(e,t){return n(t||this.mockedGroups().list.filter(function(t){return t.id===e})[0])},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedGroups:function(){return{total:5,list:[{id:"1",name:"Administrators",title:"Administrators",description:"Contacts in this group are assigned Administrator role permissions.",is_active:"1",visibility:"User and User Admin Only",group_type:["1"],is_hidden:"0",is_reserved:"0"},{id:"2",name:"Newsletter Subscribers",title:"Newsletter Subscribers",is_active:'"1',visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"3",name:"Summer Program Volunteers",title:"Summer Program Volunteers",is_active:"1",visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"4",name:"Advisory Board",title:"Advisory Board",is_active:"1",visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"5",name:"Case_Resources",title:"Case Resources",description:"Contacts in this group are listed with their phone number and email when viewing case. You also can send copies of case activities to these contacts.",is_active:"1",visibility:"User and User Admin Only",where_clause:"...",select_tables:"...",where_tables:"...",group_type:"2",is_hidden:"0",is_reserved:"0"}]}}}}])}),define("common/mocks/data/contact.data",[],function(){return{all:{is_error:0,version:3,count:26,values:[{id:"1",contact_id:"1",display_name:"Dr. Kiara Jensen-Parker",email:"kh.jensen-parker@testing.info",contact_type:"Individual"},{id:"2",contact_id:"2",display_name:"jacobc82@lol.co.pl",email:"cruz.v.jacob@spamalot.com",contact_type:"Individual"},{id:"3",contact_id:"3",display_name:"Mei Müller-Nielsen",email:"mz.mller-nielsen75@infomail.co.pl",contact_type:"Individual"},{id:"4",contact_id:"4",display_name:"Ms. Brigette Deforest",email:"deforest.p.brigette9@fakemail.info",contact_type:"Individual"},{id:"5",contact_id:"5",display_name:"robertsc@testing.net",email:"clintr56@mymail.org",contact_type:"Individual"},{id:"6",contact_id:"6",display_name:"Dr. Allen Samuels Sr.",email:"samuelsa@mymail.org",contact_type:"Individual"},{id:"7",contact_id:"7",display_name:"Mei Wilson",email:"wilson.u.mei59@sample.org",contact_type:"Individual"},{id:"8",contact_id:"8",display_name:"Dr. Betty Díaz",email:"dazb@sample.co.nz",contact_type:"Individual"},{id:"9",contact_id:"9",display_name:"Bob Jones-Dimitrov",email:"bobj@testmail.biz",contact_type:"Individual"},{id:"10",contact_id:"10",display_name:"Truman Samuels III",email:"trumans@spamalot.org",contact_type:"Individual"},{id:"11",contact_id:"11",display_name:"Iris Wagner",email:"iwagner75@notmail.info",contact_type:"Individual"},{id:"12",contact_id:"12",display_name:"Mr. Rosario McReynolds",email:"rosariomcreynolds@testmail.org",contact_type:"Individual"},{id:"13",contact_id:"13",display_name:"Shad Jones-Dimitrov III",email:"shadj@lol.net",contact_type:"Individual"},{id:"14",contact_id:"14",display_name:"Toby Cruz Sr.",email:"",contact_type:"Individual"},{id:"15",contact_id:"15",display_name:"lareedaz61@testing.com",email:"lareedaz61@testing.com",contact_type:"Individual"},{id:"16",contact_id:"16",display_name:"Dr. Jay Deforest",email:"jayd@fishmail.org",contact_type:"Individual"},{id:"17",contact_id:"17",display_name:"Mr. Norris Cruz",email:"norriscruz@spamalot.info",contact_type:"Individual"},{id:"18",contact_id:"18",display_name:"herminiac@fishmail.com",email:"herminiac@fishmail.com",contact_type:"Individual"},{id:"19",contact_id:"19",display_name:"Ashley Terrell",email:"terrell.ashley@testmail.info",contact_type:"Individual"},{id:"20",contact_id:"20",display_name:"Kandace Parker-Díaz",email:"parker-daz.kandace67@fishmail.co.uk",contact_type:"Individual"},{id:"21",contact_id:"21",display_name:"Nicole Samuels",email:"ng.samuels@testmail.net",contact_type:"Individual"},{id:"22",contact_id:"22",display_name:"Dr. Kandace Wattson",email:"kandacewattson@testing.info",contact_type:"Individual"},{id:"23",contact_id:"23",display_name:"Brittney Cruz",email:"cruz.brittney@spamalot.co.nz",contact_type:"Individual"},{id:"24",contact_id:"24",display_name:"Shauna Olsen",email:"",contact_type:"Individual"},{id:"202",contact_id:"202",display_name:"civihr_staff@compucorp.co.uk",email:"civihr_staff@compucorp.co.uk",contact_type:"Individual"},{id:"203",contact_id:"203",display_name:"civihr_manager@compucorp.co.uk",email:"civihr_manager@compucorp.co.uk",contact_type:"Individual"}]}}}),define("common/mocks/services/api/contact-mock",["common/lodash","common/mocks/module","common/mocks/data/contact.data"],function(e,t,n){"use strict";t.factory("api.contact.mock",["$q",function(t){function r(e){var n=t.defer();return n.resolve(e),n.promise}return{all:function(t,i,o,a,s){var l,u,c;return l=s||n.all.values,t&&(l=l.filter(function(n){return Object.keys(t).every(function(r){return null===t[r]||("display_name"===r?new RegExp(t[r],"i").test(n[r]):t[r].IN?e.includes(t[r].IN,n[r]):n[r]===t[r])})})),i&&(u=(i.page-1)*i.size,c=u+i.size,l=l.slice(u,c)),r({list:l,total:l.length,allIds:l.map(function(e){return e.id}).join(",")})},find:function(e,t){return r(t||n.all.values.filter(function(t){return t.id===e})[0])},leaveManagees:function(){return r(this.mockedContacts().list)},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedContacts:function(){var e=n.all.values;return{total:e.length,list:e.map(function(e){return e})}}}}])}),define("common/mocks/services/api/group-contact-mock",["common/lodash","common/mocks/module","common/mocks/services/api/contact-mock","common/mocks/services/api/group-mock"],function(e,t){"use strict";t.factory("api.group-contact.mock",["$q","api.contact.mock","api.group.mock",function(t,n,r){function i(t){return e.sample(t)}function o(e){var n=t.defer();return n.resolve(e),n.promise}var a=n.mockedContacts().list,s=r.mockedGroups().list;return{all:function(e,t,n){var r,i,a;return r=n||this.mockedGroupsContacts.list,e&&(r=r.filter(function(t){return Object.keys(e).every(function(n){return t[n]===e[n]})})),t&&(i=(t.page-1)*t.size,a=i+t.size,r=r.slice(i,a)),o({list:r,total:r.length,allIds:r.map(function(e){return e.id}).join(",")})},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedGroupsContacts:{total:a.length,list:function(){var e=1;return a.map(function(t){return{id:""+e++,group_id:i(s).id,contact_id:t.id,status:"Added"}})}()}}}])}),define("common/models/group",["common/modules/models","common/models/model","common/models/instances/group-instance","common/mocks/services/api/group-mock","common/mocks/services/api/group-contact-mock"],function(e){"use strict";e.factory("Group",["Model","api.group.mock","api.group-contact.mock","GroupInstance",function(e,t,n,r){return e.extend({all:function(e,n){return t.all(this.processFilters(e),n).then(function(e){return e.list=e.list.map(function(e){return r.init(e,!0)}),e})},find:function(e){return t.find(e).then(function(e){return r.init(e,!0)})},contactIdsOf:function(e){return n.all({group_id:e}).then(function(e){return e.list.map(function(e){return e.contact_id})})}})}])}),define("common/models/instances/job-role-instance",["common/lodash","common/moment","common/modules/models-instances","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("JobRoleInstance",["ModelInstance","HR_settings",function(n,r){return n.extend({fromAPIFilter:function(n,i,o){var a=r.DATE_FORMAT.toUpperCase();e.endsWith(o,"_date")?n[o]=t(this[o],"YYYY-MM-DD HH:mm:ss").format(a):"api.HRJobContract.getsingle"===o?(n.contact_id=this[o].contact_id,n.job_contract_id=this[o].id):n[o]=this[o]},toAPIFilter:function(n,i,o){var a=["contact_id","job_contract_id"],s=r.DATE_FORMAT.toUpperCase();if(e.endsWith(o,"_date"))n[o]=t(this[o],s).format("YYYY-MM-DD HH:mm:ss");else{if(e.includes(a,o))return;n[o]=this[o]}}})}])}),define("common/services/api/job-role",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.job-role",["$log","api",function(e,t){return e.debug("api.jobRole"),t.extend({all:function(t,n,r,i){return e.debug("api.jobRole.api"),this.getAll("HrJobRoles",t,n,r,i)},find:function(t){return e.debug("api.jobRole.find"),this.sendGET("HRJobRole","get",{id:""+t},!1).then(function(e){return e.values[0]})}})}])}),define("common/models/job-role",["common/modules/models","common/models/model","common/models/instances/job-role-instance","common/services/api/job-role"],function(e){"use strict";e.factory("JobRole",["Model","api.job-role","JobRoleInstance",function(e,t,n){return e.extend({all:function(e,r){return t.all(this.processFilters(e),r).then(function(e){return e.list=e.list.map(function(e){return n.init(e,!0)}),e})},find:function(e){return t.find(e).then(function(e){return n.init(e,!0)})}})}])}),define("common/services/api/contact",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.contact",["$log","api",function(e,t){return e.debug("api.contact"),t.extend({all:function(t,n,r,i){return e.debug("api.contact.api"),this.getAll("Contact",t,n,r,i)},find:function(t){return e.debug("api.contact.find"),this.sendGET("Contact","get",{id:""+t},!1).then(function(e){return e.values[0]})},leaveManagees:function(t,n){return e.debug("api.contact.leaveManagees"),n=_.assign({},n,{managed_by:t}),this.sendGET("Contact","getleavemanagees",n).then(function(e){return e.values})}})}])}),define("common/models/instances/contact-instance",["common/modules/models-instances","common/models/instances/instance","common/services/api/contact"],function(e){"use strict";e.factory("ContactInstance",["ModelInstance","api.contact",function(e,t){return e.extend({leaveManagees:function(e){return t.leaveManagees(this.id,e)}})}])}),define("common/models/contact",["common/lodash","common/modules/models","common/models/model","common/models/contact-job-role.model","common/models/group","common/models/job-role","common/models/instances/contact-instance","common/services/api/contact"],function(e,t){"use strict";t.factory("Contact",["$q","Model","api.contact","Group","JobRole","ContactJobRole","ContactInstance",function(t,n,r,i,o,a,s){function l(t,n){return!e.isEmpty(e.intersection(e.keys(t),n))}function u(e){return a.all(e).then(function(e){return e.map(function(e){return e.contact_id})})}function c(t,n){return e(t).omit(d).omit(p).assign({id:{in:e.intersection.apply(null,n)}}).value()}function f(n){var r=t.defer(),o=[];return n=this.compactFilters(n),l(n,p)&&o.push(u(e.pick(n,p))),l(n,d)&&o.push(i.contactIdsOf(n.group_id)),e.isEmpty(o)?r.resolve(this.processFilters(n)):t.all(o).then(function(e){n=c(n,e),r.resolve(this.processFilters(n))}.bind(this)),r.promise}var d=["group_id"],p=["region","department","level_type","location"];return n.extend({all:function(e,t,n,i){return f.call(this,e).then(function(e){return e&&e.id&&!e.id.IN.length?{list:[]}:r.all(e,t,n,i)}).then(function(e){return e.list=e.list.map(function(e){return s.init(e,!0)}),e})},find:function(e){return r.find(e).then(function(e){return s.init(e,!0)})},leaveManagees:function(e,t){return f.call(this,t).then(function(t){return t&&t.id&&!t.id.IN.length?[]:r.leaveManagees(e,t)})}})}])}),define("common/models/instances/contract-instance",["common/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("ContractInstance",["ModelInstance",function(e){return e.extend({})}])}),define("common/services/api/contract",["common/lodash","common/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("api.contract",["$log","api",function(t,n){function r(t){var n=e.clone(t);return n.info=n["api.HRJobContract.getfulldetails"],delete n["api.HRJobContract.getfulldetails"],n}return t.debug("api.contract"),n.extend({all:function(e){return t.debug("ContractAPI.all"),e=e||{},e["api.HRJobContract.getfulldetails"]={jobcontract_id:"$value.id"},e.deleted=0,this.sendGET("HRJobContract","get",e,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r)})}})}])}),define("common/models/contract",["common/modules/models","common/models/model","common/models/instances/contract-instance","common/services/api/contract"],function(e){"use strict";e.factory("Contract",["$log","Model","api.contract","ContractInstance",function(e,t,n,r){return e.debug("Contract"),t.extend({all:function(e){return n.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})}})}])}),define("common/models/option-group",["common/modules/models","common/models/model","common/services/api/option-group"],function(e){"use strict";e.factory("OptionGroup",["Model","api.optionGroup",function(e,t){return e.extend({valuesOf:function(e,n){return t.valuesOf(e,n)}})}])}),function(e,t){define("common/models/session.model",["common/modules/models","common/models/model"],function(n){"use strict";n.factory("Session",["$log","$q","Model",function(n,r,i){return n.debug("Session"),i.extend({get:function(){var n={contactId:e.vars.session?e.vars.session.contact_id:t.settings.currentCiviCRMUserId};if(!n.contactId)throw new Error("Session Error: *Logged In Contact Id* is not defined");return r.resolve(n)}})}])})}(CRM,window.Drupal),define("common/bundles/models",["common/instances/contact-job-role-instance.instance","common/models/model","common/models/contact","common/models/contact-job-role.model","common/models/contract","common/models/group","common/models/job-role","common/models/option-group","common/models/session.model","common/models/instances/instance","common/models/instances/contact-instance","common/models/instances/contract-instance","common/models/instances/group-instance","common/models/instances/job-role-instance"],function(){}),define("common/services/dialog/dialog",["common/lodash","common/modules/services"],function(e,t){"use strict";function n(t,n,r){function i(i){var o;if(!e.isObject(i))throw new Error("Dialog Service: Options passed should be an object");return o=n.children(),t.open({appendTo:o.length?o.eq(0):n,size:"sm",controller:"DialogController",template:r.get("dialog.html"),resolve:{options:function(){return i}}}).result}return{open:i}}t.factory("dialog",n),n.$inject=["$uibModal","$rootElement","$templateCache"]}),define("common/controllers/dialog/dialog-ctrl",["common/lodash","common/modules/controllers"],function(e,t){"use strict";function n(t,n,r,i){function o(t){e.assign(n,e.defaultsDeep(t,{title:"CiviHR",msg:"",copyConfirm:"",copyCancel:"",classConfirm:"btn-primary",loading:!1}))}function a(){r.close(!1)}function s(){n.loading=!0,r.closed.then(n.onCloseAfterConfirm),t.resolve().then(n.onConfirm).then(function(){r.close(!0)})}n.cancel=a,n.confirm=s,function(){o(i),i.optionsPromise&&i.optionsPromise().then(function(e){o(e)})}()}t.controller("DialogController",n),n.$inject=["$q","$scope","$uibModalInstance","options"]}),define("common/modules/dialog",["common/angular","common/services/dialog/dialog","common/controllers/dialog/dialog-ctrl","common/angularBootstrap","common/directives/loading","common/modules/templates"],function(e){"use strict";return e.module("common.dialog",["ui.bootstrap","common.directives","common.templates"])}),define("common/decorators/xeditable-civi/editable-directive-factory",[],function(){"use strict";return["$delegate",function(e){return function(t){var n=e(t);return n.compile=function(e){var t,r=e[0].attributes.getNamedItem("ng-href");return e.append(''),r&&(t=angular.element(""),t.text("Follow link"),t.attr(r.nodeName,r.value),t.attr("ng-click","$event.stopPropagation();"),t.addClass("editable-link"),e.append(t),e.addClass("editable-with-link")),{post:n.link}},n}}]}),define("common/directives/xeditable-civi/editable-ta",[],function(){"use strict";return["editableDirectiveFactory","$timeout",function(e,t){var n,r;return r=e({directiveName:"editableTa",inputTpl:"",render:function(){this.parent.render.call(this),this.inputEl.parent().parent().removeClass("form-inline"),this.inputEl.addClass("editable-ta"),this.inputEl.attr("ng-model","ta.$data"),this.inputEl.attr("ta-toolbar",this.attrs.eTaToolbar||'[["bold","italics","underline","strikeThrough","ul","ol","undo","redo","clear"]]'),t(function(){this.inputEl.find("textarea").hide()}.bind(this),0)},save:function(){this.scope.$data=this.scope.ta.$data,this.parent.save.call(this)},setLocalValue:function(){this.parent.setLocalValue.call(this),this.scope.ta.$data=this.scope.$data}}),n=r.link,r.link=function(e,t,r,i){return e.ta={},n(e,t,r,i)},r}]}),define("common/modules/xeditable-civi",["common/angular","common/decorators/xeditable-civi/editable-directive-factory","common/directives/xeditable-civi/editable-ta","common/angularXeditable","common/text-angular"],function(e,t,n){"use strict";return e.module("xeditable-civi",["xeditable","textAngular"]).directive("editableTa",n)}); +this.date(a.getUTCDate()),this}function Ut(e){return null==e?Math.ceil((this.month()+1)/3):this.month(3*(e-1)+this.month()%3)}function Ht(e){return me(e,this._week.dow,this._week.doy).week}function qt(){return this._week.dow}function Vt(){return this._week.doy}function zt(e){var t=this.localeData().week(this);return null==e?t:this.add(7*(e-t),"d")}function Bt(e){var t=me(this,1,4).week;return null==e?t:this.add(7*(e-t),"d")}function Yt(e,t){return"string"!=typeof e?e:isNaN(e)?(e=t.weekdaysParse(e),"number"==typeof e?e:null):parseInt(e,10)}function Wt(e,n){return t(this._weekdays)?this._weekdays[e.day()]:this._weekdays[this._weekdays.isFormat.test(n)?"format":"standalone"][e.day()]}function Gt(e){return this._weekdaysShort[e.day()]}function Kt(e){return this._weekdaysMin[e.day()]}function Zt(e,t,n){var r,i,o;for(this._weekdaysParse||(this._weekdaysParse=[],this._minWeekdaysParse=[],this._shortWeekdaysParse=[],this._fullWeekdaysParse=[]),r=0;7>r;r++){if(i=Te([2e3,1]).day(r),n&&!this._fullWeekdaysParse[r]&&(this._fullWeekdaysParse[r]=new RegExp("^"+this.weekdays(i,"").replace(".",".?")+"$","i"),this._shortWeekdaysParse[r]=new RegExp("^"+this.weekdaysShort(i,"").replace(".",".?")+"$","i"),this._minWeekdaysParse[r]=new RegExp("^"+this.weekdaysMin(i,"").replace(".",".?")+"$","i")),this._weekdaysParse[r]||(o="^"+this.weekdays(i,"")+"|^"+this.weekdaysShort(i,"")+"|^"+this.weekdaysMin(i,""),this._weekdaysParse[r]=new RegExp(o.replace(".",""),"i")),n&&"dddd"===t&&this._fullWeekdaysParse[r].test(e))return r;if(n&&"ddd"===t&&this._shortWeekdaysParse[r].test(e))return r;if(n&&"dd"===t&&this._minWeekdaysParse[r].test(e))return r;if(!n&&this._weekdaysParse[r].test(e))return r}}function Jt(e){if(!this.isValid())return null!=e?this:NaN;var t=this._isUTC?this._d.getUTCDay():this._d.getDay();return null!=e?(e=Yt(e,this.localeData()),this.add(e-t,"d")):t}function Qt(e){if(!this.isValid())return null!=e?this:NaN;var t=(this.day()+7-this.localeData()._week.dow)%7;return null==e?t:this.add(e-t,"d")}function Xt(e){return this.isValid()?null==e?this.day()||7:this.day(this.day()%7?e:e-7):null!=e?this:NaN}function en(e){var t=Math.round((this.clone().startOf("day")-this.clone().startOf("year"))/864e5)+1;return null==e?t:this.add(e-t,"d")}function tn(){return this.hours()%12||12}function nn(e,t){R(e,0,0,function(){return this.localeData().meridiem(this.hours(),this.minutes(),t)})}function rn(e,t){return t._meridiemParse}function on(e){return"p"===(e+"").toLowerCase().charAt(0)}function an(e,t,n){return e>11?n?"pm":"PM":n?"am":"AM"}function sn(e,t){t[_r]=g(1e3*("0."+e))}function ln(){return this._isUTC?"UTC":""}function un(){return this._isUTC?"Coordinated Universal Time":""}function cn(e){return Te(1e3*e)}function fn(){return Te.apply(null,arguments).parseZone()}function dn(e,t,n){var r=this._calendar[e];return M(r)?r.call(t,n):r}function pn(e){var t=this._longDateFormat[e],n=this._longDateFormat[e.toUpperCase()];return t||!n?t:(this._longDateFormat[e]=n.replace(/MMMM|MM|DD|dddd/g,function(e){return e.slice(1)}),this._longDateFormat[e])}function hn(){return this._invalidDate}function mn(e){return this._ordinal.replace("%d",e)}function gn(e){return e}function vn(e,t,n,r){var i=this._relativeTime[n];return M(i)?i(e,t,n,r):i.replace(/%d/i,e)}function yn(e,t){var n=this._relativeTime[e>0?"future":"past"];return M(n)?n(t):n.replace(/%s/i,t)}function bn(e){var t,n;for(n in e)t=e[n],M(t)?this[n]=t:this["_"+n]=t;this._ordinalParseLenient=new RegExp(this._ordinalParse.source+"|"+/\d{1,2}/.source)}function $n(e,t,n,r){var i=k(),o=a().set(r,t);return i[n](o,e)}function wn(e,t,n,r,i){if("number"==typeof e&&(t=e,e=void 0),e=e||"",null!=t)return $n(e,t,n,i);var o,a=[];for(o=0;r>o;o++)a[o]=$n(e,o,n,i);return a}function xn(e,t){return wn(e,t,"months",12,"month")}function Cn(e,t){return wn(e,t,"monthsShort",12,"month")}function kn(e,t){return wn(e,t,"weekdays",7,"day")}function En(e,t){return wn(e,t,"weekdaysShort",7,"day")}function Sn(e,t){return wn(e,t,"weekdaysMin",7,"day")}function _n(){var e=this._data;return this._milliseconds=gi(this._milliseconds),this._days=gi(this._days),this._months=gi(this._months),e.milliseconds=gi(e.milliseconds),e.seconds=gi(e.seconds),e.minutes=gi(e.minutes),e.hours=gi(e.hours),e.months=gi(e.months),e.years=gi(e.years),this}function Mn(e,t,n,r){var i=Ze(t,n);return e._milliseconds+=r*i._milliseconds,e._days+=r*i._days,e._months+=r*i._months,e._bubble()}function Tn(e,t){return Mn(this,e,t,1)}function Dn(e,t){return Mn(this,e,t,-1)}function An(e){return 0>e?Math.floor(e):Math.ceil(e)}function On(){var e,t,n,r,i,o=this._milliseconds,a=this._days,s=this._months,l=this._data;return o>=0&&a>=0&&s>=0||0>=o&&0>=a&&0>=s||(o+=864e5*An(Rn(s)+a),a=0,s=0),l.milliseconds=o%1e3,e=m(o/1e3),l.seconds=e%60,t=m(e/60),l.minutes=t%60,n=m(t/60),l.hours=n%24,a+=m(n/24),i=m(Nn(a)),s+=i,a-=An(Rn(i)),r=m(s/12),s%=12,l.days=a,l.months=s,l.years=r,this}function Nn(e){return 4800*e/146097}function Rn(e){return 146097*e/4800}function In(e){var t,n,r=this._milliseconds;if("month"===(e=S(e))||"year"===e)return t=this._days+r/864e5,n=this._months+Nn(t),"month"===e?n:n/12;switch(t=this._days+Math.round(Rn(this._months)),e){case"week":return t/7+r/6048e5;case"day":return t+r/864e5;case"hour":return 24*t+r/36e5;case"minute":return 1440*t+r/6e4;case"second":return 86400*t+r/1e3;case"millisecond":return Math.floor(864e5*t)+r;default:throw new Error("Unknown unit "+e)}}function Pn(){return this._milliseconds+864e5*this._days+this._months%12*2592e6+31536e6*g(this._months/12)}function Fn(e){return function(){return this.as(e)}}function jn(e){return e=S(e),this[e+"s"]()}function Ln(e){return function(){return this._data[e]}}function Un(){return m(this.days()/7)}function Hn(e,t,n,r,i){return i.relativeTime(t||1,!!n,e,r)}function qn(e,t,n){var r=Ze(e).abs(),i=Oi(r.as("s")),o=Oi(r.as("m")),a=Oi(r.as("h")),s=Oi(r.as("d")),l=Oi(r.as("M")),u=Oi(r.as("y")),c=i=o&&["m"]||o=a&&["h"]||a=s&&["d"]||s=l&&["M"]||l=u&&["y"]||["yy",u];return c[2]=t,c[3]=+e>0,c[4]=n,Hn.apply(null,c)}function Vn(e,t){return void 0!==Ni[e]&&(void 0===t?Ni[e]:(Ni[e]=t,!0))}function zn(e){var t=this.localeData(),n=qn(this,!e,t);return e&&(n=t.pastFuture(+this,n)),t.postformat(n)}function Bn(){var e,t,n,r=Ri(this._milliseconds)/1e3,i=Ri(this._days),o=Ri(this._months);e=m(r/60),t=m(e/60),r%=60,e%=60,n=m(o/12),o%=12;var a=n,s=o,l=i,u=t,c=e,f=r,d=this.asSeconds();return d?(0>d?"-":"")+"P"+(a?a+"Y":"")+(s?s+"M":"")+(l?l+"D":"")+(u||c||f?"T":"")+(u?u+"H":"")+(c?c+"M":"")+(f?f+"S":""):"P0D"}var Yn,Wn,Gn=e.momentProperties=[],Kn=!1,Zn={},Jn={},Qn=/(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,Xn=/(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g,er={},tr={},nr=/\d/,rr=/\d\d/,ir=/\d{3}/,or=/\d{4}/,ar=/[+-]?\d{6}/,sr=/\d\d?/,lr=/\d\d\d\d?/,ur=/\d\d\d\d\d\d?/,cr=/\d{1,3}/,fr=/\d{1,4}/,dr=/[+-]?\d{1,6}/,pr=/\d+/,hr=/[+-]?\d+/,mr=/Z|[+-]\d\d:?\d\d/gi,gr=/Z|[+-]\d\d(?::?\d\d)?/gi,vr=/[+-]?\d+(\.\d{1,3})?/,yr=/[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i,br={},$r={},wr=0,xr=1,Cr=2,kr=3,Er=4,Sr=5,_r=6,Mr=7,Tr=8;R("M",["MM",2],"Mo",function(){return this.month()+1}),R("MMM",0,0,function(e){return this.localeData().monthsShort(this,e)}),R("MMMM",0,0,function(e){return this.localeData().months(this,e)}),E("month","M"),L("M",sr),L("MM",sr,rr),L("MMM",function(e,t){return t.monthsShortRegex(e)}),L("MMMM",function(e,t){return t.monthsRegex(e)}),V(["M","MM"],function(e,t){t[xr]=g(e)-1}),V(["MMM","MMMM"],function(e,t,n,r){var i=n._locale.monthsParse(e,r,n._strict);null!=i?t[xr]=i:l(n).invalidMonth=e});var Dr=/D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?/,Ar="January_February_March_April_May_June_July_August_September_October_November_December".split("_"),Or="Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),Nr=yr,Rr=yr,Ir={};e.suppressDeprecationWarnings=!1;var Pr=/^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/,Fr=/^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/,jr=/Z|[+-]\d\d(?::?\d\d)?/,Lr=[["YYYYYY-MM-DD",/[+-]\d{6}-\d\d-\d\d/],["YYYY-MM-DD",/\d{4}-\d\d-\d\d/],["GGGG-[W]WW-E",/\d{4}-W\d\d-\d/],["GGGG-[W]WW",/\d{4}-W\d\d/,!1],["YYYY-DDD",/\d{4}-\d{3}/],["YYYY-MM",/\d{4}-\d\d/,!1],["YYYYYYMMDD",/[+-]\d{10}/],["YYYYMMDD",/\d{8}/],["GGGG[W]WWE",/\d{4}W\d{3}/],["GGGG[W]WW",/\d{4}W\d{2}/,!1],["YYYYDDD",/\d{7}/]],Ur=[["HH:mm:ss.SSSS",/\d\d:\d\d:\d\d\.\d+/],["HH:mm:ss,SSSS",/\d\d:\d\d:\d\d,\d+/],["HH:mm:ss",/\d\d:\d\d:\d\d/],["HH:mm",/\d\d:\d\d/],["HHmmss.SSSS",/\d\d\d\d\d\d\.\d+/],["HHmmss,SSSS",/\d\d\d\d\d\d,\d+/],["HHmmss",/\d\d\d\d\d\d/],["HHmm",/\d\d\d\d/],["HH",/\d\d/]],Hr=/^\/?Date\((\-?\d+)/i;e.createFromInputFallback=ie("moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to https://github.com/moment/moment/issues/1407 for more info.",function(e){e._d=new Date(e._i+(e._useUTC?" UTC":""))}),R("Y",0,0,function(){var e=this.year();return 9999>=e?""+e:"+"+e}),R(0,["YY",2],0,function(){return this.year()%100}),R(0,["YYYY",4],0,"year"),R(0,["YYYYY",5],0,"year"),R(0,["YYYYYY",6,!0],0,"year"),E("year","y"),L("Y",hr),L("YY",sr,rr),L("YYYY",fr,or),L("YYYYY",dr,ar),L("YYYYYY",dr,ar),V(["YYYYY","YYYYYY"],wr),V("YYYY",function(t,n){n[wr]=2===t.length?e.parseTwoDigitYear(t):g(t)}),V("YY",function(t,n){n[wr]=e.parseTwoDigitYear(t)}),V("Y",function(e,t){t[wr]=parseInt(e,10)}),e.parseTwoDigitYear=function(e){return g(e)+(g(e)>68?1900:2e3)};var qr=T("FullYear",!1);e.ISO_8601=function(){};var Vr=ie("moment().min is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548",function(){var e=Te.apply(null,arguments);return this.isValid()&&e.isValid()?this>e?this:e:c()}),zr=ie("moment().max is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548",function(){var e=Te.apply(null,arguments);return this.isValid()&&e.isValid()?e>this?this:e:c()}),Br=function(){return Date.now?Date.now():+new Date};Ie("Z",":"),Ie("ZZ",""),L("Z",gr),L("ZZ",gr),V(["Z","ZZ"],function(e,t,n){n._useUTC=!0,n._tzm=Pe(gr,e)});var Yr=/([\+\-]|\d\d)/gi;e.updateOffset=function(){};var Wr=/(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/,Gr=/^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/;Ze.fn=Ne.prototype;var Kr=et(1,"add"),Zr=et(-1,"subtract");e.defaultFormat="YYYY-MM-DDTHH:mm:ssZ";var Jr=ie("moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.",function(e){return void 0===e?this.localeData():this.locale(e)});R(0,["gg",2],0,function(){return this.weekYear()%100}),R(0,["GG",2],0,function(){return this.isoWeekYear()%100}),Nt("gggg","weekYear"),Nt("ggggg","weekYear"),Nt("GGGG","isoWeekYear"),Nt("GGGGG","isoWeekYear"),E("weekYear","gg"),E("isoWeekYear","GG"),L("G",hr),L("g",hr),L("GG",sr,rr),L("gg",sr,rr),L("GGGG",fr,or),L("gggg",fr,or),L("GGGGG",dr,ar),L("ggggg",dr,ar),z(["gggg","ggggg","GGGG","GGGGG"],function(e,t,n,r){t[r.substr(0,2)]=g(e)}),z(["gg","GG"],function(t,n,r,i){n[i]=e.parseTwoDigitYear(t)}),R("Q",0,"Qo","quarter"),E("quarter","Q"),L("Q",nr),V("Q",function(e,t){t[xr]=3*(g(e)-1)}),R("w",["ww",2],"wo","week"),R("W",["WW",2],"Wo","isoWeek"),E("week","w"),E("isoWeek","W"),L("w",sr),L("ww",sr,rr),L("W",sr),L("WW",sr,rr),z(["w","ww","W","WW"],function(e,t,n,r){t[r.substr(0,1)]=g(e)});var Qr={dow:0,doy:6};R("D",["DD",2],"Do","date"),E("date","D"),L("D",sr),L("DD",sr,rr),L("Do",function(e,t){return e?t._ordinalParse:t._ordinalParseLenient}),V(["D","DD"],Cr),V("Do",function(e,t){t[Cr]=g(e.match(sr)[0],10)});var Xr=T("Date",!0);R("d",0,"do","day"),R("dd",0,0,function(e){return this.localeData().weekdaysMin(this,e)}),R("ddd",0,0,function(e){return this.localeData().weekdaysShort(this,e)}),R("dddd",0,0,function(e){return this.localeData().weekdays(this,e)}),R("e",0,0,"weekday"),R("E",0,0,"isoWeekday"),E("day","d"),E("weekday","e"),E("isoWeekday","E"),L("d",sr),L("e",sr),L("E",sr),L("dd",yr),L("ddd",yr),L("dddd",yr),z(["dd","ddd","dddd"],function(e,t,n,r){var i=n._locale.weekdaysParse(e,r,n._strict);null!=i?t.d=i:l(n).invalidWeekday=e}),z(["d","e","E"],function(e,t,n,r){t[r]=g(e)});var ei="Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),ti="Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),ni="Su_Mo_Tu_We_Th_Fr_Sa".split("_");R("DDD",["DDDD",3],"DDDo","dayOfYear"),E("dayOfYear","DDD"),L("DDD",cr),L("DDDD",ir),V(["DDD","DDDD"],function(e,t,n){n._dayOfYear=g(e)}),R("H",["HH",2],0,"hour"),R("h",["hh",2],0,tn),R("hmm",0,0,function(){return""+tn.apply(this)+N(this.minutes(),2)}),R("hmmss",0,0,function(){return""+tn.apply(this)+N(this.minutes(),2)+N(this.seconds(),2)}),R("Hmm",0,0,function(){return""+this.hours()+N(this.minutes(),2)}),R("Hmmss",0,0,function(){return""+this.hours()+N(this.minutes(),2)+N(this.seconds(),2)}),nn("a",!0),nn("A",!1),E("hour","h"),L("a",rn),L("A",rn),L("H",sr),L("h",sr),L("HH",sr,rr),L("hh",sr,rr),L("hmm",lr),L("hmmss",ur),L("Hmm",lr),L("Hmmss",ur),V(["H","HH"],kr),V(["a","A"],function(e,t,n){n._isPm=n._locale.isPM(e),n._meridiem=e}),V(["h","hh"],function(e,t,n){t[kr]=g(e),l(n).bigHour=!0}),V("hmm",function(e,t,n){var r=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r)),l(n).bigHour=!0}),V("hmmss",function(e,t,n){var r=e.length-4,i=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r,2)),t[Sr]=g(e.substr(i)),l(n).bigHour=!0}),V("Hmm",function(e,t,n){var r=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r))}),V("Hmmss",function(e,t,n){var r=e.length-4,i=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r,2)),t[Sr]=g(e.substr(i))});var ri=/[ap]\.?m?\.?/i,ii=T("Hours",!0);R("m",["mm",2],0,"minute"),E("minute","m"),L("m",sr),L("mm",sr,rr),V(["m","mm"],Er);var oi=T("Minutes",!1);R("s",["ss",2],0,"second"),E("second","s"),L("s",sr),L("ss",sr,rr),V(["s","ss"],Sr);var ai=T("Seconds",!1);R("S",0,0,function(){return~~(this.millisecond()/100)}),R(0,["SS",2],0,function(){return~~(this.millisecond()/10)}),R(0,["SSS",3],0,"millisecond"),R(0,["SSSS",4],0,function(){return 10*this.millisecond()}),R(0,["SSSSS",5],0,function(){return 100*this.millisecond()}),R(0,["SSSSSS",6],0,function(){return 1e3*this.millisecond()}),R(0,["SSSSSSS",7],0,function(){return 1e4*this.millisecond()}),R(0,["SSSSSSSS",8],0,function(){return 1e5*this.millisecond()}),R(0,["SSSSSSSSS",9],0,function(){return 1e6*this.millisecond()}),E("millisecond","ms"),L("S",cr,nr),L("SS",cr,rr),L("SSS",cr,ir);var si;for(si="SSSS";si.length<=9;si+="S")L(si,pr);for(si="S";si.length<=9;si+="S")V(si,sn);var li=T("Milliseconds",!1);R("z",0,0,"zoneAbbr"),R("zz",0,0,"zoneName");var ui=p.prototype;ui.add=Kr,ui.calendar=nt,ui.clone=rt,ui.diff=ct,ui.endOf=xt,ui.format=ht,ui.from=mt,ui.fromNow=gt,ui.to=vt,ui.toNow=yt,ui.get=O,ui.invalidAt=At,ui.isAfter=it,ui.isBefore=ot,ui.isBetween=at,ui.isSame=st,ui.isSameOrAfter=lt,ui.isSameOrBefore=ut,ui.isValid=Tt,ui.lang=Jr,ui.locale=bt,ui.localeData=$t,ui.max=zr,ui.min=Vr,ui.parsingFlags=Dt,ui.set=O,ui.startOf=wt,ui.subtract=Zr,ui.toArray=St,ui.toObject=_t,ui.toDate=Et,ui.toISOString=pt,ui.toJSON=Mt,ui.toString=dt,ui.unix=kt,ui.valueOf=Ct,ui.creationData=Ot,ui.year=qr,ui.isLeapYear=de,ui.weekYear=Rt,ui.isoWeekYear=It,ui.quarter=ui.quarters=Ut,ui.month=J,ui.daysInMonth=Q,ui.week=ui.weeks=zt,ui.isoWeek=ui.isoWeeks=Bt,ui.weeksInYear=Ft,ui.isoWeeksInYear=Pt,ui.date=Xr,ui.day=ui.days=Jt,ui.weekday=Qt,ui.isoWeekday=Xt,ui.dayOfYear=en,ui.hour=ui.hours=ii,ui.minute=ui.minutes=oi,ui.second=ui.seconds=ai,ui.millisecond=ui.milliseconds=li,ui.utcOffset=Le,ui.utc=He,ui.local=qe,ui.parseZone=Ve,ui.hasAlignedHourOffset=ze,ui.isDST=Be,ui.isDSTShifted=Ye,ui.isLocal=We,ui.isUtcOffset=Ge,ui.isUtc=Ke,ui.isUTC=Ke,ui.zoneAbbr=ln,ui.zoneName=un,ui.dates=ie("dates accessor is deprecated. Use date instead.",Xr),ui.months=ie("months accessor is deprecated. Use month instead",J),ui.years=ie("years accessor is deprecated. Use year instead",qr),ui.zone=ie("moment().zone is deprecated, use moment().utcOffset instead. https://github.com/moment/moment/issues/1779",Ue);var ci=ui,fi={sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"},di={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},pi=/\d{1,2}/,hi={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},mi=y.prototype;mi._calendar=fi,mi.calendar=dn,mi._longDateFormat=di,mi.longDateFormat=pn,mi._invalidDate="Invalid date",mi.invalidDate=hn,mi._ordinal="%d",mi.ordinal=mn,mi._ordinalParse=pi,mi.preparse=gn,mi.postformat=gn,mi._relativeTime=hi,mi.relativeTime=vn,mi.pastFuture=yn,mi.set=bn,mi.months=W,mi._months=Ar,mi.monthsShort=G,mi._monthsShort=Or,mi.monthsParse=K,mi._monthsRegex=Rr,mi.monthsRegex=ee,mi._monthsShortRegex=Nr,mi.monthsShortRegex=X,mi.week=Ht,mi._week=Qr,mi.firstDayOfYear=Vt,mi.firstDayOfWeek=qt,mi.weekdays=Wt,mi._weekdays=ei,mi.weekdaysMin=Kt,mi._weekdaysMin=ni,mi.weekdaysShort=Gt,mi._weekdaysShort=ti,mi.weekdaysParse=Zt,mi.isPM=on,mi._meridiemParse=ri,mi.meridiem=an,x("en",{ordinalParse:/\d{1,2}(th|st|nd|rd)/,ordinal:function(e){var t=e%10;return e+(1===g(e%100/10)?"th":1===t?"st":2===t?"nd":3===t?"rd":"th")}}),e.lang=ie("moment.lang is deprecated. Use moment.locale instead.",x),e.langData=ie("moment.langData is deprecated. Use moment.localeData instead.",k);var gi=Math.abs,vi=Fn("ms"),yi=Fn("s"),bi=Fn("m"),$i=Fn("h"),wi=Fn("d"),xi=Fn("w"),Ci=Fn("M"),ki=Fn("y"),Ei=Ln("milliseconds"),Si=Ln("seconds"),_i=Ln("minutes"),Mi=Ln("hours"),Ti=Ln("days"),Di=Ln("months"),Ai=Ln("years"),Oi=Math.round,Ni={s:45,m:45,h:22,d:26,M:11},Ri=Math.abs,Ii=Ne.prototype;return Ii.abs=_n,Ii.add=Tn,Ii.subtract=Dn,Ii.as=In,Ii.asMilliseconds=vi,Ii.asSeconds=yi,Ii.asMinutes=bi,Ii.asHours=$i,Ii.asDays=wi,Ii.asWeeks=xi,Ii.asMonths=Ci,Ii.asYears=ki,Ii.valueOf=Pn,Ii._bubble=On,Ii.get=jn,Ii.milliseconds=Ei,Ii.seconds=Si,Ii.minutes=_i,Ii.hours=Mi,Ii.days=Ti,Ii.weeks=Un,Ii.months=Di,Ii.years=Ai,Ii.humanize=zn,Ii.toISOString=Bn,Ii.toString=Bn,Ii.toJSON=Bn,Ii.locale=bt,Ii.localeData=$t,Ii.toIsoString=ie("toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)",Bn),Ii.lang=Jr,R("X",0,0,"unix"),R("x",0,0,"valueOf"),L("x",hr),L("X",vr),V("X",function(e,t,n){n._d=new Date(1e3*parseFloat(e,10))}),V("x",function(e,t,n){n._d=new Date(g(e))}),e.version="2.11.1",function(e){Yn=e}(Te),e.fn=ci,e.min=Ae,e.max=Oe,e.now=Br,e.utc=a,e.unix=cn,e.months=xn,e.isDate=n,e.locale=x,e.invalid=c,e.duration=Ze,e.isMoment=h,e.weekdays=kn,e.parseZone=fn,e.localeData=k,e.isDuration=Re,e.monthsShort=Cn,e.weekdaysMin=Sn,e.defineLocale=C,e.weekdaysShort=En,e.normalizeUnits=S,e.relativeTimeThreshold=Vn,e.prototype=ci,e}),define("common/bundles/vendors",["common/require","common/angular","common/angularAnimate","common/angularBootstrap","common/angular-file-upload","common/angularMocks","common/angularResource","common/angularRoute","common/angularXeditable","common/text-angular","common/ui-select","common/d3","common/lodash","common/moment"],function(){}),define("common/modules/apis",["common/angular"],function(e){"use strict";return e.module("common.apis",[])}),define("common/services/api",["common/angular","common/lodash","common/modules/apis"],function(e,t,n){"use strict";n.factory("api",["$cacheFactory","$log","$http","$httpParamSerializer","$q","$timeout",function(n,r,i,o,a,s){function l(e){return e.data.is_error?(r.error(e.data),a.reject(e.data.error_message)):e.data}function u(e){var n={options:{limit:0}};return JSON.stringify(t.merge(n,e||{}))}function c(e){return"?"+Object.keys(e).sort().map(function(t){return(encodeURIComponent(t)+"="+encodeURIComponent(e[t])).replace(/%3A/g,":").replace(/%2C/g,",")}).join("&")}r.debug("api");return{extend:function(t){return e.extend(Object.create(this),t)},getAll:function(e,n,i,o,s,l,u){return r.debug("api.all"),n=n||{},l=l||"get",a.all([function(){var r=t.assign({},n,s||{},{options:t.assign({},n.options,{sort:o||"id DESC"})});return i&&(r.options.offset=(i.page-1)*i.size,r.options.limit=i.size),this.sendGET(e,l,r,u)}.bind(this)(),function(){if(!i)return a.resolve();var r=t.assign({},n,{return:"id"});return r=t.omit(r,function(e,n){return t.startsWith(n,"api.")}),this.sendGET(e,l,r,u)}.bind(this)()]).then(function(e){var n=e[0],r=i?e[1]:n;return{list:n.values,total:r.count,allIds:t.compact(r.values.map(function(e){return e.id})).join(",")}})},mockGET:function(e,t){var n=a.defer();return s(function(){n.resolve(e)},t||0),n.promise},mockPOST:function(e,t){return this.mockGET.apply(this,arguments)},sendGET:function(e,t,r,o){var a={action:t,entity:e,json:u(r),sequential:1};return!1===o&&n.get("$http").remove("/civicrm/ajax/rest"+c(a)),i({method:"GET",url:"/civicrm/ajax/rest",cache:!0,responseType:"json",params:a}).then(l)},sendPOST:function(e,t,n){return r.debug("api.sendPOST"),i({method:"POST",url:"/civicrm/ajax/rest",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},responseType:"json",data:{json:u(n),sequential:1,entity:e,action:t},transformRequest:o}).then(l)}}}])}),define("common/services/api/appraisal",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.appraisal",["$log","api",function(e,t){return e.debug("api.appraisal"),t.extend({all:function(t,n,r){return e.debug("api.appraisal.api"),this.getAll("Appraisal",t,n,r)},create:function(t){return e.debug("api.appraisal.create"),this.sendPOST("Appraisal","create",t).then(function(e){return e.values[0]})},find:function(t){return e.debug("api.appraisal.find"),this.sendGET("Appraisal","get",{id:""+t},!1).then(function(e){return e.values[0]})}})}])}),define("common/services/api/option-group",["common/lodash","common/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("api.optionGroup",["$log","api",function(t,n){function r(t){return t.values.map(function(t){var n=e.clone(t);return n.option_group_name=n["option_group_id.name"],delete n["option_group_id.name"],n})}function i(t){return e.transform(t,function(e,t){var n=t.option_group_name;e[n]=e[n]||[],e[n].push(t)})}return t.debug("api.optionGroup"),n.extend({valuesOf:function(t,n,o){var a=e.isArray(t);return this.sendGET("OptionValue","get",e.assign({"option_group_id.name":{IN:a?t:[t]},is_active:"1",return:["option_group_id.name","option_group_id","id","name","label","value","weight","is_active","is_reserved"]},n),o).then(r).then(function(e){return a?i(e):e})}})}])}),define("common/services/api/appraisal-cycle",["common/lodash","common/modules/apis","common/services/api","common/services/api/option-group"],function(e,t){"use strict";t.factory("api.appraisal-cycle",["$q","$log","api","api.optionGroup",function(t,n,r,i){return n.debug("api.appraisal-cycle"),r.extend({all:function(e,t,r){return n.debug("api.appraisal-cycle.all"),this.getAll("AppraisalCycle",e,t,r,{"api.AppraisalCycle.getappraisalsperstep":{}})},create:function(t){return n.debug("api.appraisal-cycle.create"),this.sendPOST("AppraisalCycle","create",e.assign(t,{"api.AppraisalCycle.getappraisalsperstep":{}})).then(function(e){return e.values[0]})},find:function(e){n.debug("api.appraisal-cycle.find");var t={id:""+e,"api.AppraisalCycle.getappraisalsperstep":{}};return this.sendGET("AppraisalCycle","get",t,!1).then(function(e){return e.values[0]})},grades:function(){return n.debug("grades"),this.mockGET([{label:1,value:17},{label:2,value:74},{label:3,value:90},{label:4,value:30}])},statuses:function(){return n.debug("api.appraisal-cycle.statuses"),i.valuesOf("appraisal_status")},statusOverview:function(e){return n.debug("api.appraisal-cycle.statusOverview"),this.sendGET("AppraisalCycle","getstatusoverview",e).then(function(e){return e.values})},update:function(t){return n.debug("api.appraisal-cycle.update"),this.sendPOST("AppraisalCycle","create",e.assign(t,{"api.AppraisalCycle.getappraisalsperstep":{}})).then(function(e){return e.values[0]})},total:function(e){return n.debug("api.appraisal-cycle.total"),this.sendGET("AppraisalCycle","getcount",e||{}).then(function(e){return e.result})},types:function(){return n.debug("api.appraisal-cycle.types"),i.valuesOf("appraisal_cycle_type")}})}])}),define("common/services/api/contact-job-role-api.api",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("ContactJobRoleAPI",["$log","api",function(e,t){return e.debug("ContactJobRoleAPI"),t.extend({all:function(t,n,r,i){return e.debug("ContactJobRoleAPI.all()"),this.getAll("ContactHrJobRoles",t,n,r,i)}})}])}),define("common/bundles/apis",["common/services/api/appraisal","common/services/api/appraisal-cycle","common/services/api/contact-job-role-api.api","common/services/api/option-group"],function(){}),define("common/modules/services",["common/angular","common/angular-file-upload"],function(e){"use strict";return e.module("common.services",["angularFileUpload"])}),define("common/services/before-hash-query-params.service",["common/lodash","common/modules/services"],function(e,t){"use strict";t.factory("beforeHashQueryParams",["$log","$window",function(t,n){function r(e){var t=e||n.location.href,r=o(t);return-1===r.indexOf("?")?{}:i(a(r))}function i(t){return t.length?e.transform(t,function(e,t){var n=t.split("=");n[0]&&(e[n[0]]=n[1]?decodeURI(n[1]):null)},{}):{}}function o(e){var t=e.indexOf("#");return e.substring(0,-1!==t?t:e.length)}function a(e){var t=e.indexOf("?");return e.substr(t+1).split("&")}return t.debug("Service: beforeHashQueryParams"),{parse:r}}])}),function(e){define("common/services/check-permissions",["common/lodash","common/modules/services"],function(t,n){"use strict";n.factory("checkPermissions",["$q",function(n){return function(r){return r=t.isArray(r)?r:[r],n.resolve(r.every(function(t){return e.checkPerm(t)}))}}])})}(CRM),function(e){define("common/services/crm-ang.service",["common/lodash","common/modules/services"],function(t,n){"use strict";function r(t,n){return e.loadForm(t,n)}n.factory("crmAngService",function(){return{loadForm:r}})})}(CRM),define("common/services/detect-device.service",["common/modules/services"],function(e){"use strict";e.factory("detectDevice",[function(){return{isMobile:function(){return document.getElementsByTagName("body")[0].classList.contains("mobile")}}}])}),define("common/services/dom-event-trigger",["common/modules/services"],function(e){"use strict";!function(t){e.factory("DOMEventTrigger",function(){return function(e,n){t(document).trigger(e,n)}})}(CRM.$)}),define("common/services/file-mime-types",["common/lodash","common/modules/services"],function(e,t){"use strict";t.factory("fileMimeTypes",["$q",function(e){var t={txt:"plain",png:"png",jpeg:"jpeg",bmp:"bmp",gif:"gif",pdf:"pdf",doc:"msword",docx:"vnd.openxmlformats-officedocument.wordprocessingml.document",xls:"vnd.ms-excel",xlsx:"vnd.openxmlformats-officedocument.spreadsheetml.sheet",ppt:"vnd.ms-powerpoint",pptx:"vnd.openxmlformats-officedocument.presentationml.presentation"};return{getMimeTypeFor:function(n){return e.resolve(t[n])}}}])}),define("common/services/file-upload",["common/modules/services","common/lodash","common/angular-file-upload"],function(e,t){"use strict";e.factory("FileUpload",["$q","$log","FileUploader",function(e,n,r){function i(e){throw new Error(e+" missing from parameter")}function o(e,t,r,i){n.error(" ===== Item Error: "+r+" ======"),n.error(" ===== - item ======"),n.error(e),n.error(" ===== - response ======"),n.error(t),n.error(" ===== - headers ======"),n.error(i)}function a(e){return t.defaults(e,{allowedMimeTypes:{txt:"plain",png:"png",jpeg:"jpeg",bmp:"bmp",gif:"gif",pdf:"pdf"},url:"/civicrm/ajax/attachment",queueLimit:1})}return{uploader:function(n){var s,l,u,c=[];return n?(n=a(n),s=new r({url:n.url,queueLimit:+n.queueLimit,onCompleteItem:function(e,t){c.push(t)},onCompleteAll:function(){u.resolve(c)},onErrorItem:function(e){o.apply(null,arguments),u.reject("Could not upload file: "+e.file.name)},formData:[{entity_table:n.entityTable||i("entityTable"),crm_attachment_token:n.crmAttachmentToken||i("crmAttachmentToken")}],filters:[{name:"fileFormatFilter",fn:function(e){var r=e.type.slice(e.type.lastIndexOf("/")+1);return t.includes(t.values(n.allowedMimeTypes),r)}}]}),s.uploadAll=function(){return l=s.uploadAll,function(n){return u=e.defer(),s.onBeforeUploadItem=function(e){t.each(n,function(n,r){var i={};i[t.snakeCase(r)]=n,e.formData.push(i)})},l.apply(s),u.promise}}(),s):i("custom settings")}}}])}),define("common/services/file.service",["common/modules/services"],function(e){"use strict";e.factory("fileService",["$http","$window","$log",function(e,t,n){return n.debug("Service: fileService"),{openFile:function(n){return e.get(n.url,{responseType:"arraybuffer"}).success(function(e){var r=new Blob([e],{type:n.fileType});t.navigator.msSaveOrOpenBlob?t.navigator.msSaveOrOpenBlob(r,n.name):t.open(URL.createObjectURL(r),"_blank")})}}}])}),define("common/services/hr-settings",["common/modules/services"],function(e){"use strict";e.factory("HR_settings",function(){return{DATE_FORMAT:null}})}),function(e){define("common/services/notification.service",["common/lodash","common/modules/services"],function(t,n){"use strict";n.factory("notificationService",function(){return t(["alert","success","info","error"]).map(function(t){return[t,function(n,r,i){return e.alert(r,n,t,i)}]}).zipObject().value()})})}(CRM),define("common/services/pub-sub",["common/modules/services"],function(e){"use strict";var t=Object.create(null);e.factory("pubSub",["$rootScope",function(e){return{subscribe:function(n,r){var i;return t[n]=t[n]||[],r.$rootScope=e,i=t[n].push(r)-1,{remove:function(){delete t[n][i]}}},publish:function(e,n){t[e]&&(n=void 0!=n?n:{},t[e].forEach(function(e){e.$rootScope.$applyAsync(function(){e(n)})}))}}}])}),define("common/bundles/services",["common/services/before-hash-query-params.service","common/services/check-permissions","common/services/crm-ang.service","common/services/detect-device.service","common/services/dom-event-trigger","common/services/file-mime-types","common/services/file-upload","common/services/file.service","common/services/hr-settings","common/services/notification.service","common/services/pub-sub"],function(){}),define("common/modules/components",["common/angular"],function(e){return e.module("common.components",[])}),define("common/components/heatmap.component",["common/lodash","common/moment","common/modules/components"],function(e,t,n){function r(){function n(e){e.values&&(u(),l(),c())}function r(){return Object.values(d.values).filter(function(e){return!1!==e})}function i(e,t){return e.reduce(function(e,n){return Math.abs(n.value-t)');r(n,t),e.after(n)}function r(e,n){function r(){n.isOpen=!0,n.$apply()}t.isMobile()||(e.on("click",r),n.$on("$destroy",function(){e.off("click",r)}))}var i=e[0],o=i.compile;return i.compile=function(){var e=o.apply(this,arguments);return function(t,i,o){e.apply(this,arguments),n(i,t),r(i,t)}},e}]}),define("common/decorators/uib-datepicker-mobile-version.decorator",["common/moment","common/services/detect-device.service"],function(e){"use strict";return["$delegate","detectDevice",function(t,n){function r(t){return t?e(t).format("Y-MM-DD"):""}var i=t[0],o=i.compile;return i.require=["ngModel","uibDatepickerPopup"],i.compile=function(){var e=o.apply(this,arguments);return function(t,i,o,a){n.isMobile()?(i.prop("type","date"),o.ngReadonly=!1,a[0].$formatters.push(function(e){return r(e)}),t.$watch("datepickerOptions.minDate",function(e){o.$set("min",r(e))}),t.$watch("datepickerOptions.maxDate",function(e){o.$set("max",r(e))})):e.apply(this,arguments)}},t}]}),define("common/decorators/xeditable-disable-calendar-icon.decorator",[],function(){"use strict";return["$delegate",function(e){var t=e[0],n=t.compile;return t.compile=function(){var e=n.apply(this,arguments);return function(t,n,r){e.apply(this,arguments),r.eShowCalendarButton=!1}},e}]}),define("common/decorators/ui-bootstrap/uib-tabset",[],function(){"use strict";return["$delegate",function(e){return e[0].bindToController.customHeaderClass="@",e}]}),define("common/decorators/ui-bootstrap/uib-modal.decorator",["common/angular"],function(e){"use strict";return["$delegate","$document",function(t,n){function r(){var t,r=[{item:e.element(n[0].body),styles:[{name:"overflow",old:null,new:"hidden"},{name:"height",old:null,new:"100%"},{name:"width",old:null,new:"100%"}]},{item:e.element(n[0].getElementsByTagName("html")[0]),styles:[{name:"overflow",old:null,new:"hidden"},{name:"height",old:null,new:"100%"},{name:"width",old:null,new:"100%"}]}];return r.forEach(function(e){e.styles.forEach(function(t){t.old=e.item.css(t.name),e.item.css(t.name,t.new)})}),t=i.apply(this,arguments),t.closed.then(function(){r.forEach(function(e){e.styles.forEach(function(t){e.item.css(t.name,t.old)})})}),t}var i=t.open;return t.open=r,t}]}),define("common/modules/templates",["common/angular"],function(e){"use strict";return e.module("common.templates",[]).run(["$templateCache",function(e){e.put("dialog.html",'\n\n\n'),e.put("help-text.html",'\n'),e.put("loading.html",'
    \n
    \n
    \n
    \n'),e.put("time-amount-picker.html",'
    \n
    \n \n \n
    \n h\n
    \n \n \n
    \n m\n
    \n'),e.put("timepicker-select.html",'\n\n'),e.put("civihr-ui-select/choices.tpl.html",'
      \n
    • \n
      \n
        \n
      • \n
        \n
      • \n
      \n
    • \n
    \n'),e.put("civihr-ui-select/match-multiple.tpl.html",'\n
  • \n \n \n
  • \n\n'),e.put("civihr-ui-select/match.tpl.html",'\n {{$select.contactList ? \'-select-\' : $select.placeholder}}\n \n \n \n\n'),e.put("civihr-ui-select/select-contacts-multiple.tpl.html",'
    \n
    \n
      \n \n
    • \n \n
    • \n
    \n\n \n\n \n
    \n
    \n'),e.put("civihr-ui-select/select-contacts.tpl.html",'
    \n
    \n \n
    \n'),e.put("civihr-ui-select/select-multiple.tpl.html",'
    \n
    \n
      \n \n
    • \n \n
    • \n
    \n \n
    \n
    \n'),e.put("civihr-ui-select/select.tpl.html",'
    \n
    \n \n
    \n'),e.put("components/heatmap.html",'
      \n
    • \n {{day.name.short}}\n
    • \n
    \n'),e.put("contact-actions/contact-actions.html",'
    \n \n \n
    \n'),e.put("contact-actions/modals/form.html",'
    \n \n \n \n
    \n')}])}),define("common/modules/controllers",["common/angular","common/angularBootstrap","common/modules/apis"],function(e){"use strict";return e.module("common.controllers",["ui.bootstrap","common.apis"])}),define("common/modules/directives",["common/angular","common/decorators/ui-select-focus.decorator","common/decorators/uib-datepicker-calendar-icon.decorator","common/decorators/uib-datepicker-mobile-version.decorator","common/decorators/xeditable-disable-calendar-icon.decorator","common/decorators/ui-bootstrap/uib-tabset","common/decorators/ui-bootstrap/uib-modal.decorator","common/angularBootstrap","common/angularXeditable","common/ui-select","common/modules/templates","common/modules/controllers","common/modules/services","common/modules/apis"],function(e,t,n,r,i,o,a){"use strict";return e.module("common.directives",["common.templates","common.controllers","ui.select","ui.bootstrap","xeditable"]).config(["$provide",function(e){e.decorator("uibDatepickerPopupDirective",r),e.decorator("uibDatepickerPopupDirective",n),e.decorator("uibTabsetDirective",o),e.decorator("$uibModal",a),e.decorator("editableBsdateDirective",i),e.decorator("uiSelectDirective",t)}]).run(["$templateCache",function(e){var t="uib/template/tabs/tabset.html",n=jQuery(e.get(t));n.find("ul").addClass("{{tabset.customHeaderClass}}"),e.put(t,n.wrap("
    ").parent().html())}])}),define("common/services/api/contact-actions",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.contactActions",["$q","api",function(e,t){function n(e,n){return t.sendGET(e,"getoptions",{field:n,context:"search"}).then(function(e){return e.values})}function r(e){return t.sendGET("UFField","get",{uf_group_id:e,is_active:!0}).then(function(e){return e.values})}function i(n,r){return e(function(e,i){if(r.contact_type=n,r.email)return t.sendGET("CustomField","get",{return:["id"],custom_group_id:"Emergency_Contacts",name:"email"}).then(function(t){r["custom_"+t.id]=r.email,delete r.email,e()});e()}).then(function(){return t.sendPOST("Contact","create",r).then(function(e){return e.values[0]})})}return t.extend({getOptions:{forContactType:function(){return n.call(this,"Contact","contact_type")},forGroup:function(){return n.call(this,"GroupContact","group_id")},forTag:function(){return n.call(this,"EntityTag","tag_id")},forStateProvince:function(){return n.call(this,"Address","state_province_id")},forCountry:function(){return n.call(this,"Address","country_id")},forGender:function(){return n.call(this,"Contact","gender_id")},forDeceased:function(){return n.call(this,"Contact","is_deceased")}},save:{newIndividual:function(e){return i.call(this,"Individual",e)},newOrganization:function(e){return i.call(this,"Organization",e)},newHousehold:function(e){return i.call(this,"Household",e)}},getFormFields:{forNewIndividual:function(){return r.call(this,"new_individual")},forNewOrganization:function(){return r.call(this,"new_organization")},forNewHousehold:function(){return r.call(this,"new_household")}}})}])}),define("common/controllers/contact-actions/modal-ctrl",[],function(){"use strict";return function(e,t){this.errorMsg="",this.loading=!0,this.formFields=[],this.init=function(e){e().then(function(e){this.loading=!1,this.formFields=e}.bind(this)).catch(function(){this.loading=!1,this.errorMsg="Error while loading form fields"}.bind(this))},this.cancel=function(){t.dismiss("cancel")},this.save=function(n,r){this.loading=!0,n(this.formFields.reduce(function(e,t){return e[t.field_name]=t.value,e},{})).then(function(n){this.loading=!1,e.$broadcast(r,n),t.dismiss("cancel")}.bind(this)).catch(function(){this.loading=!1,this.errorMsg="Error while saving data"}.bind(this))}}}),define("common/controllers/contact-actions/new-individual-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Individual",i.init(r.getFormFields.forNewIndividual),i.submit=function(){i.save(r.save.newIndividual,"newIndividualCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewIndividualModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/new-household-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Household",i.init(r.getFormFields.forNewHousehold),i.submit=function(){i.save(r.save.newHousehold,"newHouseholdCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewHouseholdModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/new-organization-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Organization",i.init(r.getFormFields.forNewOrganization),i.submit=function(){i.save(r.save.newOrganization,"newOrganizationCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewOrganizationModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/contact-actions-ctrl",["common/modules/controllers","common/services/api/contact-actions","common/controllers/contact-actions/new-individual-ctrl","common/controllers/contact-actions/new-household-ctrl","common/controllers/contact-actions/new-organization-ctrl"],function(e){"use strict";e.controller("ContactActionsCtrl",["$scope","$rootElement","$uibModal","api.contactActions",function(e,t,n,r){var i=this;e.$watch(function(){return i.refineSearch.selected},function(t,n){t!==n&&e.$emit("contactRefineSearch",{field:t.field?t.field.label:null,option:t.option?t.option.value:null})},!0),i.refineSearch={selected:{field:null,option:null},availableFields:[{label:"Contact Type",getOptions:r.getOptions.forContactType},{label:"Group",getOptions:r.getOptions.forGroup},{label:"Tag",getOptions:r.getOptions.forTag},{label:"State / Province",getOptions:r.getOptions.forStateProvince},{label:"Country",getOptions:r.getOptions.forCountry},{label:"Gender",getOptions:r.getOptions.forGender},{label:"Deceased",getOptions:r.getOptions.forDeceased}],availableOptions:{refresh:function(){i.refineSearch.selected.field?(this.options=null,i.refineSearch.selected.field.getOptions().then(function(e){this.options=e}.bind(this))):this.options=[]},options:[]}},i.showNewIndividualModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewIndividualModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})},i.showNewHouseholdModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewHouseholdModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})},i.showNewOrganizationModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewOrganizationModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})}}])}),define("common/directives/prevent-animations",["common/modules/directives"],function(e){"use strict";e.directive("preventAnimations",["$animate",function(e){return{restrict:"A",link:function(t,n,r){e.enabled(n,!1)}}}])}),define("common/directives/loading",["common/modules/directives","common/directives/prevent-animations"],function(e){"use strict";e.directive("crmLoading",["$templateCache",function(e){return{scope:{show:"="},restrict:"E",replace:!0,transclude:!0,template:e.get("loading.html")}}])}),define("common/directives/contact-actions/contact-actions",["common/modules/directives","common/controllers/contact-actions/contact-actions-ctrl","common/directives/loading"],function(e){"use strict";e.directive("contactActions",[function(){return{restrict:"E",templateUrl:"contact-actions/contact-actions.html",controller:"ContactActionsCtrl",controllerAs:"$ctrl",link:function(e,t,n){e.$ctrl.refineSearchVisible=t.parent().parent()[0].hasAttribute("refine-search")}}}])}),define("common/directives/help-text.directive",["common/lodash","common/moment","common/modules/directives","common/services/notification.service"],function(e,t,n){function r(e,t){function n(){var n=e.getHelpText();t.info(e.title||r,n)}var r="Help";this.displayHelpText=n}function i(e,t,n){function r(){return t.find(".help-text").html()}e.getHelpText=r}n.directive("helpText",["$templateCache",function(e){return{restrict:"E",scope:{title:"@?"},transclude:!0,controller:r,controllerAs:"helpText",template:e.get("help-text.html"),link:i}}]),r.$inject=["$scope","notificationService"]}),define("common/directives/scroll-shadows.directive",["common/angular","common/modules/directives"],function(e,t){"use strict";function n(t,n,r){function i(){u(),a(),l(),s()}function o(){var e=f.width(),t=p+"__shadows--show-left",n=p+"__shadows--show-right",r=d.scrollLeft(),i=d.width();if(e<=i)return void d.removeClass(t+" "+n);d[r>0?"addClass":"removeClass"](t),d[r
    ').parent(),d=f.wrap('
    ').parent(),d.wrap('
    ')}var f,d,p="chr_scroll-shadows";!function(){c(),i(),o()}()}t.directive("scrollShadows",[function(){return{restrict:"A",controller:n}}]),n.$inject=["$element","$scope","$window"]}),define("common/directives/timepicker-select.directive",["common/moment","common/modules/directives"],function(e,t){"use strict";function n(t){function n(){var n=+t.timepickerSelectInterval||1,i=e.duration(t.timepickerSelectTimeFrom||"00:00"),o=e.duration(t.timepickerSelectTimeTo||"23:59");for(r.options=[];i.asMinutes()<=o.asMinutes();){var a=e.utc(i.asMilliseconds());r.options.push(a.format("HH:mm")),i.add(n,"minutes")}}var r=this;r.placeholder=t.timepickerSelectPlaceholder,r.options=[],t.$watchGroup(["timepickerSelectTimeFrom","timepickerSelectTimeTo","timepickerSelectInterval"],function(){n()})}t.directive("timepickerSelect",["$templateCache",function(e){return{scope:{timepickerSelectPlaceholder:"@",timepickerSelectTimeFrom:"<",timepickerSelectTimeTo:"<",timepickerSelectInterval:"<"},restrict:"A",controllerAs:"selector",controller:["$scope",n],template:e.get("timepicker-select.html")}}]),n.$inject=["$scope"]}),define("common/directives/time-amount-picker.directive",["common/lodash","common/modules/directives"],function(e,t){"use strict";function n(t){function n(){var e=Math.floor(c);for(d.hoursOptions=[];e<=f;)d.hoursOptions.push(e),e++}function r(){var e,t,n,r=0;for(d.minutesOptions=[];r<60;)t=+d.selectedHours===Math.floor(c)&&rf%1*60,e=t||n,!e&&d.minutesOptions.push(r),r+=u;l()}function i(){u=+t.interval||1,c=isNaN(+t.minAmount)?0:+t.minAmount,f=isNaN(+t.maxAmount)?24:+t.maxAmount,n(),r()}function o(){""!==d.selectedHours&&""!==d.selectedMinutes&&(t.value=+d.selectedHours+d.selectedMinutes/60)}function a(){t.$watch("disabled",function(e){d.disabled=e}),t.$watch("value",function(){s()}),t.$watchGroup(["minAmount","maxAmount","interval"],function(){i()})}function s(){void 0!==t.value&&(d.selectedHours=""+Math.floor(t.value),d.selectedMinutes=""+Math.floor(t.value%1*60)),o()}function l(){d.selectedMinutese.last(d.minutesOptions)&&(d.selectedMinutes=""+e.last(d.minutesOptions))}var u,c,f,d=this;d.hoursOptions=[],d.minutesOptions=[],d.selectedHours="",d.selectedMinutes="",d.buildMinutesOptions=r,d.calculateSelectedValue=o,function(){s(),a()}()}t.directive("timeAmountPicker",["$templateCache",function(e){return{scope:{minAmount:".75?Math.floor(.25*Math.ceil(e/.25))+"h":"",n=e%1&&e%1<=.75&&e%1>0?.25*Math.ceil(e%1/.25)*60+"m":"",r+t+(t&&n?" ":"")+n)}};return function(t,n){var r=void 0===t?0:parseFloat(t);if(isNaN(r))throw new Error("Value must be a number or a numeric string: "+t);return e[n](r)}})}),define("common/bundles/filters",["common/filters/time-unit-applier.filter"],function(){}),define("common/decorators/angular-date/datepicker-popup",["common/lodash"],function(e){return["$delegate","HR_settings",function(t,n){"use strict";var r=t[0].link +;return t[0].compile=function(){return function(t,i,o,a){o.uibDatepickerPopup=o.uibDatepickerPopup||n.DATE_FORMAT||"yyyy-MM-dd",o.showButtonBar=o.showButtonBar||!1,t.datepickerOptions=e.assign({formatDayHeader:"E",showWeeks:!1,startingDay:1},t.datepickerOptions),r.apply(this,arguments)}},t}]}),define("common/decorators/angular-date/date-filter",[],function(){"use strict";return["$delegate",function(e){var t=e;return function(){if("E"===arguments[1]){var e=Array.prototype.slice.call(arguments);return e[1]="EEE",t.apply(this,e)[0]}return t.apply(this,arguments)}}]}),function(e){define("common/modules/angular-date",["common/angular","common/decorators/angular-date/datepicker-popup","common/decorators/angular-date/date-filter","common/modules/services","common/angularBootstrap","common/modules/templates"],function(t,n,r){"use strict";function i(t){var n="uib/template/datepicker/"+t+".html",r=o.get(n);r=r.replace(/glyphicon glyphicon-chevron-(left|right)/gm,"fa fa-chevron-$1"),"day"===t&&(r=function(t){return e(t).find('th[ng-if="showWeeks"]').parent().css({"border-top":"1px solid #DDD"}),e(t).prop("outerHTML")}(e.parseHTML(r))),o.put(n,r)}var o;return t.module("common.angularDate",["common.services","ui.bootstrap","common.templates"]).config(["$provide",function(e){e.decorator("uibDatepickerPopupDirective",n),e.decorator("dateFilter",r)}]).run(["$templateCache",function(e){o=e,["day","month","year"].forEach(i)}])})}(CRM.$),define("common/services/angular-date/date-format",["common/angular","common/modules/angular-date","common/services/hr-settings"],function(e,t){"use strict";t.factory("DateFormat",["$q","HR_settings",function(e,t){return{dateFormat:null,getDateFormat:function(){return this.dateFormat?e.when(this.dateFormat):e.when("dd/MM/yyyy").catch(function(){return"yyyy-MM-dd"}).then(function(e){return t.DATE_FORMAT=e,this.dateFormat=e,e}.bind(this))}}}])}),define("common/filters/angular-date/format-date",["common/moment","common/modules/angular-date","common/services/hr-settings"],function(e,t){"use strict";t.filter("formatDate",["HR_settings",function(t){var n=["DD-MM-YYYY","DD-MM-YYYY HH:mm:ss","YYYY-MM-DD","YYYY-MM-DD HH:mm:ss","DD/MM/YYYY","x","YYYY-MM-DD HH:mm:ss"];return function(r,i,o){var a,s=i||t.DATE_FORMAT||"YYYY-MM-DD",l=e(0);return r instanceof Date&&(r=e(r).format("YYYY-MM-DD HH:mm:ss")),a=e(r,n,!0),a.isValid()&&!a.isSame(l)?i===Date?a.toDate():a.format(s.toUpperCase())+("hours"===o?" "+a.format("HH:mm"):""):"Unspecified"}}])}),define("common/directives/angular-date/date-input",["common/modules/angular-date","common/filters/angular-date/format-date"],function(e){"use strict";e.directive("dateInput",["$filter",function(e){return{require:"ngModel",link:function(t,n,r,i){function o(t){var n=e("formatDate")(t);return n="Unspecified"==n?"":n}i.$formatters.push(o),i.$parsers=[]}}}])}),define("common/bundles/angular-date",["common/services/angular-date/date-format","common/filters/angular-date/format-date","common/directives/angular-date/date-input"],function(){}),define("common/modules/routers/compu-ng-route",["common/angular","common/angularRoute"],function(e){"use strict";return e.module("compuNgRoute",["ngRoute"]).config(["$routeProvider",function(t){var n=t.when;t.resolveForAll=function(e){return t.commonResolve=e,t},t.when=function(r,i){return e.extend(i.resolve||{},t.commonResolve||{}),n.call(t,r,i)}}])}),"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function r(e,t){return L(new(L(function(){},{prototype:e})),t)}function i(e){return j(arguments,function(t){t!==e&&j(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var r in e.path){if(e.path[r]!==t.path[r])break;n.push(e.path[r])}return n}function a(e){if(Object.keys)return Object.keys(e);var t=[];return j(e,function(e,n){t.push(n)}),t}function s(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,r=Number(arguments[2])||0;for(0>(r=0>r?Math.ceil(r):Math.floor(r))&&(r+=n);n>r;r++)if(r in e&&e[r]===t)return r;return-1}function l(e,t,n,r){var i,l=o(n,r),u={},c=[];for(var f in l)if(l[f].params&&(i=a(l[f].params),i.length))for(var d in i)s(c,i[d])>=0||(c.push(i[d]),u[i[d]]=e[i[d]]);return L({},u,t)}function u(e,t,n){if(!n){n=[];for(var r in e)n.push(r)}for(var i=0;i "));if(y[n]=r,I(e))g.push(n,[function(){return t.get(e)}],u);else{var i=t.annotate(e);j(i,function(e){e!==n&&l.hasOwnProperty(e)&&p(l[e],e)}),g.push(n,e,i)}v.pop(),y[n]=o}}function h(e){return P(e)&&e.then&&e.$$promises}if(!P(l))throw new Error("'invocables' must be an object");var m=a(l||{}),g=[],v=[],y={};return j(l,p),l=v=y=null,function(r,o,a){function s(){--b||($||i(y,o.$$values),p.$$values=y,p.$$promises=p.$$promises||!0,delete p.$$inheritedValues,u.resolve(y))}function l(e){p.$$failure=e,u.reject(e)}if(h(r)&&a===n&&(a=o,o=r,r=null),r){if(!P(r))throw new Error("'locals' must be an object")}else r=c;if(o){if(!h(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=f;var u=e.defer(),p=u.promise,v=p.$$promises={},y=L({},r),b=1+g.length/3,$=!1;if(N(o.$$failure))return l(o.$$failure),p;o.$$inheritedValues&&i(y,d(o.$$inheritedValues,m)),L(v,o.$$promises),o.$$values?($=i(y,d(o.$$values,m)),p.$$inheritedValues=d(o.$$values,m),s()):(o.$$inheritedValues&&(p.$$inheritedValues=d(o.$$inheritedValues,m)),o.then(s,l));for(var w=0,x=g.length;x>w;w+=3)r.hasOwnProperty(g[w])?s():function(n,i,o){function u(e){f.reject(e),l(e)}function c(){if(!N(p.$$failure))try{f.resolve(t.invoke(i,a,y)),f.promise.then(function(e){y[n]=e,s()},u)}catch(e){u(e)}}var f=e.defer(),d=0;j(o,function(e){v.hasOwnProperty(e)&&!r.hasOwnProperty(e)&&(d++,v[e].then(function(t){y[e]=t,--d||c()},u))}),d||c(),v[n]=f.promise}(g[w],g[w+1],g[w+2]);return p}},this.resolve=function(e,t,n,r){return this.study(e)(t,n,r)}}function g(e,t,n){this.fromConfig=function(e,t,n){return N(e.template)?this.fromString(e.template,t):N(e.templateUrl)?this.fromUrl(e.templateUrl,t):N(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return R(e)?e(t):e},this.fromUrl=function(n,r){return R(n)&&(n=n(r)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,r){return n.invoke(e,null,r||{params:t})}}function v(e,t,i){function o(t,n,r,i){if(g.push(t),h[t])return h[t];if(!/^\w+(-+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(m[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return m[t]=new H.Param(t,n,r,i),m[t]}function a(e,t,n,r){var i=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:i=["(",")"+(r?"?":"")];break;case!0:i=["?(",")?"];break;default:i=["("+n+"|",")?"]}return o+i[0]+t+i[1]}function s(i,o){var a,s,l,u,c;return a=i[2]||i[3],c=t.params[a],l=e.substring(d,i.index),s=o?i[4]:i[4]||("*"==i[1]?".*":null),u=H.type(s||"string")||r(H.type("string"),{pattern:new RegExp(s,t.caseInsensitive?"i":n)}),{id:a,regexp:s,segment:l,type:u,cfg:c}}t=L({params:{}},P(t)?t:{});var l,u=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,c=/([:]?)([\w\[\]-]+)|\{([\w\[\]-]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,f="^",d=0,p=this.segments=[],h=i?i.params:{},m=this.params=i?i.params.$$new():new H.ParamSet,g=[];this.source=e;for(var v,y,b;(l=u.exec(e))&&(v=s(l,!1),!(v.segment.indexOf("?")>=0));)y=o(v.id,v.type,v.cfg,"path"),f+=a(v.segment,y.type.pattern.source,y.squash,y.isOptional),p.push(v.segment),d=u.lastIndex;b=e.substring(d);var $=b.indexOf("?");if($>=0){var w=this.sourceSearch=b.substring($);if(b=b.substring(0,$),this.sourcePath=e.substring(0,d+$),w.length>0)for(d=0;l=c.exec(w);)v=s(l,!0),y=o(v.id,v.type,v.cfg,"search"),d=u.lastIndex}else this.sourcePath=e,this.sourceSearch="";f+=a(b)+(!1===t.strict?"/?":"")+"$",p.push(b),this.regexp=new RegExp(f,t.caseInsensitive?"i":n),this.prefix=p[0],this.$$paramNames=g}function y(e){L(this,e)}function b(){function e(e){return null!=e?e.toString().replace(/\//g,"%2F"):e}function i(e){return null!=e?e.toString().replace(/%2F/g,"/"):e}function o(){return{strict:m,caseInsensitive:d}}function l(e){return R(e)||F(e)&&R(e[e.length-1])}function u(){for(;x.length;){var e=x.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend($[e.name],f.invoke(e.def))}}function c(e){L(this,e||{})}H=this;var f,d=!1,m=!0,g=!1,$={},w=!0,x=[],C={string:{encode:e,decode:i,is:function(e){return null==e||!N(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return N(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};b.$$getDefaultValue=function(e){if(!l(e.value))return e.value;if(!f)throw new Error("Injectable functions cannot be called at configuration time");return f.invoke(e.value)},this.caseInsensitive=function(e){return N(e)&&(d=e),d},this.strictMode=function(e){return N(e)&&(m=e),m},this.defaultSquashPolicy=function(e){if(!N(e))return g;if(!0!==e&&!1!==e&&!I(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return g=e,e},this.compile=function(e,t){return new v(e,L(o(),t))},this.isMatcher=function(e){if(!P(e))return!1;var t=!0;return j(v.prototype,function(n,r){R(n)&&(t=t&&N(e[r])&&R(e[r]))}),t},this.type=function(e,t,n){if(!N(t))return $[e];if($.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return $[e]=new y(L({name:e},t)),n&&(x.push({name:e,def:n}),w||u()),this},j(C,function(e,t){$[t]=new y(L({name:t},e))}),$=r($,{}),this.$get=["$injector",function(e){return f=e,w=!1,u(),j(C,function(e,t){$[t]||($[t]=new y(e))}),this}],this.Param=function(e,t,r,i){function o(){if(!f)throw new Error("Injectable functions cannot be called at configuration time");var e=f.invoke(r.$$fn);if(null!==e&&e!==n&&!d.type.is(e))throw new Error("Default value ("+e+") for parameter '"+d.id+"' is not an instance of Type ("+d.type.name+")");return e}function u(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=h(p(d.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),N(e)?d.type.$normalize(e):o()}function c(){return"{Param:"+e+" "+t+" squash: '"+b+"' optional: "+v+"}"}var d=this;r=function(e){var t=P(e)?a(e):[];return-1===s(t,"value")&&-1===s(t,"type")&&-1===s(t,"squash")&&-1===s(t,"array")&&(e={value:e}),e.$$fn=l(e.value)?e.value:function(){return e.value},e}(r),t=function(t,n,r){if(t.type&&n)throw new Error("Param '"+e+"' has two type configurations.");return n||(t.type?t.type instanceof y?t.type:new y(t.type):"config"===r?$.any:$.string)}(r,t,i);var m=function(){var t={array:"search"===i&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return L(t,n,r).array}();t=m?t.$asArray(m,"search"===i):t,"string"!==t.name||m||"path"!==i||r.value!==n||(r.value="");var v=r.value!==n,b=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!N(n)||null==n)return g;if(!0===n||I(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,v),w=function(e,t,r,i){var o,a,l=[{from:"",to:r||t?n:""},{from:null,to:r||t?n:""}];return o=F(e.replace)?e.replace:[],I(i)&&o.push({from:i,to:n}),a=h(o,function(e){return e.from}),p(l,function(e){return-1===s(a,e.from)}).concat(o)}(r,m,v,b);L(this,{id:e,type:t,location:i,array:m,squash:b,replace:w,isOptional:v,value:u,dynamic:n,config:r,toString:c})},c.prototype={$$new:function(){return r(this,L(new c,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,r=a(c.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),j(t,function(t){j(a(t),function(t){-1===s(e,t)&&-1===s(r,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return j(n.$$keys(),function(r){t[r]=n[r].value(e&&e[r])}),t},$$equals:function(e,t){var n=!0,r=this;return j(r.$$keys(),function(i){var o=e&&e[i],a=t&&t[i];r[i].type.equals(o,a)||(n=!1)}),n},$$validates:function(e){var r,i,o,a,s,l=this.$$keys();for(r=0;ri;i++)if(t(u[i]))return;c&&t(c)}}function p(){return l=l||i.$on("$locationChangeSuccess",d)}var h,m=a.baseHref(),g=r.url();return f||p(),{sync:function(){d()},listen:function(){return p()},update:function(e){return e?void(g=r.url()):void(r.url()!==g&&(r.url(g),r.replace()))},push:function(e,t,i){var o=e.format(t||{});null!==o&&t&&t["#"]&&(o+="#"+t["#"]),r.url(o),h=i&&i.$$avoidResync?r.url():n,i&&i.replace&&r.replace()},href:function(n,i,o){if(!n.validates(i))return null;var a=e.html5Mode();t.isObject(a)&&(a=a.enabled);var l=n.format(i);if(o=o||{},a||null===l||(l="#"+e.hashPrefix()+l),null!==l&&i&&i["#"]&&(l+="#"+i["#"]),l=s(l,a,o.absolute),!o.absolute||!l)return l;var u=!a&&l?"/":"",c=r.port();return c=80===c||443===c?"":":"+c,[r.protocol(),"://",r.host(),c,u,l].join("")}}}var l,u=[],c=null,f=!1;this.rule=function(e){if(!R(e))throw new Error("'rule' must be a function");return u.push(e),this},this.otherwise=function(e){if(I(e)){var t=e;e=function(){return t}}else if(!R(e))throw new Error("'rule' must be a function");return c=e,this},this.when=function(e,t){var n,s=I(t);if(I(e)&&(e=r.compile(e)),!s&&!R(t)&&!F(t))throw new Error("invalid 'handler' in when()");var l={matcher:function(e,t){return s&&(n=r.compile(t),t=["$match",function(e){return n.format(e)}]),L(function(n,r){return a(n,t,e.exec(r.path(),r.search()))},{prefix:I(e.prefix)?e.prefix:""})},regex:function(e,t){if(e.global||e.sticky)throw new Error("when() RegExp must not be global or sticky");return s&&(n=t,t=["$match",function(e){return o(n,e)}]),L(function(n,r){return a(n,t,e.exec(r.path()))},{prefix:i(e)})}},u={matcher:r.isMatcher(e),regex:e instanceof RegExp};for(var c in u)if(u[c])return this.rule(l[c](e,t));throw new Error("invalid 'what' in when()")},this.deferIntercept=function(e){e===n&&(e=!0),f=e},this.$get=s,s.$inject=["$location","$rootScope","$injector","$browser"]}function w(e,i){function o(e){return 0===e.indexOf(".")||0===e.indexOf("^")}function d(e,t){if(!e)return n;var r=I(e),i=r?e:e.name;if(o(i)){if(!t)throw new Error("No reference point given for path '"+i+"'");t=d(t);for(var a=i.split("."),s=0,l=a.length,u=t;l>s;s++)if(""!==a[s]||0!==s){if("^"!==a[s])break;if(!u.parent)throw new Error("Path '"+i+"' not valid for state '"+t.name+"'");u=u.parent}else u=t;a=a.slice(s).join("."),i=u.name+(u.name&&a?".":"")+a}var c=E[i];return!c||!r&&(r||c!==e&&c.self!==e)?n:c}function p(e,t){S[e]||(S[e]=[]),S[e].push(t)}function m(e){for(var t=S[e]||[];t.length;)g(t.shift())}function g(t){t=r(t,{self:t,resolve:t.resolve||{},toString:function(){return this.name}});var n=t.name;if(!I(n)||n.indexOf("@")>=0)throw new Error("State must have a valid name");if(E.hasOwnProperty(n))throw new Error("State '"+n+"'' is already defined");var i=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):I(t.parent)?t.parent:P(t.parent)&&I(t.parent.name)?t.parent.name:"";if(i&&!E[i])return p(i,t.self);for(var o in M)R(M[o])&&(t[o]=M[o](t,M.$delegates[o]));return E[n]=t,!t[_]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){k.$current.navigable==t&&u(e,n)||k.transitionTo(t,e,{inherit:!0,location:!1})}]),m(n),t}function v(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=k.$current.name.split("."),r=0,i=t.length;i>r;r++)"*"===t[r]&&(n[r]="*");return"**"===t[0]&&(n=n.slice(s(n,t[1])),n.unshift("**")),"**"===t[t.length-1]&&(n.splice(s(n,t[t.length-2])+1,Number.MAX_VALUE),n.push("**")),t.length==n.length&&n.join("")===t.join("")}function b(e,t){return I(e)&&!N(t)?M[e]:R(t)&&I(e)?(M[e]&&!M.$delegates[e]&&(M.$delegates[e]=M[e]),M[e]=t,this):this}function $(e,t){return P(e)?t=e:t.name=e,g(t),this}function w(e,i,o,s,f,p,m,g,b){function $(t,n,r,o){var a=e.$broadcast("$stateNotFound",t,n,r);if(a.defaultPrevented)return m.update(),T;if(!a.retry)return null;if(o.$retry)return m.update(),D;var s=k.transition=i.when(a.retry);return s.then(function(){return s!==k.transition?S:(t.options.$retry=!0,k.transitionTo(t.to,t.toParams,t.options))},function(){return T}),m.update(),s}function w(e,n,r,a,l,u){function d(){var n=[];return j(e.views,function(r,i){var a=r.resolve&&r.resolve!==e.resolve?r.resolve:{};a.$template=[function(){return o.load(i,{view:r,locals:l.globals,params:p,notify:u.notify})||""}],n.push(f.resolve(a,l.globals,l.resolve,e).then(function(n){if(R(r.controllerProvider)||F(r.controllerProvider)){var o=t.extend({},a,l.globals);n.$$controller=s.invoke(r.controllerProvider,null,o)}else n.$$controller=r.controller;n.$$state=e,n.$$controllerAs=r.controllerAs,l[i]=n}))}),i.all(n).then(function(){return l.globals})}var p=r?n:c(e.params.$$keys(),n),h={$stateParams:p};l.resolve=f.resolve(e.resolve,h,l.resolve,e);var m=[l.resolve.then(function(e){l.globals=e})];return a&&m.push(a),i.all(m).then(d).then(function(e){return l})}var S=i.reject(new Error("transition superseded")),M=i.reject(new Error("transition prevented")),T=i.reject(new Error("transition aborted")),D=i.reject(new Error("transition failed"));return C.locals={resolve:null,globals:{$stateParams:{}}},k={params:{},current:C.self,$current:C,transition:null},k.reload=function(e){return k.transitionTo(k.current,p,{reload:e||!0,inherit:!1,notify:!0})},k.go=function(e,t,n){return k.transitionTo(e,t,L({inherit:!0,relative:k.$current},n))},k.transitionTo=function(t,n,o){n=n||{},o=L({location:!0,inherit:!1,relative:null,notify:!0,reload:!1,$retry:!1},o||{});var a,u=k.$current,f=k.params,h=u.path,g=d(t,o.relative),v=n["#"];if(!N(g)){var y={to:t,toParams:n,options:o},b=$(y,u.self,f,o);if(b)return b;if(t=y.to,n=y.toParams,o=y.options,g=d(t,o.relative),!N(g)){if(!o.relative)throw new Error("No such state '"+t+"'");throw new Error("Could not resolve '"+t+"' from state '"+o.relative+"'")}}if(g[_])throw new Error("Cannot transition to abstract state '"+t+"'");if(o.inherit&&(n=l(p,n||{},k.$current,g)),!g.params.$$validates(n))return D;n=g.params.$$values(n),t=g;var E=t.path,T=0,A=E[T],O=C.locals,R=[];if(o.reload){if(I(o.reload)||P(o.reload)){if(P(o.reload)&&!o.reload.name)throw new Error("Invalid reload state object");var F=!0===o.reload?h[0]:d(o.reload);if(o.reload&&!F)throw new Error("No such reload state '"+(I(o.reload)?o.reload:o.reload.name)+"'");for(;A&&A===h[T]&&A!==F;)O=R[T]=A.locals,T++,A=E[T]}}else for(;A&&A===h[T]&&A.ownParams.$$equals(n,f);)O=R[T]=A.locals,T++,A=E[T];if(x(t,n,u,f,O,o))return v&&(n["#"]=v),k.params=n,U(k.params,p),o.location&&t.navigable&&t.navigable.url&&(m.push(t.navigable.url,n,{$$avoidResync:!0,replace:"replace"===o.location}),m.update(!0)),k.transition=null,i.when(k.current);if(n=c(t.params.$$keys(),n||{}),o.notify&&e.$broadcast("$stateChangeStart",t.self,n,u.self,f).defaultPrevented)return e.$broadcast("$stateChangeCancel",t.self,n,u.self,f),m.update(),M;for(var j=i.when(O),H=T;H=T;r--)a=h[r],a.self.onExit&&s.invoke(a.self.onExit,a.self,a.locals.globals),a.locals=null;for(r=T;r=0?i:i+"@"+(o?o.state.name:"")}function _(e,t){var n,r=e.match(/^\s*({[^}]*})\s*$/);if(r&&(e=t+"("+r[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function M(e){var t=e.parent().inheritedData("$uiView");return t&&t.state&&t.state.name?t.state:void 0}function T(e,n){var r=["location","inherit","reload","absolute"];return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(i,o,a,s){var l=_(a.uiSref,e.current.name),u=null,c=M(o)||e.$current,f="[object SVGAnimatedString]"===Object.prototype.toString.call(o.prop("href"))?"xlink:href":"href",d=null,p="A"===o.prop("tagName").toUpperCase(),h="FORM"===o[0].nodeName,m=h?"action":f,g=!0,v={relative:c,inherit:!0},y=i.$eval(a.uiSrefOpts)||{};t.forEach(r,function(e){e in y&&(v[e]=y[e])});var b=function(n){if(n&&(u=t.copy(n)),g){d=e.href(l.state,u,v);var r=s[1]||s[0];return r&&r.$$addStateInfo(l.state,u),null===d?(g=!1,!1):void a.$set(m,d)}};l.paramExpr&&(i.$watch(l.paramExpr,function(e,t){e!==u&&b(e)},!0),u=t.copy(i.$eval(l.paramExpr))),b(),h||o.bind("click",function(t){if(!((t.which||t.button)>1||t.ctrlKey||t.metaKey||t.shiftKey||o.attr("target"))){var r=n(function(){e.go(l.state,u,v)});t.preventDefault();var i=p&&!d?1:0;t.preventDefault=function(){i--<=0&&n.cancel(r)}}})}}}function D(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs",function(t,r,i){function o(){a()?r.addClass(l):r.removeClass(l)}function a(){for(var e=0;er;r++){o=a[r];var c=this.params[o],f=n[r+1];for(i=0;ir;r++)o=a[r],u[o]=this.params[o].value(t[o]);return u},v.prototype.parameters=function(e){return N(e)?this.params[e]||null:this.$$paramNames},v.prototype.validates=function(e){return this.params.$$validates(e)},v.prototype.format=function(e){function t(e){return encodeURIComponent(e).replace(/-/g,function(e){return"%5C%"+e.charCodeAt(0).toString(16).toUpperCase()})}e=e||{};var n=this.segments,r=this.parameters(),i=this.params;if(!this.validates(e))return null;var o,a=!1,s=n.length-1,l=r.length,u=n[0];for(o=0;l>o;o++){var c=s>o,f=r[o],d=i[f],p=d.value(e[f]),m=d.isOptional&&d.type.equals(d.value(),p),g=!!m&&d.squash,v=d.type.encode(p);if(c){var y=n[o+1];if(!1===g)null!=v&&(u+=F(v)?h(v,t).join("-"):encodeURIComponent(v)),u+=y;else if(!0===g){var b=u.match(/\/$/)?/\/?(.*)/:/(.*)/;u+=y.match(b)[1]}else I(g)&&(u+=g+y)}else{if(null==v||m&&!1!==g)continue;F(v)||(v=[v]),v=h(v,encodeURIComponent).join("&"+f+"="),u+=(a?"&":"?")+f+"="+v,a=!0}}return u},y.prototype.is=function(e,t){return!0},y.prototype.encode=function(e,t){return e},y.prototype.decode=function(e,t){return e},y.prototype.equals=function(e,t){return e==t},y.prototype.$subPattern=function(){var e=this.pattern.toString();return e.substr(1,e.length-2)},y.prototype.pattern=/.*/,y.prototype.toString=function(){return"{Type:"+this.name+"}"},y.prototype.$normalize=function(e){return this.is(e)?e:this.decode(e)},y.prototype.$asArray=function(e,t){function r(e,t){function r(e,t){return function(){return e[t].apply(e,arguments)}}function i(e){return F(e)?e:N(e)?[e]:[]}function o(e){switch(e.length){case 0:return n;case 1:return"auto"===t?e[0]:e;default:return e}}function a(e){return!e}function s(e,t){return function(n){n=i(n);var r=h(n,e) +;return!0===t?0===p(r,a).length:o(r)}}this.encode=s(r(e,"encode")),this.decode=s(r(e,"decode")),this.is=s(r(e,"is"),!0),this.equals=function(e){return function(t,n){var r=i(t),o=i(n);if(r.length!==o.length)return!1;for(var a=0;a=":n(e.from)}:{"<=":n(e.to)}}function o(e){return e.in?{IN:e.in}:{"NOT IN":e.nin}}return{extend:function(t){return e.assign(Object.create(this),t)},compactFilters:function(t){return t?e.pick(t,function(e){return 0===e||!1===e||!!e}):null},processFilters:function(t){return t?(t=this.compactFilters(t),e.transform(t,function(e,t,n){t.from||t.to?e[n]=i(t):t.in||t.nin?e[n]=o(t):e[n]=t},{})):null}}})}),define("common/models/contact-job-role.model",["common/modules/models","common/models/model","common/instances/contact-job-role-instance.instance","common/services/api/contact-job-role-api.api"],function(e){"use strict";e.factory("ContactJobRole",["$log","Model","ContactJobRoleAPI","ContactJobRoleInstance",function(e,t,n,r){return e.debug("ContactJobRole"),t.extend({all:function(e){return n.all(e).then(function(e){return e.list.map(function(e){return r.init(e,!0)})})}})}])}),define("common/models/instances/group-instance",["common/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("GroupInstance",["ModelInstance",function(e){var t=["id","name","title","description"];return e.extend({fromAPIFilter:function(e,n,r){_.includes(t,r)&&(e[r]=this[r])}})}])}),define("common/mocks/module",["common/angular"],function(e){"use strict";return e.module("common.mocks",[])}),define("common/mocks/services/api/group-mock",["common/lodash","common/mocks/module"],function(e,t){"use strict";t.factory("api.group.mock",["$q",function(t){function n(e){var n=t.defer();return n.resolve(e),n.promise}return{all:function(e,t,r){var i,o,a;return i=r||this.mockedGroups().list,e&&(i=i.filter(function(t){return Object.keys(e).every(function(n){return t[n]===e[n]})})),t&&(o=(t.page-1)*t.size,a=o+t.size,i=i.slice(o,a)),n({list:i,total:i.length,allIds:i.map(function(e){return e.id}).join(",")})},find:function(e,t){return n(t||this.mockedGroups().list.filter(function(t){return t.id===e})[0])},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedGroups:function(){return{total:5,list:[{id:"1",name:"Administrators",title:"Administrators",description:"Contacts in this group are assigned Administrator role permissions.",is_active:"1",visibility:"User and User Admin Only",group_type:["1"],is_hidden:"0",is_reserved:"0"},{id:"2",name:"Newsletter Subscribers",title:"Newsletter Subscribers",is_active:'"1',visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"3",name:"Summer Program Volunteers",title:"Summer Program Volunteers",is_active:"1",visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"4",name:"Advisory Board",title:"Advisory Board",is_active:"1",visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"5",name:"Case_Resources",title:"Case Resources",description:"Contacts in this group are listed with their phone number and email when viewing case. You also can send copies of case activities to these contacts.",is_active:"1",visibility:"User and User Admin Only",where_clause:"...",select_tables:"...",where_tables:"...",group_type:"2",is_hidden:"0",is_reserved:"0"}]}}}}])}),define("common/mocks/data/contact.data",[],function(){return{all:{is_error:0,version:3,count:26,values:[{id:"1",contact_id:"1",display_name:"Dr. Kiara Jensen-Parker",email:"kh.jensen-parker@testing.info",contact_type:"Individual"},{id:"2",contact_id:"2",display_name:"jacobc82@lol.co.pl",email:"cruz.v.jacob@spamalot.com",contact_type:"Individual"},{id:"3",contact_id:"3",display_name:"Mei Müller-Nielsen",email:"mz.mller-nielsen75@infomail.co.pl",contact_type:"Individual"},{id:"4",contact_id:"4",display_name:"Ms. Brigette Deforest",email:"deforest.p.brigette9@fakemail.info",contact_type:"Individual"},{id:"5",contact_id:"5",display_name:"robertsc@testing.net",email:"clintr56@mymail.org",contact_type:"Individual"},{id:"6",contact_id:"6",display_name:"Dr. Allen Samuels Sr.",email:"samuelsa@mymail.org",contact_type:"Individual"},{id:"7",contact_id:"7",display_name:"Mei Wilson",email:"wilson.u.mei59@sample.org",contact_type:"Individual"},{id:"8",contact_id:"8",display_name:"Dr. Betty Díaz",email:"dazb@sample.co.nz",contact_type:"Individual"},{id:"9",contact_id:"9",display_name:"Bob Jones-Dimitrov",email:"bobj@testmail.biz",contact_type:"Individual"},{id:"10",contact_id:"10",display_name:"Truman Samuels III",email:"trumans@spamalot.org",contact_type:"Individual"},{id:"11",contact_id:"11",display_name:"Iris Wagner",email:"iwagner75@notmail.info",contact_type:"Individual"},{id:"12",contact_id:"12",display_name:"Mr. Rosario McReynolds",email:"rosariomcreynolds@testmail.org",contact_type:"Individual"},{id:"13",contact_id:"13",display_name:"Shad Jones-Dimitrov III",email:"shadj@lol.net",contact_type:"Individual"},{id:"14",contact_id:"14",display_name:"Toby Cruz Sr.",email:"",contact_type:"Individual"},{id:"15",contact_id:"15",display_name:"lareedaz61@testing.com",email:"lareedaz61@testing.com",contact_type:"Individual"},{id:"16",contact_id:"16",display_name:"Dr. Jay Deforest",email:"jayd@fishmail.org",contact_type:"Individual"},{id:"17",contact_id:"17",display_name:"Mr. Norris Cruz",email:"norriscruz@spamalot.info",contact_type:"Individual"},{id:"18",contact_id:"18",display_name:"herminiac@fishmail.com",email:"herminiac@fishmail.com",contact_type:"Individual"},{id:"19",contact_id:"19",display_name:"Ashley Terrell",email:"terrell.ashley@testmail.info",contact_type:"Individual"},{id:"20",contact_id:"20",display_name:"Kandace Parker-Díaz",email:"parker-daz.kandace67@fishmail.co.uk",contact_type:"Individual"},{id:"21",contact_id:"21",display_name:"Nicole Samuels",email:"ng.samuels@testmail.net",contact_type:"Individual"},{id:"22",contact_id:"22",display_name:"Dr. Kandace Wattson",email:"kandacewattson@testing.info",contact_type:"Individual"},{id:"23",contact_id:"23",display_name:"Brittney Cruz",email:"cruz.brittney@spamalot.co.nz",contact_type:"Individual"},{id:"24",contact_id:"24",display_name:"Shauna Olsen",email:"",contact_type:"Individual"},{id:"202",contact_id:"202",display_name:"civihr_staff@compucorp.co.uk",email:"civihr_staff@compucorp.co.uk",contact_type:"Individual"},{id:"203",contact_id:"203",display_name:"civihr_manager@compucorp.co.uk",email:"civihr_manager@compucorp.co.uk",contact_type:"Individual"}]}}}),define("common/mocks/services/api/contact-mock",["common/lodash","common/mocks/module","common/mocks/data/contact.data"],function(e,t,n){"use strict";t.factory("api.contact.mock",["$q",function(t){function r(e){var n=t.defer();return n.resolve(e),n.promise}return{all:function(t,i,o,a,s){var l,u,c;return l=s||n.all.values,t&&(l=l.filter(function(n){return Object.keys(t).every(function(r){return null===t[r]||("display_name"===r?new RegExp(t[r],"i").test(n[r]):t[r].IN?e.includes(t[r].IN,n[r]):n[r]===t[r])})})),i&&(u=(i.page-1)*i.size,c=u+i.size,l=l.slice(u,c)),r({list:l,total:l.length,allIds:l.map(function(e){return e.id}).join(",")})},find:function(e,t){return r(t||n.all.values.filter(function(t){return t.id===e})[0])},leaveManagees:function(){return r(this.mockedContacts().list)},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedContacts:function(){var e=n.all.values;return{total:e.length,list:e.map(function(e){return e})}}}}])}),define("common/mocks/services/api/group-contact-mock",["common/lodash","common/mocks/module","common/mocks/services/api/contact-mock","common/mocks/services/api/group-mock"],function(e,t){"use strict";t.factory("api.group-contact.mock",["$q","api.contact.mock","api.group.mock",function(t,n,r){function i(t){return e.sample(t)}function o(e){var n=t.defer();return n.resolve(e),n.promise}var a=n.mockedContacts().list,s=r.mockedGroups().list;return{all:function(e,t,n){var r,i,a;return r=n||this.mockedGroupsContacts.list,e&&(r=r.filter(function(t){return Object.keys(e).every(function(n){return t[n]===e[n]})})),t&&(i=(t.page-1)*t.size,a=i+t.size,r=r.slice(i,a)),o({list:r,total:r.length,allIds:r.map(function(e){return e.id}).join(",")})},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedGroupsContacts:{total:a.length,list:function(){var e=1;return a.map(function(t){return{id:""+e++,group_id:i(s).id,contact_id:t.id,status:"Added"}})}()}}}])}),define("common/models/group",["common/modules/models","common/models/model","common/models/instances/group-instance","common/mocks/services/api/group-mock","common/mocks/services/api/group-contact-mock"],function(e){"use strict";e.factory("Group",["Model","api.group.mock","api.group-contact.mock","GroupInstance",function(e,t,n,r){return e.extend({all:function(e,n){return t.all(this.processFilters(e),n).then(function(e){return e.list=e.list.map(function(e){return r.init(e,!0)}),e})},find:function(e){return t.find(e).then(function(e){return r.init(e,!0)})},contactIdsOf:function(e){return n.all({group_id:e}).then(function(e){return e.list.map(function(e){return e.contact_id})})}})}])}),define("common/models/instances/job-role-instance",["common/lodash","common/moment","common/modules/models-instances","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("JobRoleInstance",["ModelInstance","HR_settings",function(n,r){return n.extend({fromAPIFilter:function(n,i,o){var a=r.DATE_FORMAT.toUpperCase();e.endsWith(o,"_date")?n[o]=t(this[o],"YYYY-MM-DD HH:mm:ss").format(a):"api.HRJobContract.getsingle"===o?(n.contact_id=this[o].contact_id,n.job_contract_id=this[o].id):n[o]=this[o]},toAPIFilter:function(n,i,o){var a=["contact_id","job_contract_id"],s=r.DATE_FORMAT.toUpperCase();if(e.endsWith(o,"_date"))n[o]=t(this[o],s).format("YYYY-MM-DD HH:mm:ss");else{if(e.includes(a,o))return;n[o]=this[o]}}})}])}),define("common/services/api/job-role",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.job-role",["$log","api",function(e,t){return e.debug("api.jobRole"),t.extend({all:function(t,n,r,i){return e.debug("api.jobRole.api"),this.getAll("HrJobRoles",t,n,r,i)},find:function(t){return e.debug("api.jobRole.find"),this.sendGET("HRJobRole","get",{id:""+t},!1).then(function(e){return e.values[0]})}})}])}),define("common/models/job-role",["common/modules/models","common/models/model","common/models/instances/job-role-instance","common/services/api/job-role"],function(e){"use strict";e.factory("JobRole",["Model","api.job-role","JobRoleInstance",function(e,t,n){return e.extend({all:function(e,r){return t.all(this.processFilters(e),r).then(function(e){return e.list=e.list.map(function(e){return n.init(e,!0)}),e})},find:function(e){return t.find(e).then(function(e){return n.init(e,!0)})}})}])}),define("common/services/api/contact",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.contact",["$log","api",function(e,t){return e.debug("api.contact"),t.extend({all:function(t,n,r,i){return e.debug("api.contact.api"),this.getAll("Contact",t,n,r,i)},find:function(t){return e.debug("api.contact.find"),this.sendGET("Contact","get",{id:""+t},!1).then(function(e){return e.values[0]})},leaveManagees:function(t,n){return e.debug("api.contact.leaveManagees"),n=_.assign({},n,{managed_by:t}),this.sendGET("Contact","getleavemanagees",n).then(function(e){return e.values})}})}])}),define("common/models/instances/contact-instance",["common/modules/models-instances","common/models/instances/instance","common/services/api/contact"],function(e){"use strict";e.factory("ContactInstance",["ModelInstance","api.contact",function(e,t){return e.extend({leaveManagees:function(e){return t.leaveManagees(this.id,e)}})}])}),define("common/models/contact",["common/lodash","common/modules/models","common/models/model","common/models/contact-job-role.model","common/models/group","common/models/job-role","common/models/instances/contact-instance","common/services/api/contact"],function(e,t){"use strict";t.factory("Contact",["$q","Model","api.contact","Group","JobRole","ContactJobRole","ContactInstance",function(t,n,r,i,o,a,s){function l(t,n){return!e.isEmpty(e.intersection(e.keys(t),n))}function u(e){return a.all(e).then(function(e){return e.map(function(e){return e.contact_id})})}function c(t,n){return e(t).omit(d).omit(p).assign({id:{in:e.intersection.apply(null,n)}}).value()}function f(n){var r=t.defer(),o=[];return n=this.compactFilters(n),l(n,p)&&o.push(u(e.pick(n,p))),l(n,d)&&o.push(i.contactIdsOf(n.group_id)),e.isEmpty(o)?r.resolve(this.processFilters(n)):t.all(o).then(function(e){n=c(n,e),r.resolve(this.processFilters(n))}.bind(this)),r.promise}var d=["group_id"],p=["region","department","level_type","location"];return n.extend({all:function(e,t,n,i){return f.call(this,e).then(function(e){return e&&e.id&&!e.id.IN.length?{list:[]}:r.all(e,t,n,i)}).then(function(e){return e.list=e.list.map(function(e){return s.init(e,!0)}),e})},find:function(e){return r.find(e).then(function(e){return s.init(e,!0)})},leaveManagees:function(e,t){return f.call(this,t).then(function(t){return t&&t.id&&!t.id.IN.length?[]:r.leaveManagees(e,t)})}})}])}),define("common/models/instances/contract-instance",["common/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("ContractInstance",["ModelInstance",function(e){return e.extend({})}])}),define("common/services/api/contract",["common/lodash","common/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("api.contract",["$log","api",function(t,n){function r(t){var n=e.clone(t);return n.info=n["api.HRJobContract.getfulldetails"],delete n["api.HRJobContract.getfulldetails"],n}return t.debug("api.contract"),n.extend({all:function(e){return t.debug("ContractAPI.all"),e=e||{},e["api.HRJobContract.getfulldetails"]={jobcontract_id:"$value.id"},e.deleted=0,this.sendGET("HRJobContract","get",e,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r)})}})}])}),define("common/models/contract",["common/modules/models","common/models/model","common/models/instances/contract-instance","common/services/api/contract"],function(e){"use strict";e.factory("Contract",["$log","Model","api.contract","ContractInstance",function(e,t,n,r){return e.debug("Contract"),t.extend({all:function(e){return n.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})}})}])}),define("common/models/option-group",["common/modules/models","common/models/model","common/services/api/option-group"],function(e){"use strict";e.factory("OptionGroup",["Model","api.optionGroup",function(e,t){return e.extend({valuesOf:function(e,n,r){return t.valuesOf(e,n,r)}})}])}),function(e,t){define("common/models/session.model",["common/modules/models","common/models/model"],function(n){"use strict";n.factory("Session",["$log","$q","Model",function(n,r,i){return n.debug("Session"),i.extend({get:function(){var n={contactId:e.vars.session?e.vars.session.contact_id:t.settings.currentCiviCRMUserId};if(!n.contactId)throw new Error("Session Error: *Logged In Contact Id* is not defined");return r.resolve(n)}})}])})}(CRM,window.Drupal),define("common/bundles/models",["common/instances/contact-job-role-instance.instance","common/models/model","common/models/contact","common/models/contact-job-role.model","common/models/contract","common/models/group","common/models/job-role","common/models/option-group","common/models/session.model","common/models/instances/instance","common/models/instances/contact-instance","common/models/instances/contract-instance","common/models/instances/group-instance","common/models/instances/job-role-instance"],function(){}),define("common/services/dialog/dialog",["common/lodash","common/modules/services"],function(e,t){"use strict";function n(t,n,r){function i(i){var o;if(!e.isObject(i))throw new Error("Dialog Service: Options passed should be an object");return o=n.children(),t.open({appendTo:o.length?o.eq(0):n,size:"sm",controller:"DialogController",template:r.get("dialog.html"),resolve:{options:function(){return i}}}).result}return{open:i}}t.factory("dialog",n),n.$inject=["$uibModal","$rootElement","$templateCache"]}),define("common/controllers/dialog/dialog-ctrl",["common/lodash","common/modules/controllers"],function(e,t){"use strict";function n(t,n,r,i){function o(t){e.assign(n,e.defaultsDeep(t,{title:"CiviHR",msg:"",copyConfirm:"",copyCancel:"",classConfirm:"btn-primary",loading:!1}))}function a(){r.close(!1)}function s(){n.loading=!0,r.closed.then(n.onCloseAfterConfirm),t.resolve().then(n.onConfirm).then(function(){r.close(!0)})}n.cancel=a,n.confirm=s,function(){o(i),i.optionsPromise&&i.optionsPromise().then(function(e){o(e)})}()}t.controller("DialogController",n),n.$inject=["$q","$scope","$uibModalInstance","options"]}),define("common/modules/dialog",["common/angular","common/services/dialog/dialog","common/controllers/dialog/dialog-ctrl","common/angularBootstrap","common/directives/loading","common/modules/templates"],function(e){"use strict";return e.module("common.dialog",["ui.bootstrap","common.directives","common.templates"])}),define("common/decorators/xeditable-civi/editable-directive-factory",[],function(){"use strict";return["$delegate",function(e){return function(t){var n=e(t);return n.compile=function(e){var t,r=e[0].attributes.getNamedItem("ng-href");return e.append(''),r&&(t=angular.element(""),t.text("Follow link"),t.attr(r.nodeName,r.value),t.attr("ng-click","$event.stopPropagation();"),t.addClass("editable-link"),e.append(t),e.addClass("editable-with-link")),{post:n.link}},n}}]}),define("common/directives/xeditable-civi/editable-ta",[],function(){"use strict";return["editableDirectiveFactory","$timeout",function(e,t){var n,r;return r=e({directiveName:"editableTa",inputTpl:"",render:function(){this.parent.render.call(this),this.inputEl.parent().parent().removeClass("form-inline"),this.inputEl.addClass("editable-ta"),this.inputEl.attr("ng-model","ta.$data"),this.inputEl.attr("ta-toolbar",this.attrs.eTaToolbar||'[["bold","italics","underline","strikeThrough","ul","ol","undo","redo","clear"]]'),t(function(){this.inputEl.find("textarea").hide()}.bind(this),0)},save:function(){this.scope.$data=this.scope.ta.$data,this.parent.save.call(this)},setLocalValue:function(){this.parent.setLocalValue.call(this),this.scope.ta.$data=this.scope.$data}}),n=r.link,r.link=function(e,t,r,i){return e.ta={},n(e,t,r,i)},r}]}),define("common/modules/xeditable-civi",["common/angular","common/decorators/xeditable-civi/editable-directive-factory","common/directives/xeditable-civi/editable-ta","common/angularXeditable","common/text-angular"],function(e,t,n){"use strict";return e.module("xeditable-civi",["xeditable","textAngular"]).directive("editableTa",n)}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/org.civicrm.reqangular/dist/reqangular.min.js.map \ No newline at end of file diff --git a/org.civicrm.reqangular/src/common/models/option-group.js b/org.civicrm.reqangular/src/common/models/option-group.js index 0a503a14f7a..a05bb58aece 100644 --- a/org.civicrm.reqangular/src/common/models/option-group.js +++ b/org.civicrm.reqangular/src/common/models/option-group.js @@ -18,11 +18,12 @@ define([ * @param {String|Array} names * Bases on the type of the parameter, the method will return * either an array of values (string) or an object (array) + * @param {Object} params optional parameters for the query * @param {Boolean} cache optional parameter to cache the query or not * @return {Promise} */ - valuesOf: function (names, cache) { - return optionGroupAPI.valuesOf(names, cache); + valuesOf: function (names, params, cache) { + return optionGroupAPI.valuesOf(names, params, cache); } }); } diff --git a/org.civicrm.reqangular/test/models/option-group.spec.js b/org.civicrm.reqangular/test/models/option-group.spec.js index d96201ab043..73bc12d7692 100644 --- a/org.civicrm.reqangular/test/models/option-group.spec.js +++ b/org.civicrm.reqangular/test/models/option-group.spec.js @@ -47,7 +47,7 @@ define([ }); it('caches requests by default', function () { - expect(optionGroupAPI.valuesOf.calls.mostRecent().args[1]).toBe(undefined); + expect(optionGroupAPI.valuesOf.calls.mostRecent().args[2]).toBe(undefined); }); }); @@ -63,15 +63,27 @@ define([ }); }); + describe('when extra params are passed', function () { + var params = { paramKey: 'paramValue' }; + + beforeEach(function () { + OptionGroup.valuesOf(optionGroupName, params); + }); + + it('passed params to API', function () { + expect(optionGroupAPI.valuesOf.calls.mostRecent().args[1]).toBe(params); + }); + }); + describe('when caching is disabled', function () { var cache = false; beforeEach(function () { - OptionGroup.valuesOf(optionGroupName, cache); + OptionGroup.valuesOf(optionGroupName, {}, cache); }); it('does not cache requests', function () { - expect(optionGroupAPI.valuesOf.calls.mostRecent().args[1]).toBe(cache); + expect(optionGroupAPI.valuesOf.calls.mostRecent().args[2]).toBe(cache); }); }); }); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js index 9d67e301981..e15f2509c91 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js @@ -1,5 +1,5 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,o){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:t(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,o,s,i){return t.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return s.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,o,s){return t.debug("WorkPatternAPI.getCalendar",n,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,o){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,o,s,i){function r(t,n){return u().then(function(a){var o=this.days[c(t).valueOf()];return!!o&&e.find(a,function(e){return e.name===n}).value===o.type}.bind(this))}function c(e){return t(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[c(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,o){return t.debug("Calendar"),n.extend({get:function(n,s,i,r){return t.debug("Calendar.get"),a.getCalendar(n,s,i,r).then(function(t){var a=t.values.map(function(e){return o.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function o(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,o,s){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return o.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",t,n,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t,n,o,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var i=a.defer();t&&n||i.reject("contact_id and period_id are mandatory");var r={contact_id:t,period_id:n,statuses:o?{IN:o}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",r,!1).then(function(e){i.resolve(e.values)}),i.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?o.reject(t(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(t){return s.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,o&&(i.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return r.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),n.all(t)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(s.permissions.admin.administer).then(function(t){return t?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,o,s,i){return n.all(this.processFilters(e),t,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,o){return n.balanceChangeByAbsenceType(e,t,a,o)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/instances/work-pattern.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("WorkPatternInstance",["$log","ModelInstance",function(e,t){return e.debug("WorkPatternInstance"),t.extend({})}])}),define("leave-absences/shared/models/work-pattern.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/work-pattern.instance"],function(e,t){"use strict";t.factory("WorkPattern",["$log","Model","WorkPatternAPI","WorkPatternInstance",function(t,n,a,o){return t.debug("WorkPattern"),n.extend({assignWorkPattern:function(e,t,n,o,s,i){return a.assignWorkPattern(e,t,n,o,s,i)},default:function(){return a.get({is_default:!0}).then(function(t){return o.init(e.first(t),!0)})},unassignWorkPattern:function(e){return a.unassignWorkPattern(e)},workPatternsOf:function(e,t,n){return a.workPatternsOf(e,t,n).then(function(e){return e.map(function(e){return o.init(e,!0)})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function u(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?c():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return o.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):i.all()}function m(e){return"me"===e?o.leaveManagees(v.contactId):"unassigned"===e?o.leaveManagees(void 0,{unassigned:!0}):o.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){r.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,u()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:i.contactId}).leaveManagees().then(function(e){i.lookupContacts=e}).then(o)}}}function o(){return t.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:i.filters.userSettings.department?i.filters.userSettings.department.value:null,level_type:i.filters.userSettings.level_type?i.filters.userSettings.level_type.value:null,location:i.filters.userSettings.location?i.filters.userSettings.location.value:null,region:i.filters.userSettings.region?i.filters.userSettings.region.value:null,id:{IN:i.filters.userSettings.contact?[i.filters.userSettings.contact.id]:i.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var i;return{init:function(e){return i=e,i.showContactName=!0,i.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function o(a,o,s,i,r,c,u,l,d,m){function f(){for(var e=[],t=n(M.selectedPeriod.start_date).clone().startOf("month"),a=n(M.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(R(t)),t.add(1,"month");M.months=e}function p(){i.$new().$watch(function(){return M.selectedMonths},function(t,n){null===n||e.equals(t,n)||I()})}function h(e){M.injectMonths=!0,S("injected").then(function(){I(e)}).then(function(){M.loading.calendar=!1})}function v(){L=a("LeaveCalendar"+t.capitalize(k)+"Controller").init(M)}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function g(){return c.all().then(function(e){M.absencePeriods=t.sortBy(e,"start_date"),M.selectedPeriod=t.find(M.absencePeriods,function(e){return!!e.current})}).then(f).then(w)}function _(){return u.all().then(u.loadCalculationUnits)}function y(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return L.loadContacts().then(function(e){M.contacts=e})}function C(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){M.filters.optionValues.regions=e.hrjc_region,M.filters.optionValues.locations=e.hrjc_location,M.filters.optionValues.levelTypes=e.hrjc_level_type,M.filters.optionValues.departments=e.hrjc_department})}function D(){return l.all()}function T(){return o.all([_(),D(),y()]).then(function(e){M.supportData.absenceTypes=e[0],M.supportData.publicHolidays=e[1],M.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,M.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,M.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,M.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function P(){var e=o.resolve();return M.injectMonths&&(e=S("destroyed"),M.injectMonths=!1),e}function R(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function A(e){e=t.includes(["contacts","period"],e)?e:"period",o.resolve().then(function(){M.loading.calendar=!0}).then(P).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function I(e){var n=M.selectedMonths.length?M.months.filter(function(e){return t.includes(M.selectedMonths,e.index)}):M.months;i.$emit("LeaveCalendar::showMonths",n,!!e)}function w(){M.selectedMonths=[n().month()]}function O(){return M.roleOverride?o.resolve().then(function(){k=M.roleOverride}):o.all([m(r.permissions.admin.administer),m(r.permissions.ssp.manage)]).then(function(e){k=e[0]?"admin":e[1]?"manager":"staff"})}function S(e){return o(function(n){var a=0,o=i.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===M.months.length&&(o(),n())})})}s.debug("Component: leave-calendar");var L,k,M=this;M.absencePeriods=[],M.contacts=[],M.contactIdsToReduceTo=null,M.injectMonths=!1,M.months=[],M.selectedMonths=null,M.selectedPeriod=null,M.showContactName=!1,M.showFilters=!1,M.supportData={},M.loading={calendar:!0,page:!0},M.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},M.labelPeriod=b,M.refresh=A,function(){O().then(p).then(v).then(P).then(g).then(function(){return o.all([q(),T()])}).then(function(){return M.showFilters?C():t.noop}).then(function(){h()}).then(function(){M.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",o]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,o){"use strict";function s(){y.calculationUnit=i(y.supportData.calculationUnits,"value",b.calculation_unit)}function i(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function r(){var e,n;return n=t(y.contactData.leaveRequest.from_date).isSame(y.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+y.calculationUnit.name+"-on-"+e+"-tooltip"}function c(){b=i(y.supportData.absenceTypes,"id",y.contactData.leaveRequest.type_id),y.contactData.leaveRequest["type_id.title"]=b.title}function u(){"days"===y.calculationUnit.name&&(g=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.from_date_type),_=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.to_date_type),y.contactData.leaveRequest["from_date_type.label"]=g.label,y.contactData.leaveRequest["to_date_type.label"]=_.label)}function l(e,t,n,a,s){e.stopPropagation(),o.openModal(t,n,a,s)}function d(){y.dates.from=new Date(y.contactData.leaveRequest.from_date),y.dates.to=new Date(y.contactData.leaveRequest.to_date)}function m(){y.contactData.isAccruedTOIL?y.label="AT":"days"===y.calculationUnit.name?f():p()}function f(){y.label=y.contactData.isAM?"AM":y.contactData.isPM?"PM":""}function p(){var e=t(y.contactData.leaveRequest.from_date).isSame(y.date,"day"),n=t(y.contactData.leaveRequest.to_date).isSame(y.date,"day");y.label=e?t(y.contactData.leaveRequest.from_date).format("HH:mm"):n?t(y.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){y.tooltipTemplate=y.contactData.isAccruedTOIL?"accrued-toil-tooltip":r()}function v(){a.$watch("day.contactData.leaveRequest",function(){y.contactData&&y.contactData.leaveRequest&&(c(),s(),u(),m(),d(),h()) })}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(e){_([e]),U(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return j[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){L(e),U(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=P(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){N.push(o.$on("LeaveCalendar::showMonths",$)),N.push(r.subscribe("LeaveRequest::new",u)),N.push(r.subscribe("LeaveRequest::edit",B)),N.push(r.subscribe("LeaveRequest::updatedByManager",B)),N.push(r.subscribe("LeaveRequest::delete",h)),N.push(r.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function D(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function T(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function P(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function R(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function A(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function I(){return[A(c.statusNames.approved),A(c.statusNames.adminApproved),A(c.statusNames.awaitingApproval),A(c.statusNames.moreInformationRequired)]}function w(){return H.month.loading=!0,a.all([S(),O()]).then(b).then(x).then(function(){F=!0}).then(function(){H.month.loading=!1})}function O(){return i.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:I()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function S(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){j=e.indexBy(t,"contact_id")})}function L(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function k(){o.$emit("LeaveCalendar::monthDestroyed"),N.map(function(e){e.remove?e.remove():e()})}function M(t,n,o){var s,i;return t.contactsData[n]=t.contactsData[n]||{},i=m(n),s=!0===o?a.resolve():a.all([i.isWeekend(p(t.date)),i.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:D(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?T(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function x(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return M(e,t.id)}))}))}function $(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!F)&&w())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=R(e);t&&(h(t),-1!==I().indexOf(e.status_id)&&u(e))}function U(e){return a.all(P(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var F=!1,N=[],j={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=k,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,i,r,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(i.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=D[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&r.publish("ManagerBadge:: Update Count"),r.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(D,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:D[e].label,isDirectAction:D[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,D={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return r.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,c.serverDateFormat).toDate()}function h(e){return t(e).format(c.serverDateFormat)}function v(e){var t;return i.resolve().then(function(){N(e),"from"===e&&F(),S("hours")&&(_(e),"from"!==e||te.uiOptions.multipleDays||_("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return i.reject("Please change date as it is not in any absence period")}).then(W).then(function(){if(t)return x()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(V(),!t)return E();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(P).finally(y)}function b(){return V(),E()}function g(){return te.uiOptions.toDate=null,N("to"),i.resolve().then(V).then(te.setDaysSelectionModeExtended).then(y).then(!te.uiOptions.multipleDays&&E)}function _(e){te.uiOptions.times[e].loading=!0}function y(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,S("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function C(){return te.request?te.request.request_type:te.leaveType||null}function D(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(j).catch(P)}function P(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function R(){return te.isMode("create")||te.forceRecalculateBalanceChange?E():T()}function A(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():i.resolve()}function I(){ee.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){Q()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){J(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",E))}function w(){te.isMode("edit")&&(te.isLeaveStatus(c.statusNames.approved)||te.isLeaveStatus(c.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function O(){o.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(K(e),V()))})}function S(e){return te.selectedAbsenceType.calculation_unit_name===e}function L(e){return te.request.request_type===e}function k(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function M(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function x(){return u.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function $(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function E(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(j).catch(P).finally(function(){te.loading.balanceChange=!1})):i.resolve()}function B(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function U(){return h(te.request.from_date)===h(te.request.to_date)}function F(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,N("to"))}function N(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),V(),z()}function j(e){te.balance.change=e,te.request.balance_change=e.amount,f(),B(),te.loading.balanceChange=!1}function W(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function H(){return!te.isMode("create")&&U()||te.isMode("create")&&(L("sickness")||S("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,i.resolve().then(te.setDaysSelectionModeExtended)}function G(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function Y(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function V(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(S("hours")||L("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function X(){e.forEach(ee,function(e){e()})}function Q(){var e,t=te.selectedAbsenceType.calculation_unit_name;return Y(),e=t!==te.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&H).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&V).then(y).then(E)}function J(e){return te.absenceTypes=e,Y(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,N("to")),G(),E()}function K(e){var t=D(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(D(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(D(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=c.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:$},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:r.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=b,te.daysSelectionModeChangeHandler=g,te.disableAndShowLoadingTimeInput=_,te.getMomentDateWithGivenTime=D,te.handleError=P,te.isCalculationUnit=S,te.isLeaveType=L,te.isNotWorkingDay=k,te.performBalanceChangeCalculation=E,te.setRequestDateTimesAndDateTypes=V,te.updateEndTimeInputMinTime=K,te.$onDestroy=X,function(){n("RequestModalDetails"+e.capitalize(C(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",te),I(),te.initChildController().then(function(){return i.all([x(),M()])}).then(!te.isMode("create")&&A).then(H).then(function(){if(!te.isMode("create"))return i.resolve().then(te.initTimesExtended).then(V)}).then(!te.isMode("create")&&W).then(w).then(G).then(R).then(O).then(!te.isMode("view")&&te.initWatchersExtended).catch(P).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l){function d(){return O.fileUploader&&O.fileUploader.queue.length>0}function m(){return O.getFilesAmount()0?A.map(function(e){return e.label}).join(", "):""}function q(){return O.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(A.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){w[e.label]=t})})).catch(function(){w=null})}function D(){return c.valuesOf("safe_file_extension").then(function(e){A=e})}function T(e){return!e.attachment_id||O.canManage}function P(){e.forEach(I,function(e){e()})}function R(e,t){O.fileUploader.queue&&O.fileUploader.queue.length>0?O.fileUploader.uploadAll({entityID:O.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var A=[],I=[],w={},O=Object.create(this);return O.filesLoaded=!1,O.fileUploader=null,O.today=Date.now(),O.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",O.userDateFormat=i.DATE_FORMAT,O.$onDestroy=P,O.canRemoveAttachment=T,O.canSubmit=d,O.canUploadMore=m,O.formatDateTime=f,O.getAuthorName=p,O.getFilesAmount=h,O.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",O),g(),a.all([D(),q()]).then(_).finally(function(){O.filesLoaded=!0})}(),O}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,o){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],s.openLeavePopup=a,function(){o=n.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,o,s,i,r,c,u,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var t=j[e.status];t?t(e.leaveRequest):W.refresh()}function b(t){t.dataIndex=e.indexBy(t.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return i.all().then(i.loadCalculationUnits).then(function(t){W.absenceTypes=t,W.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return A("approved",{status_id:N(m.statusNames.approved)})}function C(){return n.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[N(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[N(m.statusNames.awaitingApproval),N(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function D(){return r.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(t){var n=e.find(W.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function T(){return r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return M(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function P(){return n.all([r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),R({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:M(e[0]),expiredTOILS:x(e[1].list)})}).then(function(t){W.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function R(t){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function A(e,t){return R(t).then(function(t){W.sections[e].data=t.list})}function I(){return n.all(Object.values(W.sections).filter(function(e){return e.open}).map(L))}function w(){return A("other",{status_id:{in:[N(m.statusNames.rejected),N(m.statusNames.cancelled)]}})}function O(){return A("pending",{status_id:{in:[N(m.statusNames.awaitingApproval),N(m.statusNames.moreInformationRequired)]}})}function S(){return A("holidays",{public_holiday:!0})}function L(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function k(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){W.leaveRequestStatuses=e.indexBy(t,"value")})}function M(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(W.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function x(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function $(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(W.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],B(t,a))})}function B(e,t){var n=W.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function U(){W.loading.content=!0,n.all([D(),C()]).then(function(){W.loading.content=!1}).then(function(){return n.all([I(),h()])})}function F(e){var t=W.sections[e];t.open=!t.open,t.open&&!t.data.length&&L(t)}function N(t){return e.find(W.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var j={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:T},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:P},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w}},W.labelPeriod=g,W.refresh=U,W.toggleSection=F,function(){n.all([k(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return n.all([D(),C()])}).then(function(){W.loading.content=!1}),$()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report", -controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function u(){var e=i.request,t=!!e.from_date&&!!e.to_date,n=i.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return i.canCalculateChange()}function d(t,n){var a=i.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);i.uiOptions.multipleDays||("from"===t&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=i.convertDateToServerFormat(t),r.isPublicHoliday(t).then(function(n){return n?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,i.requestDayTypes).then(function(t){return t.length?t:i.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return R(n,e),e})):o.reject([])}function f(e,n){return e=t(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return o.resolve()}function v(){return C(i.uiOptions.fromDate,"from").then(function(){return C(i.uiOptions.toDate,"to")})}function b(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,t){i.isCalculationUnit("days")||+e==+t||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function g(e){var n=t(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),i.uiOptions.times[e].time=n}function _(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],t=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(T)).then(function(){["from","to"].forEach(function(e){g(e),I(e),t[e].amount=Math.min(i.request[e+"_date_amount"],t[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function y(){["from","to"].forEach(function(e){b(e),q(e)})}function q(e){s.$watch(function(){return i.uiOptions.times[e].time},function(t,n){i.isCalculationUnit("days")||t===n||(i.setRequestDateTimesAndDateTypes(),t&&I(e,!0))})}function C(e,t){return m(e,t).then(function(){i.loading[t+"DayTypes"]=!1})}function D(e){return C(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return T(e).then(function(){I(e,!0)})})}function T(e){var t=i.uiOptions[e+"Date"],n=!i.uiOptions.multipleDays;return t?i.request.getWorkDayForDate(i.convertDateToServerFormat(t)).then(function(t){S[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return S[e]={},i.handleError(t)}).finally(function(){n&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(t){var n=i.uiOptions.times[t];i["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function R(t,n){var a="request"+e.startCase(t)+"DayTypes";i[a]=n,i.isMode("create")&&(i.request[t+"_date_type"]=i[a][0].value)}function A(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),T("from").then(function(){I("from",!0)})):o.resolve()}function I(e,t){var n=i.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,c=S[a].number_of_hours?p(s,r).toString():"0";o.maxAmount=c,t&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function O(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?T("from").then(function(){I("from",!0)}):o.resolve()}var S={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=c,i.canCalculateChange=u,i.canSubmit=l,i.initChildController=h,i.initDayTypesExtended=v,i.initTimesExtended=_,i.initWatchersExtended=y,i.onAbsenceTypeUpdateExtended=O,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=A}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function i(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function r(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=i,s.initChildController=r,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=t.duration(t(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,t=!c.uiOptions.multipleDays&&!!c.request.from_date,n=t||e,a=E.from_date!==c.request.from_date||E.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&n&&U.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,t=c.request;return b({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function b(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&U.hasExpirationFromAdminSettings,t=U.hasPreviousExpirationDate,n=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=n&&(a||e||t)}function _(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function y(){return U.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){U.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",y().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function D(){o.$watch(function(){return c.request.toil_to_accrue},function(e,t){+e!=+t&&c.performBalanceChangeCalculation()})}function T(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,t){c.isCalculationUnit("hours")&&e!==t&&(c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function P(){var e=c.uiOptions.times;e.from.time=t(c.request.from_date).format("HH:mm"),e.to.time=t(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,t){e!==t&&(c.setRequestDateTimesAndDateTypes(),x(),l(),S())})})}function A(){c.isMode("view")||(D(),T(),R())}function I(t){return i.valuesOf("hrleaveandabsences_toil_amounts",{},t).then(function(t){c.toilAmounts=e.sortBy(t,"value")})}function w(){return l(),S(),x()}function O(){return k(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),B?B=!1:S(),x()}function S(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function L(){E=e.cloneDeep(c.request.attributes())}function k(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function M(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){I(!1)})}function x(){return f()?d().catch(a.resolve):a.resolve()}function $(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var E,B=!c.isMode("create"),U={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=P,c.initWatchersExtended=A,c.onDateChangeExtended=w,c.openToilInDaysAccrualOptionsEditor=M,c.setDaysSelectionModeExtended=O,c.updateExpiryDate=$,function(){L(),k(),!c.isMode("create")&&_()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,D){function T(e){"days"===xe.selectedAbsenceType.calculation_unit_name?delete xe.request[e+"_date_amount"]:delete xe.request[e+"_date_type"]}function P(){["from","to"].forEach(T)}function R(){var e=xe.requestStatuses[y.statusNames.awaitingApproval].value;we.status_id===e&&e!==xe.request.status_id&&d.publish("ManagerBadge:: Update Count")}function A(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!xe.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function O(){var e=A();return xe.isMode("edit")&&(e=e&&(G()||I())),xe.canManage&&xe.requestStatuses&&(e=e&&!!xe.getStatusFromValue(xe.newStatusOnSave)),(e=e&&!!xe.period.id)&&!xe.isMode("view")}function S(){xe.isSelfRecord?xe.request.status_id=xe.requestStatuses[y.statusNames.awaitingApproval].value:xe.canManage&&(xe.request.status_id=xe.newStatusOnSave||xe.request.status_id)}function L(){if(xe.isMode("edit")&&!xe.isRole("staff")&&"toil"!==N())return xe.request.calculateBalanceChange(xe.selectedAbsenceType.calculation_unit_name).then(function(e){if(+xe.balance.change.amount!=+e.amount)return D.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function k(){xe.errors=[]}function M(){return xe.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function x(){ee()&&!xe.isRole("staff")&&(xe.request.change_balance=!0)}function $(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return xe.request.delete().then(function(){xe.dismissModal(),d.publish("LeaveRequest::delete",xe.request)})}})}function E(){r.dismiss({$value:"cancel"})}function B(){var e=N();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return F(xe.getStatusFromValue(xe.request.status_id).name)}function F(e){return n.map(Ae[e],function(e){return xe.requestStatuses[e]})}function N(){return xe.request?xe.request.request_type:xe.leaveType||null}function j(){return!xe.request||e.equals({},xe.requestStatuses)?[]:xe.request.status_id?U():F("none")}function W(e){return n.find(xe.requestStatuses,function(t){return t.value===e})}function H(e){xe.errors=n.isArray(e)?e:[e],xe.loading.absenceTypes=!1,xe.submitting=!1}function G(){return!e.equals(we,xe.request.attributes())||xe.canManage&&xe.newStatusOnSave}function Y(){return xe.postContactSelection=!0,xe.staffMemberSelectionComplete=!1,xe.request.contact_id?o.resolve().then(re).then(ce).then(he).then(be).then(Z).then(z).then(xe.isMode("edit")?ge:n.noop).then(function(){xe.postContactSelection=!1,xe.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Le)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Ae.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Ae.awaiting_approval=e,Ae.more_information_required=e,Ae.rejected=e,Ae.approved=e,Ae.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return xe.canManage?f.find(xe.request.contact_id).then(function(e){xe.contactName=e.display_name}):o.resolve()}function X(){Oe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",xe.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Ie++})),i.$on("$destroy",De),i.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function Q(){var e,t;xe.request=xe.leaveRequest||null,e=N(),t=xe.initRequestAttributes(),"leave"===e?xe.request=_.init(t):"sickness"===e?xe.request=q.init(t):"toil"===e&&(xe.request=C.init(t))}function J(){var e={};return xe.request?e=xe.request.attributes():xe.canManage||(e={contact_id:Se}),e}function K(){if(ke="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(ke="admin")}).then(function(){return"staff"===ke&&c(y.permissions.ssp.manage).then(function(e){e&&(ke="manager")})}).finally(function(){xe.canManage=xe.isRole("manager")||xe.isRole("admin")})}function Z(){(xe.isRole("admin")||xe.isMode("create")&&xe.isRole("manager"))&&(xe.newStatusOnSave=xe.requestStatuses[y.statusNames.approved].value)}function ee(){return!xe.request.status_id||!n.includes(["cancelled","rejected"],W(xe.request.status_id).name)}function te(e){var t=xe.getStatusFromValue(xe.request.status_id);return!!t&&t.name===e}function ne(e){return xe.request&&xe.request.request_type===e}function ae(e){return xe.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return ke===e}function ie(){return h.all().then(function(e){xe.absencePeriods=e})}function re(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Re={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return xe.loading.entitlements=!0,b.all({contact_id:xe.request.contact_id,period_id:xe.period.id,type_id:{IN:Re.ids}},!0).finally(function(){xe.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Se=e.contactId})}function le(){return xe.selectedContactId?f.find(xe.selectedContactId).then(function(e){xe.managedContacts=[e]}):xe.isRole("admin")?f.all().then(function(e){xe.managedContacts=n.remove(e.list,function(e){return e.id!==Se})}):f.find(Se).then(function(e){return e.leaveManagees()}).then(function(e){xe.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){xe.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){R(),d.publish(e,xe.request),xe.errors=[],xe.dismissModal()}function pe(){["from","to"].forEach(function(e){xe.request[e+"_date"]=we[e+"_date"]})}function he(e){if(xe.absenceTypes=me(Re.types,e),!xe.absenceTypes.length)return o.reject(Le)}function ve(){xe.period=n.find(xe.absencePeriods,function(e){return xe.isMode("create")?e.current:oe(xe.request,e)})}function be(){xe.isMode("create")?(xe.selectedAbsenceType=xe.absenceTypes[0],xe.request.type_id=xe.selectedAbsenceType.id):xe.selectedAbsenceType=n.find(xe.absenceTypes,function(e){return e.id===xe.request.type_id})}function ge(){we=e.copy(xe.request.attributes())}function _e(){var e;xe.request.id?(e=[xe.requestStatuses[y.statusNames.approved].value,xe.requestStatuses[y.statusNames.adminApproved].value,xe.requestStatuses[y.statusNames.rejected].value,xe.requestStatuses[y.statusNames.cancelled].value],xe.mode="edit",xe.isRole("staff")&&e.indexOf(xe.request.status_id)>-1&&(xe.mode="view")):xe.mode="create"}function ye(){var e=xe.request.status_id;if(!xe.isMode("view")&&!xe.submitting)return xe.submitting=!0,S(),P(),xe.request.isValid().then(ee()&&L).then(x).then(!xe.request.change_balance&&pe).then(qe).then(function(){return xe.isMode("edit")?Pe():M()}).catch(function(t){xe.request.status_id=e,t&&H(t)}).finally(function(){xe.submitting=!1})}function qe(){return o.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===Ie&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return Ie>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function De(){Oe.forEach(function(e){e()})}function Te(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Pe(){return xe.request.update().then(Ce).then(function(){xe.isRole("manager")?fe("LeaveRequest::updatedByManager"):(xe.isRole("staff")||xe.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Re,Ae={},Ie=0,we={},Oe=[],Se="",Le="No entitlement",ke="",Me=[],xe=n.assign(this,m);xe.absencePeriods=[],xe.absenceTypes=[],xe.canManage=!1,xe.contactName=null,xe.errors=[],xe.loading={absenceTypes:!0,entitlements:!0},xe.managedContacts=[],xe.mode="",xe.newStatusOnSave=null,xe.period={},xe.postContactSelection=!1,xe.requestStatuses={},xe.selectedAbsenceType={},xe.staffMemberSelectionComplete=!1,xe.submitting=!1,xe.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},xe.canChangeAbsenceType=w,xe.canSubmit=O,xe.closeAlert=k,xe.deleteLeaveRequest=$,xe.dismissModal=E,xe.getStatuses=j,xe.getStatusFromValue=W,xe.initAfterContactSelection=Y,xe.initRequestAttributes=J,xe.isLeaveStatus=te,xe.isLeaveType=ne,xe.isMode=ae,xe.isRole=se,xe.submit=ye,xe.updateAbsenceType=Te,function(){xe.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),ie(),de()]).then(Q).then(_e).then(ve).then(function(){return xe.canManage&&!xe.isMode("edit")&&le()}).then(function(){if(xe.selectedContactId&&(xe.request.contact_id=xe.selectedContactId),xe.request.contact_id)return xe.initAfterContactSelection()}).catch(H).finally(function(){xe.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,i,r,c){function u(e){return r.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,i,r){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:i,forceRecalculateBalanceChange:r}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,i){function r(e){l.errorMessage=e}function c(){return i.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrjc_revision_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,i.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(r).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrjc_revision_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e}) -}(),g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){r.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){i.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i){function r(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,i){n=o.entitlements.slice(0,i),a=e.entitlements.slice(i+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,i;return s=e.indexBy(n,"entitlement_id.type_id"),i=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:i}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t];e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,i){o.comment&&(t=s.concat(o).concat(i),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(r).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,i,r,c,u,l,d){function m(){D.absencePeriods=t.chain(D.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){D.absenceTypes=t.filter(D.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:D.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:D.contactId,returnUrl:n})}function h(){return c.all().then(function(e){D.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:D.contactId}).then(function(e){q=e})}function g(e){i.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=D.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){D.absencePeriods=t.map(D.absencePeriods,function(e){var n=t.map(D.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

    Last updated:
    By: "+e.author_name+"
    Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
    ";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],D=this;D.absencePeriods=[],D.loading={absencePeriods:!0},D.getEditEntitlementsPageURL=p,D.openAnnualEntitlementChangeLog=g,D.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){D.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i,r){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return i.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){r.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); +controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function u(){var e=i.request,t=!!e.from_date&&!!e.to_date,n=i.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return i.canCalculateChange()}function d(t,n){var a=i.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);i.uiOptions.multipleDays||("from"===t&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=i.convertDateToServerFormat(t),r.isPublicHoliday(t).then(function(n){return n?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,i.requestDayTypes).then(function(t){return t.length?t:i.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return R(n,e),e})):o.reject([])}function f(e,n){return e=t(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return o.resolve()}function v(){return C(i.uiOptions.fromDate,"from").then(function(){return C(i.uiOptions.toDate,"to")})}function b(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,t){i.isCalculationUnit("days")||+e==+t||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function g(e){var n=t(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),i.uiOptions.times[e].time=n}function _(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],t=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(T)).then(function(){["from","to"].forEach(function(e){g(e),I(e),t[e].amount=Math.min(i.request[e+"_date_amount"],t[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function y(){["from","to"].forEach(function(e){b(e),q(e)})}function q(e){s.$watch(function(){return i.uiOptions.times[e].time},function(t,n){i.isCalculationUnit("days")||t===n||(i.setRequestDateTimesAndDateTypes(),t&&I(e,!0))})}function C(e,t){return m(e,t).then(function(){i.loading[t+"DayTypes"]=!1})}function D(e){return C(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return T(e).then(function(){I(e,!0)})})}function T(e){var t=i.uiOptions[e+"Date"],n=!i.uiOptions.multipleDays;return t?i.request.getWorkDayForDate(i.convertDateToServerFormat(t)).then(function(t){S[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return S[e]={},i.handleError(t)}).finally(function(){n&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(t){var n=i.uiOptions.times[t];i["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function R(t,n){var a="request"+e.startCase(t)+"DayTypes";i[a]=n,i.isMode("create")&&(i.request[t+"_date_type"]=i[a][0].value)}function A(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),T("from").then(function(){I("from",!0)})):o.resolve()}function I(e,t){var n=i.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,c=S[a].number_of_hours?p(s,r).toString():"0";o.maxAmount=c,t&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function O(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?T("from").then(function(){I("from",!0)}):o.resolve()}var S={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=c,i.canCalculateChange=u,i.canSubmit=l,i.initChildController=h,i.initDayTypesExtended=v,i.initTimesExtended=_,i.initWatchersExtended=y,i.onAbsenceTypeUpdateExtended=O,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=A}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function i(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function r(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=i,s.initChildController=r,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=t.duration(t(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,t=!c.uiOptions.multipleDays&&!!c.request.from_date,n=t||e,a=E.from_date!==c.request.from_date||E.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&n&&U.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,t=c.request;return b({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function b(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&U.hasExpirationFromAdminSettings,t=U.hasPreviousExpirationDate,n=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=n&&(a||e||t)}function _(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function y(){return U.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){U.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",y().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function D(){o.$watch(function(){return c.request.toil_to_accrue},function(e,t){+e!=+t&&c.performBalanceChangeCalculation()})}function T(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,t){c.isCalculationUnit("hours")&&e!==t&&(c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function P(){var e=c.uiOptions.times;e.from.time=t(c.request.from_date).format("HH:mm"),e.to.time=t(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,t){e!==t&&(c.setRequestDateTimesAndDateTypes(),x(),l(),S())})})}function A(){c.isMode("view")||(D(),T(),R())}function I(t){return i.valuesOf("hrleaveandabsences_toil_amounts",{},t).then(function(t){c.toilAmounts=e.sortBy(t,"value")})}function w(){return l(),S(),x()}function O(){return k(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),B?B=!1:S(),x()}function S(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function L(){E=e.cloneDeep(c.request.attributes())}function k(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function M(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){I(!1)})}function x(){return f()?d().catch(a.resolve):a.resolve()}function $(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var E,B=!c.isMode("create"),U={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=P,c.initWatchersExtended=A,c.onDateChangeExtended=w,c.openToilInDaysAccrualOptionsEditor=M,c.setDaysSelectionModeExtended=O,c.updateExpiryDate=$,function(){L(),k(),!c.isMode("create")&&_()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,D){function T(e){"days"===xe.selectedAbsenceType.calculation_unit_name?delete xe.request[e+"_date_amount"]:delete xe.request[e+"_date_type"]}function P(){["from","to"].forEach(T)}function R(){var e=xe.requestStatuses[y.statusNames.awaitingApproval].value;we.status_id===e&&e!==xe.request.status_id&&d.publish("ManagerBadge:: Update Count")}function A(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!xe.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function O(){var e=A();return xe.isMode("edit")&&(e=e&&(G()||I())),xe.canManage&&xe.requestStatuses&&(e=e&&!!xe.getStatusFromValue(xe.newStatusOnSave)),(e=e&&!!xe.period.id)&&!xe.isMode("view")}function S(){xe.isSelfRecord?xe.request.status_id=xe.requestStatuses[y.statusNames.awaitingApproval].value:xe.canManage&&(xe.request.status_id=xe.newStatusOnSave||xe.request.status_id)}function L(){if(xe.isMode("edit")&&!xe.isRole("staff")&&"toil"!==N())return xe.request.calculateBalanceChange(xe.selectedAbsenceType.calculation_unit_name).then(function(e){if(+xe.balance.change.amount!=+e.amount)return D.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function k(){xe.errors=[]}function M(){return xe.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function x(){ee()&&!xe.isRole("staff")&&(xe.request.change_balance=!0)}function $(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return xe.request.delete().then(function(){xe.dismissModal(),d.publish("LeaveRequest::delete",xe.request)})}})}function E(){r.dismiss({$value:"cancel"})}function B(){var e=N();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return F(xe.getStatusFromValue(xe.request.status_id).name)}function F(e){return n.map(Ae[e],function(e){return xe.requestStatuses[e]})}function N(){return xe.request?xe.request.request_type:xe.leaveType||null}function j(){return!xe.request||e.equals({},xe.requestStatuses)?[]:xe.request.status_id?U():F("none")}function W(e){return n.find(xe.requestStatuses,function(t){return t.value===e})}function H(e){xe.errors=n.isArray(e)?e:[e],xe.loading.absenceTypes=!1,xe.submitting=!1}function G(){return!e.equals(we,xe.request.attributes())||xe.canManage&&xe.newStatusOnSave}function Y(){return xe.postContactSelection=!0,xe.staffMemberSelectionComplete=!1,xe.request.contact_id?o.resolve().then(re).then(ce).then(he).then(be).then(Z).then(z).then(xe.isMode("edit")?ge:n.noop).then(function(){xe.postContactSelection=!1,xe.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Le)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Ae.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Ae.awaiting_approval=e,Ae.more_information_required=e,Ae.rejected=e,Ae.approved=e,Ae.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return xe.canManage?f.find(xe.request.contact_id).then(function(e){xe.contactName=e.display_name}):o.resolve()}function X(){Oe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",xe.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Ie++})),i.$on("$destroy",De),i.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function Q(){var e,t;xe.request=xe.leaveRequest||null,e=N(),t=xe.initRequestAttributes(),"leave"===e?xe.request=_.init(t):"sickness"===e?xe.request=q.init(t):"toil"===e&&(xe.request=C.init(t))}function J(){var e={};return xe.request?e=xe.request.attributes():xe.canManage||(e={contact_id:Se}),e}function K(){if(ke="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(ke="admin")}).then(function(){return"staff"===ke&&c(y.permissions.ssp.manage).then(function(e){e&&(ke="manager")})}).finally(function(){xe.canManage=xe.isRole("manager")||xe.isRole("admin")})}function Z(){(xe.isRole("admin")||xe.isMode("create")&&xe.isRole("manager"))&&(xe.newStatusOnSave=xe.requestStatuses[y.statusNames.approved].value)}function ee(){return!xe.request.status_id||!n.includes(["cancelled","rejected"],W(xe.request.status_id).name)}function te(e){var t=xe.getStatusFromValue(xe.request.status_id);return!!t&&t.name===e}function ne(e){return xe.request&&xe.request.request_type===e}function ae(e){return xe.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return ke===e}function ie(){return h.all().then(function(e){xe.absencePeriods=e})}function re(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Re={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return xe.loading.entitlements=!0,b.all({contact_id:xe.request.contact_id,period_id:xe.period.id,type_id:{IN:Re.ids}},!0).finally(function(){xe.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Se=e.contactId})}function le(){return xe.selectedContactId?f.find(xe.selectedContactId).then(function(e){xe.managedContacts=[e]}):xe.isRole("admin")?f.all().then(function(e){xe.managedContacts=n.remove(e.list,function(e){return e.id!==Se})}):f.find(Se).then(function(e){return e.leaveManagees()}).then(function(e){xe.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){xe.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){R(),d.publish(e,xe.request),xe.errors=[],xe.dismissModal()}function pe(){["from","to"].forEach(function(e){xe.request[e+"_date"]=we[e+"_date"]})}function he(e){if(xe.absenceTypes=me(Re.types,e),!xe.absenceTypes.length)return o.reject(Le)}function ve(){xe.period=n.find(xe.absencePeriods,function(e){return xe.isMode("create")?e.current:oe(xe.request,e)})}function be(){xe.isMode("create")?(xe.selectedAbsenceType=xe.absenceTypes[0],xe.request.type_id=xe.selectedAbsenceType.id):xe.selectedAbsenceType=n.find(xe.absenceTypes,function(e){return e.id===xe.request.type_id})}function ge(){we=e.copy(xe.request.attributes())}function _e(){var e;xe.request.id?(e=[xe.requestStatuses[y.statusNames.approved].value,xe.requestStatuses[y.statusNames.adminApproved].value,xe.requestStatuses[y.statusNames.rejected].value,xe.requestStatuses[y.statusNames.cancelled].value],xe.mode="edit",xe.isRole("staff")&&e.indexOf(xe.request.status_id)>-1&&(xe.mode="view")):xe.mode="create"}function ye(){var e=xe.request.status_id;if(!xe.isMode("view")&&!xe.submitting)return xe.submitting=!0,S(),P(),xe.request.isValid().then(ee()&&L).then(x).then(!xe.request.change_balance&&pe).then(qe).then(function(){return xe.isMode("edit")?Pe():M()}).catch(function(t){xe.request.status_id=e,t&&H(t)}).finally(function(){xe.submitting=!1})}function qe(){return o.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===Ie&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return Ie>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function De(){Oe.forEach(function(e){e()})}function Te(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Pe(){return xe.request.update().then(Ce).then(function(){xe.isRole("manager")?fe("LeaveRequest::updatedByManager"):(xe.isRole("staff")||xe.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Re,Ae={},Ie=0,we={},Oe=[],Se="",Le="No entitlement",ke="",Me=[],xe=n.assign(this,m);xe.absencePeriods=[],xe.absenceTypes=[],xe.canManage=!1,xe.contactName=null,xe.errors=[],xe.loading={absenceTypes:!0,entitlements:!0},xe.managedContacts=[],xe.mode="",xe.newStatusOnSave=null,xe.period={},xe.postContactSelection=!1,xe.requestStatuses={},xe.selectedAbsenceType={},xe.staffMemberSelectionComplete=!1,xe.submitting=!1,xe.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},xe.canChangeAbsenceType=w,xe.canSubmit=O,xe.closeAlert=k,xe.deleteLeaveRequest=$,xe.dismissModal=E,xe.getStatuses=j,xe.getStatusFromValue=W,xe.initAfterContactSelection=Y,xe.initRequestAttributes=J,xe.isLeaveStatus=te,xe.isLeaveType=ne,xe.isMode=ae,xe.isRole=se,xe.submit=ye,xe.updateAbsenceType=Te,function(){xe.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),ie(),de()]).then(Q).then(_e).then(ve).then(function(){return xe.canManage&&!xe.isMode("edit")&&le()}).then(function(){if(xe.selectedContactId&&(xe.request.contact_id=xe.selectedContactId),xe.request.contact_id)return xe.initAfterContactSelection()}).catch(H).finally(function(){xe.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,i,r,c){function u(e){return r.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,i,r){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:i,forceRecalculateBalanceChange:r}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,i){function r(e){l.errorMessage=e}function c(){return i.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrjc_revision_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,i.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(r).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrjc_revision_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(), +g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){r.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){i.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i){function r(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,i){n=o.entitlements.slice(0,i),a=e.entitlements.slice(i+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,i;return s=e.indexBy(n,"entitlement_id.type_id"),i=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:i}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t];e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,i){o.comment&&(t=s.concat(o).concat(i),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(r).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,i,r,c,u,l,d){function m(){D.absencePeriods=t.chain(D.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){D.absenceTypes=t.filter(D.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:D.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:D.contactId,returnUrl:n})}function h(){return c.all().then(function(e){D.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:D.contactId}).then(function(e){q=e})}function g(e){i.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=D.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){D.absencePeriods=t.map(D.absencePeriods,function(e){var n=t.map(D.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

    Last updated:
    By: "+e.author_name+"
    Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
    ";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],D=this;D.absencePeriods=[],D.loading={absencePeriods:!0},D.getEditEntitlementsPageURL=p,D.openAnnualEntitlementChangeLog=g,D.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){D.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i,r){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return i.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){r.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js index 21e9a9188de..39c494d1095 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js @@ -9,6 +9,6 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),w.current)}).then(null,function(a){return a===D?S:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:S(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function M(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function L(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;aWhen All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){E.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){E.selectedMonths=[n().month()]}function T(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=D,function(){T().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",L)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([O(),T()]).then(g).then(M).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function M(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function L(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}), define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function S(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function T(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function L(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:L},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),E()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(S).then(V).then(P).then(T).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||T.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=w,T.canRemoveAttachment=A,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=h,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:E(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:L(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function E(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function M(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function L(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=M(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=h,U.getAbsenceTypeByID=v,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=x,U.refresh=k,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),O(),P(),S(),R(),I()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),S(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(S)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function S(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function T(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=T,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=k.from_date!==u.request.from_date||k.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&B.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&B.hasExpirationFromAdminSettings,t=B.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return B.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){B.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),M(),l(),O())})})} -function D(){u.isMode("view")||(C(),A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",{},t).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function S(){return l(),O(),M()}function T(){return x(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),j?j=!1:O(),M()}function O(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function I(){k=e.cloneDeep(u.request.attributes())}function x(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function E(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){R(!1)})}function M(){return m()?d().catch(a.resolve):a.resolve()}function L(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var k,j=!u.isMode("create"),B={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=S,u.openToilInDaysAccrualOptionsEditor=E,u.setDaysSelectionModeExtended=T,u.updateExpiryDate=L,function(){I(),x(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,r,o){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(o.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==F())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function E(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function L(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function F(){return Me.request?Me.request.request_type:Me.leaveType||null}function U(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Se,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=F(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Me.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Se[e+"_date"]})}function he(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function ve(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Se=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():E()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Ee=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=S,Me.canSubmit=T,Me.closeAlert=x,Me.deleteLeaveRequest=L,Me.dismissModal=k,Me.getStatuses=U,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(t){return t.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM), +function D(){u.isMode("view")||(C(),A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",{},t).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function S(){return l(),O(),M()}function T(){return x(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),j?j=!1:O(),M()}function O(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function I(){k=e.cloneDeep(u.request.attributes())}function x(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function E(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){R(!1)})}function M(){return m()?d().catch(a.resolve):a.resolve()}function L(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var k,j=!u.isMode("create"),B={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=S,u.openToilInDaysAccrualOptionsEditor=E,u.setDaysSelectionModeExtended=T,u.updateExpiryDate=L,function(){I(),x(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,r,o){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(o.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==F())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function E(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function L(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function F(){return Me.request?Me.request.request_type:Me.leaveType||null}function U(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Se,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=F(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Me.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Se[e+"_date"]})}function he(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function ve(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Se=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():E()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Ee=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=S,Me.canSubmit=T,Me.closeAlert=x,Me.deleteLeaveRequest=L,Me.dismissModal=k,Me.getStatuses=U,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(t){return t.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM), define("leave-absences/admin-dashboard/modules/config",["common/angular","leave-absences/admin-dashboard/modules/settings"],function(e){return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(e,t,n,a,r,o){var s={format:["DateFormat",function(e){return e.getDateFormat()}]};r.debugEnabled(o.debug),t.defaults.stripTrailingSlashes=!1,a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:s}).state("calendar",{url:"/calendar",template:'',resolve:s}).state("leave-balances",{url:"/leave-balances",template:"",resolve:s})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function t(e,t){e.debug("Component: admin-dashboard-container"),t.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",t]})}),define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/admin-dashboard":n+"/admin-dashboard"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js index 32e7391923a..ee65d4b8eb9 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js @@ -9,6 +9,6 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))h.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),h.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var v=s(u||{}),h=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+h.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,v)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,v)),m.$$inheritedValues=f(o.$$values,v),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,v)),o.then(i,u));for(var q=0,$=h.length;q<$;q+=3)a.hasOwnProperty(h[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(h[q],h[q+1],h[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(h.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(v[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return v[t]=new Y.Param(t,n,a,r),v[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},v=this.params=r?r.params.$$new():new Y.ParamSet,h=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=h}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:v,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,v=!0,h=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(v=e),v},this.defaultSquashPolicy=function(e){if(!j(e))return h;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return h=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!v.type.is(e))throw new Error("Default value ("+e+") for parameter '"+v.id+"' is not an instance of Type ("+v.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(v.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?v.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var v=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return h;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),h(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=L[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&h.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),h.update(!0),w.current)}).then(null,function(a){return a===D?S:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||h.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==v){d=n.$new(),v=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(h)}}var f,m,p,v,h=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:S(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function L(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function M(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return v.push(u),h[s]=r,function(){var e=v.indexOf(u);-1!==e&&v.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function E(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),h.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",h),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n){function a(e){e.absencePeriods&&c.absencePeriods.length&&(c.filters.period_id=o().id),e.absenceTypes&&c.absenceTypes.length&&(c.filters.type_id=s().id),(e.loggedInContactId||e.userRole)&&(c.filters.managed_by="manager"===c.userRole?c.loggedInContactId:void 0),r()&&c.submitFilters()}function r(){return e.every(c.filters,function(e){return null!==e})}function o(){return e.find(c.absencePeriods,function(e){return e.current})||c.absencePeriods.reduce(function(e,n){return t(e.end_date).isAfter(n.end_date)?e:n})}function s(){return c.absenceTypes.reduce(function(e,t){return e.title.localeCompare(t.title)?e:t})}function i(e){return e.current?"Current Period ("+e.title+")":e.title}function u(){n.$emit("LeaveBalanceFilters::update",c.filters)}var c=this;c.filters={period_id:null,type_id:null,managed_by:null},c.$onChanges=a,c.labelPeriod=i,c.submitFilters=u}n.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,t){return e.extend({all:function(e,n,a,r,o){return t.getLeaveBalances(this.processFilters(e),n,a,r,o)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){return r.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function p(){return o.all().then(o.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function v(){return s.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function h(){return n.all([m(),p(),v(),g(),q()]).catch(function(e){u.error("Error",e)})}function g(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function b(){return P.loading.report=!0,i.all(w,P.pagination,void 0,void 0,!1).then(function(e){P.report=y(e.list),P.reportCount=e.total}).catch(function(e){u.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function y(n){return n.map(function(n){return n=e.copy(n),n.absence_types=t.indexBy(n.absence_types,function(e){return e.id}),n})}function _(){a.$on("LeaveBalanceFilters::update",C),c.subscribe("LeaveRequest::new",$)}function q(){return f(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function $(e){C(e,w)}function C(e,t){w=t,P.pagination.page=1,A(),P.loadReportCurrentPage()}function A(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+w.type_id})}var w={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.loadReportCurrentPage=b,function(){_(),h().then(function(){P.loading.component=!1})}()}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(h.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(h.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=h.filters.userSettings.assignedTo.type;return f(e).then(function(e){h.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return h.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(m(),null,"display_name").then(function(e){return e.list})}function d(){return v?a.resolve(v):s.all()}function f(e){return"me"===e?r.leaveManagees(h.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function m(){return{department:h.filters.userSettings.department?h.filters.userSettings.department.value:null,level_type:h.filters.userSettings.level_type?h.filters.userSettings.level_type.value:null,location:h.filters.userSettings.location?h.filters.userSettings.location.value:null,region:h.filters.userSettings.region?h.filters.userSettings.region.value:null,id:{IN:h.filters.userSettings.contact?[h.filters.userSettings.contact.id]:h.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var v,h;return{init:function(e){return h=e,h.showContactDetailsLink=!0,h.showContactName=!0,h.showFilters=!0,h.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],h.filters.userSettings.assignedTo=h.filtersByAssignee[0],h.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(L.selectedPeriod.start_date).clone().startOf("month"),a=n(L.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");L.months=e}function p(){s.$new().$watch(function(){return L.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function v(e){L.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){L.loading.calendar=!1})}function h(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(L)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){L.absencePeriods=t.sortBy(e,"start_date"),L.selectedPeriod=t.find(L.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){L.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){L.filters.optionValues.regions=e.hrjc_region,L.filters.optionValues.locations=e.hrjc_location,L.filters.optionValues.levelTypes=e.hrjc_level_type,L.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){L.supportData.absenceTypes=e[0],L.supportData.publicHolidays=e[1],L.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,L.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,L.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,L.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return L.injectMonths&&(e=O("destroyed"),L.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){L.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){v("contacts"===e)})}function R(e){var n=L.selectedMonths.length?L.months.filter(function(e){return t.includes(L.selectedMonths,e.index)}):L.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){L.selectedMonths=[n().month()]}function T(){return L.roleOverride?r.resolve().then(function(){x=L.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===L.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,L=this;L.absencePeriods=[],L.contacts=[],L.contactIdsToReduceTo=null,L.injectMonths=!1,L.months=[],L.selectedMonths=null,L.selectedPeriod=null,L.showContactName=!1,L.showFilters=!1,L.supportData={},L.loading={calendar:!0,page:!0},L.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},L.labelPeriod=g,L.refresh=D,function(){T().then(p).then(h).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return L.showFilters?$():t.noop}).then(function(){v()}).then(function(){L.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function v(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function h(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),v())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){h()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function v(e){I(e),B(e)}function h(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",E)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",v)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?v(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([O(),T()]).then(g).then(M).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function L(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function M(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return L(e,t.id)}))}))}function E(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(v(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return L(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=h,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}), define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(v(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):v(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function v(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function h(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=h,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function v(e){return q.mode===e}function h(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=v,q.onBeforeSubmit=h,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function v(e){return t(e).format(u.serverDateFormat)}function h(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function S(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function T(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function L(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function E(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return v(te.request.from_date)===v(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?v(e.fromDate):null,te.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:E},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=v,te.dateChangeHandler=h,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),L()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(S).then(V).then(P).then(T).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||T.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=w,T.canRemoveAttachment=A,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=v,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function v(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function h(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:L(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:E(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function L(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function M(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function E(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=M(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=v,U.getAbsenceTypeByID=h,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=x,U.refresh=k,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),O(),P(),S(),R(),I()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function v(){return r.resolve()}function h(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),S(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(S)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function S(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function T(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=v,s.initDayTypesExtended=h,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=T,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){ -function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return h().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=k.from_date!==u.request.from_date||k.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&B.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function v(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function h(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&B.hasExpirationFromAdminSettings,t=B.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return B.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){B.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),M(),l(),O())})})}function D(){u.isMode("view")||(C(),A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",{},t).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function S(){return l(),O(),M()}function T(){return x(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),j?j=!1:O(),M()}function O(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function I(){k=e.cloneDeep(u.request.attributes())}function x(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function L(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){R(!1)})}function M(){return m()?d().catch(a.resolve):a.resolve()}function E(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var k,j=!u.isMode("create"),B={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=v,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=S,u.openToilInDaysAccrualOptionsEditor=L,u.setDaysSelectionModeExtended=T,u.updateExpiryDate=E,function(){I(),x(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function v(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function h(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?v.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([h.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([h.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,v,h,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Le.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Le.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==F())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function L(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function F(){return Me.request?Me.request.request_type:Me.leaveType||null}function U(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Se,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(ve).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(ve).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Le.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=F(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return v.all().then(function(e){Me.absencePeriods=e})}function ie(){return h.all(j()).then(h.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Se[e+"_date"]})}function ve(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function he(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Se=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():L()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Le.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Le=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=S,Me.canSubmit=T,Me.closeAlert=x,Me.deleteLeaveRequest=E,Me.dismissModal=k,Me.getStatuses=U,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(he).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){ +function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return h().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=k.from_date!==u.request.from_date||k.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&B.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function v(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function h(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&B.hasExpirationFromAdminSettings,t=B.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return B.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){B.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),M(),l(),O())})})}function D(){u.isMode("view")||(C(),A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",{},t).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function S(){return l(),O(),M()}function T(){return x(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),j?j=!1:O(),M()}function O(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function I(){k=e.cloneDeep(u.request.attributes())}function x(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function L(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){R(!1)})}function M(){return m()?d().catch(a.resolve):a.resolve()}function E(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var k,j=!u.isMode("create"),B={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=v,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=S,u.openToilInDaysAccrualOptionsEditor=L,u.setDaysSelectionModeExtended=T,u.updateExpiryDate=E,function(){I(),x(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function v(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function h(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?v.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([h.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([h.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,v,h,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Le.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Le.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==F())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function L(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function F(){return Me.request?Me.request.request_type:Me.leaveType||null}function U(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Se,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(ve).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(ve).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Le.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=F(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return v.all().then(function(e){Me.absencePeriods=e})}function ie(){return h.all(j()).then(h.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Se[e+"_date"]})}function ve(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function he(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Se=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():L()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Le.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Le=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=S,Me.canSubmit=T,Me.closeAlert=x,Me.deleteLeaveRequest=E,Me.dismissModal=k,Me.getStatuses=U,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(he).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){ return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e){define("leave-absences/manager-leave/modules/config",["common/angular","leave-absences/manager-leave/modules/settings"],function(t){return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/manager-leave/requests"),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","leave-absences/shared/ui-router","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js index cc41f687c67..48699661bd7 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js @@ -9,6 +9,6 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[m]),c[r[m]]=e[r[m]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&f(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,f),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),f.$$values=b,f.$$promises=f.$$promises||!0,delete f.$$inheritedValues,c.resolve(b))}function u(e){f.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),f=c.promise,g=f.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),f;o.$$inheritedValues&&r(b,m(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,m(o.$$values,h)),f.$$inheritedValues=m(o.$$values,h),i()):(o.$$inheritedValues&&(f.$$inheritedValues=m(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(f.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),m=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(m++,g[e].then(function(t){b[e]=t,--m||l()},c))}),m||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return f}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(m,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",m=0,f=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),f.push(g.segment),m=c.lastIndex;y=e.substring(m);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,m+_),q.length>0)for(m=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),m=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",f.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=f[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:m}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,m=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(m=e),m},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(f(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function m(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),f(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:m})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(D.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!D[r])return f(r,t.self);for(var o in R)B(R[o])&&(t[o]=R[o](t,R.$delegates[o]));return D[n]=t,!t[T]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){A.$current.navigable==t&&c(e,n)||A.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=A.$current.name.split("."),a=0,r=t.length;a=D;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=D;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.$current=t,A.current=t.self,A.params=n,V(A.params,f),A.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),A.current)}).then(null,function(a){return a===P?R:A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},A.is=function(e,t,a){a=W({relative:A.$current},a||{});var r=m(e,a.relative);return j(r)?A.$current===r&&(!t||c(r.params.$$values(t),f)):n},A.includes=function(e,t,a){if(a=W({relative:A.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=A.$current.name}var r=m(e,a.relative);if(!j(r))return n;if(!j(A.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(m&&(m.remove(),m=null),p&&(p.$destroy(),p=null),f){var e=f.data("$uiViewAnim");b.leave(f,function(){e.$$animLeave.resolve(),m=null}),m=f,f=null}}function d(s){var d,m=P(n,c,i,r),y=m&&e.$current&&e.$current.locals[m];if(s||y!==h){d=n.$new(),h=e.$current.locals[m],d.$emit("$viewContentLoading",m);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});f=_,p=d,p.$emit("$viewContentLoaded",m),p.$eval(v)}}var m,f,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function D(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=P(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var m=t.extend({},d);o[d.$$resolveAs]=m;var f=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=m),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}f(o)}}}}}function P(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function T(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function R(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function x(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function O(e,t){return{relative:R(e)||t.$current,inherit:!0}}function I(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=T(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],m=null;c.options=W(O(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var f=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),m&&m(),d&&(m=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&f(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),f(),l.clickable&&(i=x(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){m.state=t[0],m.params=t[1],m.options=t[2],m.href=e.href(m.state,m.params,m.options),f&&f(),c&&(f=c.$$addStateInfo(m.state,m.params)),m.href&&r.$set(u.attr,m.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",m={state:null,params:null,options:null,href:null},f=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=x(a,e,t,u,function(){return m}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function L(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,R(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function m(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,m){function f(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(D(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||T()})}function h(e){E.injectMonths=!0,x("injected").then(function(){T(e)}).then(function(){E.loading.calendar=!1})}function v(){O=a("LeaveCalendar"+t.capitalize(I)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(f).then(R)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return O.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function w(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return E.injectMonths&&(e=x("destroyed"),E.injectMonths=!1),e}function D(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function P(e){ e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(A).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function T(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function R(){E.selectedMonths=[n().month()]}function S(){return E.roleOverride?r.resolve().then(function(){I=E.roleOverride}):r.all([m(i.permissions.admin.administer),m(i.permissions.ssp.manage)]).then(function(e){I=e[0]?"admin":e[1]?"manager":"staff"})}function x(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var O,I,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=P,function(){S().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),w()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function m(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?f():p()}function f(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),m(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function m(e){return U[e]}function f(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){O(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",M)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function w(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function D(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function P(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function T(){return[P(u.statusNames.approved),P(u.statusNames.adminApproved),P(u.statusNames.awaitingApproval),P(u.statusNames.moreInformationRequired)]}function R(){return W.month.loading=!0,a.all([x(),S()]).then(g).then(L).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:T()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function x(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function O(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function I(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=m(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?w(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function L(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&R())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=D(e);t&&(h(t),-1!==T().indexOf(e.status_id)&&c(e))}function B(e){return a.all(A(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=I,W.contactsList=f,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),x("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return L()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(A).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,x("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function w(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(A)}function A(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function D(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():w()}function P(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function T(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function R(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function x(e){return te.selectedAbsenceType.calculation_unit_name===e}function O(e){return te.request.request_type===e}function I(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function L(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(A).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,f(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(O("sickness")||x("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(x("hours")||O("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=A,te.isCalculationUnit=x,te.isLeaveType=O,te.isNotWorkingDay=I,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),T(),te.initChildController().then(function(){return s.all([L(),E()])}).then(!te.isMode("create")&&P).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(R).then(V).then(D).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(A).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function m(){return S.getFilesAmount()0?P.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(P.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){R[e.label]=t})})).catch(function(){R=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){P=e})}function w(e){return!e.attachment_id||S.canManage}function A(){e.forEach(T,function(e){e()})}function D(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var P=[],T=[],R={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=A,S.canRemoveAttachment=w,S.canSubmit=d,S.canUploadMore=m,S.formatDateTime=f,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,r,o,s,i,u,c,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){k(e),H.sections.other.open&&f(e,H.sections.other)}function h(){Object.values(H.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):H.refresh()}function g(t){t.dataIndex=e.indexBy(t.data,"id")}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function y(){return o.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.selectedPeriod=e.find(H.absencePeriods,function(e){return!0===e.current})})}function _(){return s.all().then(s.loadCalculationUnits).then(function(t){H.absenceTypes=t,H.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return P("approved",{status_id:F(m.statusNames.approved)})}function $(){return n.all([u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,null,!0),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.approved)]),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){H.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function C(){return i.all({contact_id:H.contactId,period_id:H.selectedPeriod.id},!0).then(function(e){H.entitlements=e}).then(function(){H.absenceTypesFiltered=H.absenceTypes.filter(function(t){var n=e.find(H.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function w(){return i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id},H.entitlements).then(function(){return E(H.entitlements)}).then(function(e){H.sections.entitlements.data=e})}function A(){return n.all([i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id,expired:!0}),D({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:E(e[0]),expiredTOILS:L(e[1].list)})}).then(function(t){ -H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function D(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function P(e,t){return D(t).then(function(t){H.sections[e].data=t.list})}function T(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(O))}function R(){return P("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function S(){return P("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function x(){return P("holidays",{public_holiday:!0})}function O(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function I(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function E(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function L(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){k(e)})}function k(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([C(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([T(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&O(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:k,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:x},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([I(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([C(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return D(n,e),e})):r.reject([])}function f(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),R(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(w)).then(function(){["from","to"].forEach(function(e){b(e),T(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(R)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&T(e,!0))})}function $(e,t){return m(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return w(e).then(function(){T(e,!0)})})}function w(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){x[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return x[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function A(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function D(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function P(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),w("from").then(function(){T("from",!0)})):r.resolve()}function T(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=x[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function R(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?w("from").then(function(){T("from",!0)}):r.resolve()}var x={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=A,s.setDaysSelectionModeExtended=P}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function m(){return!!u.request.toil_to_accrue}function f(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=k.from_date!==u.request.from_date||k.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&B.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&B.hasExpirationFromAdminSettings,t=B.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return B.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){B.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(T)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function w(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function A(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function D(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),L(),l(),x())})})}function P(){u.isMode("view")||(C(),w(),D())}function T(t){return s.valuesOf("hrleaveandabsences_toil_amounts",{},t).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function R(){return l(),x(),L()}function S(){return I(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),j?j=!1:x(),L()}function x(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function O(){k=e.cloneDeep(u.request.attributes())}function I(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function E(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){T(!1)})}function L(){return f()?d().catch(a.resolve):a.resolve()}function M(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var k,j=!u.isMode("create"),B={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=m,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=A,u.initWatchersExtended=P,u.onDateChangeExtended=R,u.openToilInDaysAccrualOptionsEditor=E,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=M,function(){O(),I(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","api.optionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,m,f,p,h,v,g,b,y,_,q,$,C){function w(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function A(){["from","to"].forEach(w)}function D(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Re.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=P();return Le.isMode("edit")&&(e=e&&(V()||T())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function x(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function O(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==F())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function I(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){fe("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(Pe[e],function(e){return Le.requestStatuses[e]})}function F(){return Le.request?Le.request.request_type:Le.leaveType||null}function U(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Re,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Oe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Pe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Pe.awaiting_approval=e,Pe.more_information_required=e,Pe.rejected=e,Pe.approved=e,Pe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?f.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Te++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=F(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:xe}),e}function Q(){if(Ie="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Ie="admin")}).then(function(){return"staff"===Ie&&u(_.permissions.ssp.manage).then(function(e){e&&(Ie="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Ie===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){De={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:De.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){xe=e.contactId})}function le(){return Le.selectedContactId?f.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?f.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==xe})}):f.find(xe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){D(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Re[e+"_date"]})}function he(e){if(Le.absenceTypes=me(De.types,e),!Le.absenceTypes.length)return r.reject(Oe)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Re=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,x(),A(),Le.request.isValid().then(ee()&&O).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?Ae():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Te&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Te>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function we(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?fe("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var De,Pe={},Te=0,Re={},Se=[],xe="",Oe="No entitlement",Ie="",Ee=[],Le=n.assign(this,m);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=R,Le.canSubmit=S,Le.closeAlert=I,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=U,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=we,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM), +H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function D(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function P(e,t){return D(t).then(function(t){H.sections[e].data=t.list})}function T(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(O))}function R(){return P("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function S(){return P("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function x(){return P("holidays",{public_holiday:!0})}function O(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function I(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function E(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function L(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){k(e)})}function k(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([C(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([T(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&O(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:k,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:x},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([I(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([C(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return D(n,e),e})):r.reject([])}function f(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),R(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(w)).then(function(){["from","to"].forEach(function(e){b(e),T(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(R)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&T(e,!0))})}function $(e,t){return m(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return w(e).then(function(){T(e,!0)})})}function w(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){x[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return x[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function A(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function D(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function P(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),w("from").then(function(){T("from",!0)})):r.resolve()}function T(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=x[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function R(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?w("from").then(function(){T("from",!0)}):r.resolve()}var x={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=A,s.setDaysSelectionModeExtended=P}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function m(){return!!u.request.toil_to_accrue}function f(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=k.from_date!==u.request.from_date||k.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&B.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&B.hasExpirationFromAdminSettings,t=B.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return B.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){B.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(T)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function w(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function A(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function D(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),L(),l(),x())})})}function P(){u.isMode("view")||(C(),w(),D())}function T(t){return s.valuesOf("hrleaveandabsences_toil_amounts",{},t).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function R(){return l(),x(),L()}function S(){return I(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),j?j=!1:x(),L()}function x(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function O(){k=e.cloneDeep(u.request.attributes())}function I(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function E(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){T(!1)})}function L(){return f()?d().catch(a.resolve):a.resolve()}function M(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var k,j=!u.isMode("create"),B={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=m,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=A,u.initWatchersExtended=P,u.onDateChangeExtended=R,u.openToilInDaysAccrualOptionsEditor=E,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=M,function(){O(),I(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,m,f,p,h,v,g,b,y,_,q,$,C){function w(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function A(){["from","to"].forEach(w)}function D(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Re.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=P();return Le.isMode("edit")&&(e=e&&(V()||T())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function x(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function O(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==F())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function I(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){fe("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(Pe[e],function(e){return Le.requestStatuses[e]})}function F(){return Le.request?Le.request.request_type:Le.leaveType||null}function U(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Re,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Oe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Pe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Pe.awaiting_approval=e,Pe.more_information_required=e,Pe.rejected=e,Pe.approved=e,Pe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?f.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Te++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=F(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:xe}),e}function Q(){if(Ie="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Ie="admin")}).then(function(){return"staff"===Ie&&u(_.permissions.ssp.manage).then(function(e){e&&(Ie="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Ie===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){De={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:De.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){xe=e.contactId})}function le(){return Le.selectedContactId?f.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?f.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==xe})}):f.find(xe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){D(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Re[e+"_date"]})}function he(e){if(Le.absenceTypes=me(De.types,e),!Le.absenceTypes.length)return r.reject(Oe)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Re=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,x(),A(),Le.request.isValid().then(ee()&&O).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?Ae():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Te&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Te>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function we(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?fe("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var De,Pe={},Te=0,Re={},Se=[],xe="",Oe="No entitlement",Ie="",Ee=[],Le=n.assign(this,m);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=R,Le.canSubmit=S,Le.closeAlert=I,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=U,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=we,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM), define("leave-absences/my-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/models/option-group","common/modules/dialog","common/services/check-permissions","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/my-leave/components/my-leave-container.component","leave-absences/my-leave/modules/config"],function(e){return e.module("my-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.mocks","common.models","common.services","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","my-leave.components","my-leave.config"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/my-leave":n+"/my-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/my-leave/app"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-my-leave]"),["my-leave"])})})}(CRM,require),define("my-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js index ec292edba55..315d79d8cb8 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js @@ -9,10 +9,10 @@ define([ controllers.controller('RequestModalDetailsToilController', RequestModalDetailsToilController); RequestModalDetailsToilController.$inject = ['$log', '$q', '$rootScope', - 'crmAngService', 'api.optionGroup', 'AbsenceType', 'detailsController']; + 'crmAngService', 'OptionGroup', 'AbsenceType', 'detailsController']; function RequestModalDetailsToilController ($log, $q, $rootScope, - crmAngService, OptionGroupAPI, AbsenceType, detailsController) { + crmAngService, OptionGroup, AbsenceType, detailsController) { $log.debug('RequestModalDetailsToilController'); var initialRequestAttributes; @@ -353,7 +353,7 @@ define([ * @return {Promise} */ function loadToilAmounts (cache) { - return OptionGroupAPI.valuesOf('hrleaveandabsences_toil_amounts', {}, cache) + return OptionGroup.valuesOf('hrleaveandabsences_toil_amounts', {}, cache) .then(function (amounts) { detailsController.toilAmounts = _.sortBy(amounts, 'value'); }); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js index a27f782da98..0f26d2f37ef 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js @@ -25,7 +25,7 @@ define([ describe('RequestModalDetailsToilController', function () { var $componentController, $provide, $q, $log, $rootScope, crmAngService, controller, AbsenceType, AbsenceTypeAPI, leaveRequest, LeaveRequestInstance, - OptionGroupAPI, TOILRequestInstance; + OptionGroup, TOILRequestInstance; var date2016 = '01/12/2016'; var date2016To = '02/12/2016'; // Must be greater than `date2016` @@ -48,13 +48,9 @@ define([ $provide.value('HR_settings', _HRSettingsMock_); }])); - beforeEach(inject(['api.optionGroup', function (_optionGroupAPI_) { - OptionGroupAPI = _optionGroupAPI_; - }])); - beforeEach(inject(function ( _$componentController_, _$q_, _$log_, _$rootScope_, _AbsenceType_, _AbsenceTypeAPI_, - _crmAngService_, _LeaveRequestInstance_, _TOILRequestInstance_) { + _crmAngService_, _LeaveRequestInstance_, _OptionGroup_, _TOILRequestInstance_) { $componentController = _$componentController_; $log = _$log_; $q = _$q_; @@ -63,13 +59,14 @@ define([ crmAngService = _crmAngService_; AbsenceTypeAPI = _AbsenceTypeAPI_; LeaveRequestInstance = _LeaveRequestInstance_; + OptionGroup = _OptionGroup_; TOILRequestInstance = _TOILRequestInstance_; spyOn($log, 'debug'); spyOn(AbsenceTypeAPI, 'calculateToilExpiryDate').and.callThrough(); spyOn(AbsenceType, 'canExpire').and.callThrough(); spyOn(AbsenceType, 'calculateToilExpiryDate').and.callThrough(); - spyOn(OptionGroupAPI, 'valuesOf').and.callThrough(); + spyOn(OptionGroup, 'valuesOf').and.callThrough(); crmAngService.loadForm = function () { return { @@ -108,7 +105,7 @@ define([ }); it('caches TOIL accrual options', function () { - expect(OptionGroupAPI.valuesOf.calls.mostRecent().args[2]).not.toBe(false); + expect(OptionGroup.valuesOf.calls.mostRecent().args[2]).not.toBe(false); }); it('sorts TOIL accrual options by value', function () { @@ -347,7 +344,7 @@ define([ }); it('does not cache TOIL accrual options', function () { - expect(OptionGroupAPI.valuesOf.calls.mostRecent().args[2]).toBe(false); + expect(OptionGroup.valuesOf.calls.mostRecent().args[2]).toBe(false); }); }); }); From 96a4836a66b7cbc992d1733b19c145c721ddcb4e Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Wed, 21 Mar 2018 15:46:00 +0000 Subject: [PATCH 101/203] PCHR-3476: Create upgrader to transform TOIL end time --- .../CRM/HRLeaveAndAbsences/Upgrader.php | 1 + .../HRLeaveAndAbsences/Upgrader/Step/1021.php | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php index fd996daf1bf..9b9fd3058a4 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php @@ -26,6 +26,7 @@ class CRM_HRLeaveAndAbsences_Upgrader extends CRM_HRLeaveAndAbsences_Upgrader_Ba use CRM_HRLeaveAndAbsences_Upgrader_Step_1018; use CRM_HRLeaveAndAbsences_Upgrader_Step_1019; use CRM_HRLeaveAndAbsences_Upgrader_Step_1020; + use CRM_HRLeaveAndAbsences_Upgrader_Step_1021; /** * A list of directories to be scanned for XML installation files diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php new file mode 100644 index 00000000000..e0e07b3cd49 --- /dev/null +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php @@ -0,0 +1,41 @@ +whereAdd('request_type = "' . LeaveRequest::REQUEST_TYPE_TOIL . '"'); + $leaveRequest->whereAdd('is_deleted = 0'); + $leaveRequest->find(); + + while ($leaveRequest->fetch()) { + $leaveRequest->to_date = substr($leaveRequest->to_date, 0, 11) . '23:45:00'; + + $leaveRequest->update(); + } + + return TRUE; + } +} From f2634e767ea27993286f083f0ede4674531c0f7f Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Tue, 3 Apr 2018 13:23:11 +0100 Subject: [PATCH 102/203] PCHR-3426: PR Feedback --- org.civicrm.reqangular/dist/reqangular.min.js | 8 +- .../src/common/models/option-group.js | 7 +- .../src/common/services/api.js | 20 +-- .../src/common/services/api/option-group.js | 7 +- .../src/common/services/crm-ang.service.js | 4 +- .../test/models/option-group.spec.js | 18 +-- .../test/services/api.spec.js | 131 +++++++++--------- .../test/services/api/option-group.spec.js | 22 +-- .../test/services/crm-ang.service.spec.js | 5 +- .../js/angular/dist/absence-tab.min.js | 4 +- .../js/angular/dist/admin-dashboard.min.js | 6 +- .../js/angular/dist/manager-leave.min.js | 4 +- .../js/angular/dist/my-leave.min.js | 10 +- .../src/leave-absences/absence-tab/app.js | 1 + .../src/leave-absences/admin-dashboard/app.js | 1 + .../src/leave-absences/manager-leave/app.js | 1 + .../src/leave-absences/my-leave/app.js | 1 + .../request-modal-details-toil.controller.js | 15 +- ...uest-modal-details-toil.controller.spec.js | 39 ++++-- .../leave-request-popup/details-tab/toil.html | 12 +- 20 files changed, 151 insertions(+), 165 deletions(-) diff --git a/org.civicrm.reqangular/dist/reqangular.min.js b/org.civicrm.reqangular/dist/reqangular.min.js index 92f4e7a2f35..63e8a9ee0b9 100644 --- a/org.civicrm.reqangular/dist/reqangular.min.js +++ b/org.civicrm.reqangular/dist/reqangular.min.js @@ -114,8 +114,8 @@ return e=os.day(e),e.setMonth(0,1),e},function(e,t){e.setFullYear(e.getFullYear( e.x=(e.x-l.x)*r[0],e.y=(l.y-e.y)*r[1]}:function(e){e.x=(e.x-d)/(p-d)*r[0],e.y=(1-(l.y?e.y/l.y:1))*r[1]}),s}var t=na.layout.hierarchy().sort(null).value(null),n=Ei,r=[1,1],i=!1;return e.separation=function(t){return arguments.length?(n=t,e):n},e.size=function(t){return arguments.length?(i=null==(r=t),e):i?null:r},e.nodeSize=function(t){return arguments.length?(i=null!=(r=t),e):i?r:null},Qr(e,t)},na.layout.treemap=function(){function e(e,t){for(var n,r,i=-1,o=e.length;++it?0:t),n.area=isNaN(r)||0>=r?0:r}function t(n){var o=n.children;if(o&&o.length){var a,s,l,u=f(n),c=[],d=o.slice(),h=1/0,m="slice"===p?u.dx:"dice"===p?u.dy:"slice-dice"===p?1&n.depth?u.dy:u.dx:Math.min(u.dx,u.dy);for(e(d,u.dx*u.dy/n.value),c.area=0;(l=d.length)>0;)c.push(a=d[l-1]),c.area+=a.area,"squarify"!==p||(s=r(c,m))<=h?(d.pop(),h=s):(c.area-=c.pop().area,i(c,m,u,!1),m=Math.min(u.dx,u.dy),c.length=c.area=0,h=1/0);c.length&&(i(c,m,u,!0),c.length=c.area=0),o.forEach(t)}}function n(t){var r=t.children;if(r&&r.length){var o,a=f(t),s=r.slice(),l=[];for(e(s,a.dx*a.dy/t.value),l.area=0;o=s.pop();)l.push(o),l.area+=o.area,null!=o.z&&(i(l,o.z?a.dx:a.dy,a,!s.length),l.length=l.area=0);r.forEach(n)}}function r(e,t){for(var n,r=e.area,i=0,o=1/0,a=-1,s=e.length;++an&&(o=n),n>i&&(i=n));return r*=r,t*=t,r?Math.max(t*i*h/r,r/(t*o*h)):1/0}function i(e,t,n,r){var i,o=-1,a=e.length,s=n.x,u=n.y,c=t?l(e.area/t):0;if(t==n.dx){for((r||c>n.dy)&&(c=n.dy);++on.dx)&&(c=n.dx);++on&&(t=1),1>n&&(e=0),function(){var n,r,i;do{n=2*Math.random()-1,r=2*Math.random()-1,i=n*n+r*r}while(!i||i>1);return e+t*n*Math.sqrt(-2*Math.log(i)/i)}},logNormal:function(){var e=na.random.normal.apply(na,arguments);return function(){return Math.exp(e())}},bates:function(e){var t=na.random.irwinHall(e);return function(){return t()/e}},irwinHall:function(e){return function(){for(var t=0,n=0;e>n;n++)t+=Math.random();return t}}},na.scale={};var ml={floor:y,ceil:y};na.scale.linear=function(){return Vi([0,1],[0,1],yr,!1)};var gl={s:1,g:1,p:1,r:1,e:1};na.scale.log=function(){return Ji(na.scale.linear().domain([0,1]),10,!0,[1,10])};var vl=na.format(".0e"),yl={floor:function(e){return-Math.ceil(-e)},ceil:function(e){return-Math.floor(-e)}};na.scale.pow=function(){return Qi(na.scale.linear(),1,[0,1])},na.scale.sqrt=function(){return na.scale.pow().exponent(.5)},na.scale.ordinal=function(){return eo([],{t:"range",a:[[]]})},na.scale.category10=function(){return na.scale.ordinal().range(bl)},na.scale.category20=function(){return na.scale.ordinal().range($l)},na.scale.category20b=function(){return na.scale.ordinal().range(wl)},na.scale.category20c=function(){return na.scale.ordinal().range(xl)};var bl=[2062260,16744206,2924588,14034728,9725885,9197131,14907330,8355711,12369186,1556175].map(be),$l=[2062260,11454440,16744206,16759672,2924588,10018698,14034728,16750742,9725885,12955861,9197131,12885140,14907330,16234194,8355711,13092807,12369186,14408589,1556175,10410725].map(be),wl=[3750777,5395619,7040719,10264286,6519097,9216594,11915115,13556636,9202993,12426809,15186514,15190932,8666169,11356490,14049643,15177372,8077683,10834324,13528509,14589654].map(be),xl=[3244733,7057110,10406625,13032431,15095053,16616764,16625259,16634018,3253076,7652470,10607003,13101504,7695281,10394312,12369372,14342891,6513507,9868950,12434877,14277081].map(be);na.scale.quantile=function(){return to([],[])},na.scale.quantize=function(){return no(0,1,[0,1])},na.scale.threshold=function(){return ro([.5],[0,1])},na.scale.identity=function(){return io([0,1])},na.svg={},na.svg.arc=function(){function e(){var e=Math.max(0,+n.apply(this,arguments)),u=Math.max(0,+r.apply(this,arguments)),c=a.apply(this,arguments)-Na,f=s.apply(this,arguments)-Na,d=Math.abs(f-c),p=c>f?0:1;if(e>u&&(h=u,u=e,e=h),d>=Oa)return t(u,p)+(e?t(e,1-p):"")+"Z";var h,m,g,v,y,b,$,w,x,C,k,E,S=0,_=0,M=[];if((v=(+l.apply(this,arguments)||0)/2)&&(g=o===Cl?Math.sqrt(e*e+u*u):+o.apply(this,arguments),p||(_*=-1),u&&(_=te(g/u*Math.sin(v))),e&&(S=te(g/e*Math.sin(v)))),u){y=u*Math.cos(c+_),b=u*Math.sin(c+_),$=u*Math.cos(f-_),w=u*Math.sin(f-_);var T=Math.abs(f-c-2*_)<=Da?0:1;if(_&&fo(y,b,$,w)===p^T){var D=(c+f)/2;y=u*Math.cos(D),b=u*Math.sin(D),$=w=null}}else y=b=0;if(e){x=e*Math.cos(f-S),C=e*Math.sin(f-S),k=e*Math.cos(c+S),E=e*Math.sin(c+S);var A=Math.abs(c-f+2*S)<=Da?0:1;if(S&&fo(x,C,k,E)===1-p^A){var O=(c+f)/2;x=e*Math.cos(O),C=e*Math.sin(O),k=E=null}}else x=C=0;if((h=Math.min(Math.abs(u-e)/2,+i.apply(this,arguments)))>.001){m=u>e^p?0:1;var N=null==k?[x,C]:null==$?[y,b]:Nn([y,b],[k,E],[$,w],[x,C]),R=y-N[0],I=b-N[1],P=$-N[0],F=w-N[1],j=1/Math.sin(Math.acos((R*P+I*F)/(Math.sqrt(R*R+I*I)*Math.sqrt(P*P+F*F)))/2),L=Math.sqrt(N[0]*N[0]+N[1]*N[1]);if(null!=$){var U=Math.min(h,(u-L)/(j+1)),H=po(null==k?[x,C]:[k,E],[y,b],u,U,p),q=po([$,w],[x,C],u,U,p);h===U?M.push("M",H[0],"A",U,",",U," 0 0,",m," ",H[1],"A",u,",",u," 0 ",1-p^fo(H[1][0],H[1][1],q[1][0],q[1][1]),",",p," ",q[1],"A",U,",",U," 0 0,",m," ",q[0]):M.push("M",H[0],"A",U,",",U," 0 1,",m," ",q[0])}else M.push("M",y,",",b);if(null!=k){var V=Math.min(h,(e-L)/(j-1)),z=po([y,b],[k,E],e,-V,p),B=po([x,C],null==$?[y,b]:[$,w],e,-V,p);h===V?M.push("L",B[0],"A",V,",",V," 0 0,",m," ",B[1],"A",e,",",e," 0 ",p^fo(B[1][0],B[1][1],z[1][0],z[1][1]),",",1-p," ",z[1],"A",V,",",V," 0 0,",m," ",z[0]):M.push("L",B[0],"A",V,",",V," 0 0,",m," ",z[0])}else M.push("L",x,",",C)}else M.push("M",y,",",b),null!=$&&M.push("A",u,",",u," 0 ",T,",",p," ",$,",",w),M.push("L",x,",",C),null!=k&&M.push("A",e,",",e," 0 ",A,",",1-p," ",k,",",E);return M.push("Z"),M.join("")}function t(e,t){return"M0,"+e+"A"+e+","+e+" 0 1,"+t+" 0,"+-e+"A"+e+","+e+" 0 1,"+t+" 0,"+e}var n=ao,r=so,i=oo,o=Cl,a=lo,s=uo,l=co;return e.innerRadius=function(t){return arguments.length?(n=Se(t),e):n},e.outerRadius=function(t){return arguments.length?(r=Se(t),e):r},e.cornerRadius=function(t){return arguments.length?(i=Se(t),e):i},e.padRadius=function(t){return arguments.length?(o=t==Cl?Cl:Se(t),e):o},e.startAngle=function(t){return arguments.length?(a=Se(t),e):a},e.endAngle=function(t){return arguments.length?(s=Se(t),e):s},e.padAngle=function(t){return arguments.length?(l=Se(t),e):l},e.centroid=function(){var e=(+n.apply(this,arguments)+ +r.apply(this,arguments))/2,t=(+a.apply(this,arguments)+ +s.apply(this,arguments))/2-Na;return[Math.cos(t)*e,Math.sin(t)*e]},e};var Cl="auto";na.svg.line=function(){return ho(y)};var kl=na.map({linear:mo,"linear-closed":go,step:vo,"step-before":yo,"step-after":bo,basis:Eo,"basis-open":So,"basis-closed":_o,bundle:Mo,cardinal:xo,"cardinal-open":$o,"cardinal-closed":wo,monotone:Ro});kl.forEach(function(e,t){t.key=e,t.closed=/-closed$/.test(e)});var El=[0,2/3,1/3,0],Sl=[0,1/3,2/3,0],_l=[0,1/6,2/3,1/6];na.svg.line.radial=function(){var e=ho(Io);return e.radius=e.x,delete e.x,e.angle=e.y,delete e.y,e},yo.reverse=bo,bo.reverse=yo,na.svg.area=function(){return Po(y)},na.svg.area.radial=function(){var e=Po(Io);return e.radius=e.x,delete e.x,e.innerRadius=e.x0,delete e.x0,e.outerRadius=e.x1,delete e.x1,e.angle=e.y,delete e.y,e.startAngle=e.y0,delete e.y0,e.endAngle=e.y1,delete e.y1,e},na.svg.chord=function(){function e(e,s){var l=t(this,o,e,s),u=t(this,a,e,s);return"M"+l.p0+r(l.r,l.p1,l.a1-l.a0)+(n(l,u)?i(l.r,l.p1,l.r,l.p0):i(l.r,l.p1,u.r,u.p0)+r(u.r,u.p1,u.a1-u.a0)+i(u.r,u.p1,l.r,l.p0))+"Z"}function t(e,t,n,r){var i=t.call(e,n,r),o=s.call(e,i,r),a=l.call(e,i,r)-Na,c=u.call(e,i,r)-Na;return{r:o,a0:a,a1:c,p0:[o*Math.cos(a),o*Math.sin(a)],p1:[o*Math.cos(c),o*Math.sin(c)]}}function n(e,t){return e.a0==t.a0&&e.a1==t.a1}function r(e,t,n){return"A"+e+","+e+" 0 "+ +(n>Da)+",1 "+t}function i(e,t,n,r){return"Q 0,0 "+r}var o=yn,a=bn,s=Fo,l=lo,u=uo;return e.radius=function(t){return arguments.length?(s=Se(t),e):s},e.source=function(t){return arguments.length?(o=Se(t),e):o},e.target=function(t){return arguments.length?(a=Se(t),e):a},e.startAngle=function(t){return arguments.length?(l=Se(t),e):l},e.endAngle=function(t){return arguments.length?(u=Se(t),e):u},e},na.svg.diagonal=function(){function e(e,i){var o=t.call(this,e,i),a=n.call(this,e,i),s=(o.y+a.y)/2,l=[o,{x:o.x,y:s},{x:a.x,y:s},a];return l=l.map(r),"M"+l[0]+"C"+l[1]+" "+l[2]+" "+l[3]}var t=yn,n=bn,r=jo;return e.source=function(n){return arguments.length?(t=Se(n),e):t},e.target=function(t){return arguments.length?(n=Se(t),e):n},e.projection=function(t){return arguments.length?(r=t,e):r},e},na.svg.diagonal.radial=function(){var e=na.svg.diagonal(),t=jo,n=e.projection;return e.projection=function(e){return arguments.length?n(Lo(t=e)):t},e},na.svg.symbol=function(){function e(e,r){return(Ml.get(t.call(this,e,r))||qo)(n.call(this,e,r))}var t=Ho,n=Uo;return e.type=function(n){return arguments.length?(t=Se(n),e):t},e.size=function(t){return arguments.length?(n=Se(t),e):n},e};var Ml=na.map({circle:qo,cross:function(e){var t=Math.sqrt(e/5)/2;return"M"+-3*t+","+-t+"H"+-t+"V"+-3*t+"H"+t+"V"+-t+"H"+3*t+"V"+t+"H"+t+"V"+3*t+"H"+-t+"V"+t+"H"+-3*t+"Z"},diamond:function(e){var t=Math.sqrt(e/(2*Dl)),n=t*Dl;return"M0,"+-t+"L"+n+",0 0,"+t+" "+-n+",0Z"},square:function(e){var t=Math.sqrt(e)/2;return"M"+-t+","+-t+"L"+t+","+-t+" "+t+","+t+" "+-t+","+t+"Z"},"triangle-down":function(e){var t=Math.sqrt(e/Tl),n=t*Tl/2;return"M0,"+n+"L"+t+","+-n+" "+-t+","+-n+"Z"},"triangle-up":function(e){var t=Math.sqrt(e/Tl),n=t*Tl/2;return"M0,"+-n+"L"+t+","+n+" "+-t+","+n+"Z"}});na.svg.symbolTypes=Ml.keys();var Tl=Math.sqrt(3),Dl=Math.tan(30*Ra);wa.transition=function(e){for(var t,n,r=Al||++Il,i=Wo(e),o=[],a=Ol||{time:Date.now(),ease:Er,delay:0,duration:250},s=-1,l=this.length;++so;o++){i.push(t=[]);for(var n=this[o],s=0,l=n.length;l>s;s++)(r=n[s])&&e.call(r,r.__data__,s,o)&&t.push(r)}return zo(i,this.namespace,this.id)},Rl.tween=function(e,t){var n=this.id,r=this.namespace;return arguments.length<2?this.node()[r][n].tween.get(e):V(this,null==t?function(t){t[r][n].tween.remove(e)}:function(i){i[r][n].tween.set(e,t)})},Rl.attr=function(e,t){function n(){this.removeAttribute(s)}function r(){this.removeAttributeNS(s.space,s.local)}function i(e){return null==e?n:(e+="",function(){var t,n=this.getAttribute(s);return n!==e&&(t=a(n,e),function(e){this.setAttribute(s,t(e))})})}function o(e){return null==e?r:(e+="",function(){var t,n=this.getAttributeNS(s.space,s.local);return n!==e&&(t=a(n,e),function(e){this.setAttributeNS(s.space,s.local,t(e))})})}if(arguments.length<2){for(t in e)this.attr(t,e[t]);return this}var a="transform"==e?Hr:yr,s=na.ns.qualify(e);return Bo(this,"attr."+e,t,s.local?o:i)},Rl.attrTween=function(e,t){function n(e,n){var r=t.call(this,e,n,this.getAttribute(i));return r&&function(e){this.setAttribute(i,r(e))}}function r(e,n){var r=t.call(this,e,n,this.getAttributeNS(i.space,i.local));return r&&function(e){this.setAttributeNS(i.space,i.local,r(e))}}var i=na.ns.qualify(e);return this.tween("attr."+e,i.local?r:n)},Rl.style=function(e,n,r){function i(){this.style.removeProperty(e)}function o(n){return null==n?i:(n+="",function(){var i,o=t(this).getComputedStyle(this,null).getPropertyValue(e);return o!==n&&(i=yr(o,n),function(t){this.style.setProperty(e,i(t),r)})})}var a=arguments.length;if(3>a){if("string"!=typeof e){2>a&&(n="");for(r in e)this.style(r,e[r],n);return this}r=""}return Bo(this,"style."+e,n,o)},Rl.styleTween=function(e,n,r){function i(i,o){var a=n.call(this,i,o,t(this).getComputedStyle(this,null).getPropertyValue(e));return a&&function(t){this.style.setProperty(e,a(t),r)}}return arguments.length<3&&(r=""),this.tween("style."+e,i)},Rl.text=function(e){return Bo(this,"text",e,Yo)},Rl.remove=function(){var e=this.namespace;return this.each("end.transition",function(){var t;this[e].count<2&&(t=this.parentNode)&&t.removeChild(this)})},Rl.ease=function(e){var t=this.id,n=this.namespace;return arguments.length<1?this.node()[n][t].ease:("function"!=typeof e&&(e=na.ease.apply(na,arguments)),V(this,function(r){r[n][t].ease=e}))},Rl.delay=function(e){var t=this.id,n=this.namespace;return arguments.length<1?this.node()[n][t].delay:V(this,"function"==typeof e?function(r,i,o){r[n][t].delay=+e.call(r,r.__data__,i,o)}:(e=+e,function(r){r[n][t].delay=e}))},Rl.duration=function(e){var t=this.id,n=this.namespace;return arguments.length<1?this.node()[n][t].duration:V(this,"function"==typeof e?function(r,i,o){r[n][t].duration=Math.max(1,e.call(r,r.__data__,i,o))}:(e=Math.max(1,e),function(r){r[n][t].duration=e}))},Rl.each=function(e,t){var n=this.id,r=this.namespace;if(arguments.length<2){var i=Ol,o=Al;try{Al=n,V(this,function(t,i,o){Ol=t[r][n],e.call(t,t.__data__,i,o)})}finally{Ol=i,Al=o}}else V(this,function(i){var o=i[r][n];(o.event||(o.event=na.dispatch("start","end","interrupt"))).on(e,t)});return this},Rl.transition=function(){for(var e,t,n,r,i=this.id,o=++Il,a=this.namespace,s=[],l=0,u=this.length;u>l;l++){s.push(e=[]);for(var t=this[l],c=0,f=t.length;f>c;c++)(n=t[c])&&(r=n[a][i],Go(n,c,a,o,{time:r.time,ease:r.ease,delay:r.delay+r.duration,duration:r.duration})),e.push(n)}return zo(s,a,o)},na.svg.axis=function(){function e(e){e.each(function(){var e,u=na.select(this),c=this.__chart__||n,f=this.__chart__=n.copy(),d=null==l?f.ticks?f.ticks.apply(f,s):f.domain():l,p=null==t?f.tickFormat?f.tickFormat.apply(f,s):y:t,h=u.selectAll(".tick").data(d,f),m=h.enter().insert("g",".domain").attr("class","tick").style("opacity",Ma),g=na.transition(h.exit()).style("opacity",Ma).remove(),v=na.transition(h.order()).style("opacity",1),b=Math.max(i,0)+a,$=ji(f),w=u.selectAll(".domain").data([0]),x=(w.enter().append("path").attr("class","domain"),na.transition(w));m.append("line"),m.append("text");var C,k,E,S,_=m.select("line"),M=v.select("line"),T=h.select("text").text(p),D=m.select("text"),A=v.select("text"),O="top"===r||"left"===r?-1:1;if("bottom"===r||"top"===r?(e=Ko,C="x",E="y",k="x2",S="y2",T.attr("dy",0>O?"0em":".71em").style("text-anchor","middle"),x.attr("d","M"+$[0]+","+O*o+"V0H"+$[1]+"V"+O*o)):(e=Zo,C="y",E="x",k="y2",S="x2",T.attr("dy",".32em").style("text-anchor",0>O?"end":"start"),x.attr("d","M"+O*o+","+$[0]+"H0V"+$[1]+"H"+O*o)),_.attr(S,O*i),D.attr(E,O*b),M.attr(k,0).attr(S,O*i),A.attr(C,0).attr(E,O*b),f.rangeBand){var N=f,R=N.rangeBand()/2;c=f=function(e){return N(e)+R}}else c.rangeBand?c=f:g.call(e,f,c);m.call(e,c,f),v.call(e,f,f)})}var t,n=na.scale.linear(),r=Pl,i=6,o=6,a=3,s=[10],l=null;return e.scale=function(t){return arguments.length?(n=t,e):n},e.orient=function(t){return arguments.length?(r=t in Fl?t+"":Pl,e):r},e.ticks=function(){return arguments.length?(s=arguments,e):s},e.tickValues=function(t){return arguments.length?(l=t,e):l},e.tickFormat=function(n){return arguments.length?(t=n,e):t},e.tickSize=function(t){var n=arguments.length;return n?(i=+t,o=+arguments[n-1],e):i},e.innerTickSize=function(t){return arguments.length?(i=+t,e):i},e.outerTickSize=function(t){return arguments.length?(o=+t,e):o},e.tickPadding=function(t){return arguments.length?(a=+t,e):a},e.tickSubdivide=function(){return arguments.length&&e},e};var Pl="bottom",Fl={top:1,right:1,bottom:1,left:1};na.svg.brush=function(){function e(t){t.each(function(){var t=na.select(this).style("pointer-events","all").style("-webkit-tap-highlight-color","rgba(0,0,0,0)").on("mousedown.brush",o).on("touchstart.brush",o),a=t.selectAll(".background").data([0]);a.enter().append("rect").attr("class","background").style("visibility","hidden").style("cursor","crosshair"),t.selectAll(".extent").data([0]).enter().append("rect").attr("class","extent").style("cursor","move");var s=t.selectAll(".resize").data(m,y);s.exit().remove(),s.enter().append("g").attr("class",function(e){return"resize "+e}).style("cursor",function(e){return jl[e]}).append("rect").attr("x",function(e){return/[ew]$/.test(e)?-3:null}).attr("y",function(e){return/^[ns]/.test(e)?-3:null}).attr("width",6).attr("height",6).style("visibility","hidden"),s.style("display",e.empty()?"none":null);var l,f=na.transition(t),d=na.transition(a);u&&(l=ji(u),d.attr("x",l[0]).attr("width",l[1]-l[0]),r(f)),c&&(l=ji(c),d.attr("y",l[0]).attr("height",l[1]-l[0]),i(f)),n(f)})}function n(e){e.selectAll(".resize").attr("transform",function(e){return"translate("+f[+/e$/.test(e)]+","+d[+/^s/.test(e)]+")"})}function r(e){e.select(".extent").attr("x",f[0]),e.selectAll(".extent,.n>rect,.s>rect").attr("width",f[1]-f[0])}function i(e){e.select(".extent").attr("y",d[0]),e.selectAll(".extent,.e>rect,.w>rect").attr("height",d[1]-d[0])}function o(){function o(){32==na.event.keyCode&&(T||(b=null,A[0]-=f[1],A[1]-=d[1],T=2),k())}function m(){32==na.event.keyCode&&2==T&&(A[0]+=f[1],A[1]+=d[1],T=0,k())}function g(){var e=na.mouse(w),t=!1;$&&(e[0]+=$[0],e[1]+=$[1]),T||(na.event.altKey?(b||(b=[(f[0]+f[1])/2,(d[0]+d[1])/2]),A[0]=f[+(e[0]c?(i=r,r=c):i=c),m[0]!=r||m[1]!=i?(n?s=null:a=null,m[0]=r,m[1]=i,!0):void 0}function y(){g(),E.style("pointer-events","all").selectAll(".resize").style("display",e.empty()?"none":null),na.select("body").style("cursor",null),O.on("mousemove.brush",null).on("mouseup.brush",null).on("touchmove.brush",null).on("touchend.brush",null).on("keydown.brush",null).on("keyup.brush",null),D(),C({type:"brushend"})}var b,$,w=this,x=na.select(na.event.target),C=l.of(w,arguments),E=na.select(w),S=x.datum(),_=!/^(n|s)$/.test(S)&&u,M=!/^(e|w)$/.test(S)&&c,T=x.classed("extent"),D=K(w),A=na.mouse(w),O=na.select(t(w)).on("keydown.brush",o).on("keyup.brush",m);if(na.event.changedTouches?O.on("touchmove.brush",g).on("touchend.brush",y):O.on("mousemove.brush",g).on("mouseup.brush",y),E.interrupt().selectAll("*").interrupt(),T)A[0]=f[0]-A[0],A[1]=d[0]-A[1];else if(S){var N=+/w$/.test(S),R=+/^n/.test(S);$=[f[1-N]-A[0],d[1-R]-A[1]],A[0]=f[N],A[1]=d[R]}else na.event.altKey&&(b=A.slice());E.style("pointer-events","none").selectAll(".resize").style("display",null),na.select("body").style("cursor",x.style("cursor")),C({type:"brushstart"}),g()}var a,s,l=S(e,"brushstart","brush","brushend"),u=null,c=null,f=[0,0],d=[0,0],p=!0,h=!0,m=Ll[0];return e.event=function(e){e.each(function(){var e=l.of(this,arguments),t={x:f,y:d,i:a,j:s},n=this.__chart__||t;this.__chart__=t,Al?na.select(this).transition().each("start.brush",function(){a=n.i,s=n.j,f=n.x,d=n.y,e({type:"brushstart"})}).tween("brush:brush",function(){var n=br(f,t.x),r=br(d,t.y);return a=s=null,function(i){f=t.x=n(i),d=t.y=r(i),e({type:"brush",mode:"resize"})}}).each("end.brush",function(){a=t.i,s=t.j,e({type:"brush",mode:"resize"}),e({type:"brushend"})}):(e({type:"brushstart"}),e({type:"brush",mode:"resize"}),e({type:"brushend"}))})},e.x=function(t){return arguments.length?(u=t,m=Ll[!u<<1|!c],e):u},e.y=function(t){return arguments.length?(c=t,m=Ll[!u<<1|!c],e):c},e.clamp=function(t){return arguments.length?(u&&c?(p=!!t[0],h=!!t[1]):u?p=!!t:c&&(h=!!t),e):u&&c?[p,h]:u?p:c?h:null},e.extent=function(t){var n,r,i,o,l;return arguments.length?(u&&(n=t[0],r=t[1],c&&(n=n[0],r=r[0]),a=[n,r],u.invert&&(n=u(n),r=u(r)),n>r&&(l=n,n=r,r=l),(n!=f[0]||r!=f[1])&&(f=[n,r])),c&&(i=t[0],o=t[1],u&&(i=i[1],o=o[1]),s=[i,o],c.invert&&(i=c(i),o=c(o)),i>o&&(l=i,i=o,o=l),(i!=d[0]||o!=d[1])&&(d=[i,o])),e):(u&&(a?(n=a[0],r=a[1]):(n=f[0],r=f[1],u.invert&&(n=u.invert(n),r=u.invert(r)),n>r&&(l=n,n=r,r=l))),c&&(s?(i=s[0],o=s[1]):(i=d[0],o=d[1],c.invert&&(i=c.invert(i),o=c.invert(o)),i>o&&(l=i,i=o,o=l))),u&&c?[[n,i],[r,o]]:u?[n,r]:c&&[i,o])},e.clear=function(){return e.empty()||(f=[0,0],d=[0,0],a=s=null),e},e.empty=function(){return!!u&&f[0]==f[1]||!!c&&d[0]==d[1]},na.rebind(e,l,"on")};var jl={n:"ns-resize",e:"ew-resize",s:"ns-resize",w:"ew-resize",nw:"nwse-resize",ne:"nesw-resize",se:"nwse-resize",sw:"nesw-resize"},Ll=[["n","e","s","w","nw","ne","se","sw"],["e","w"],["n","s"],[]],Ul=os.format=fs.timeFormat,Hl=Ul.utc,ql=Hl("%Y-%m-%dT%H:%M:%S.%LZ");Ul.iso=Date.prototype.toISOString&&+new Date("2000-01-01T00:00:00.000Z")?Jo:ql,Jo.parse=function(e){var t=new Date(e);return isNaN(t)?null:t},Jo.toString=ql.toString,os.second=Le(function(e){return new as(1e3*Math.floor(e/1e3))},function(e,t){e.setTime(e.getTime()+1e3*Math.floor(t))},function(e){return e.getSeconds()}),os.seconds=os.second.range,os.seconds.utc=os.second.utc.range,os.minute=Le(function(e){return new as(6e4*Math.floor(e/6e4))},function(e,t){e.setTime(e.getTime()+6e4*Math.floor(t))},function(e){return e.getMinutes()}),os.minutes=os.minute.range,os.minutes.utc=os.minute.utc.range,os.hour=Le(function(e){var t=e.getTimezoneOffset()/60;return new as(36e5*(Math.floor(e/36e5-t)+t))},function(e,t){e.setTime(e.getTime()+36e5*Math.floor(t))},function(e){return e.getHours()}),os.hours=os.hour.range,os.hours.utc=os.hour.utc.range,os.month=Le(function(e){return e=os.day(e),e.setDate(1),e},function(e,t){e.setMonth(e.getMonth()+t)},function(e){return e.getMonth()}),os.months=os.month.range,os.months.utc=os.month.utc.range;var Vl=[1e3,5e3,15e3,3e4,6e4,3e5,9e5,18e5,36e5,108e5,216e5,432e5,864e5,1728e5,6048e5,2592e6,7776e6,31536e6],zl=[[os.second,1],[os.second,5],[os.second,15],[os.second,30],[os.minute,1],[os.minute,5],[os.minute,15],[os.minute,30],[os.hour,1],[os.hour,3],[os.hour,6],[os.hour,12],[os.day,1],[os.day,2],[os.week,1],[os.month,1],[os.month,3],[os.year,1]],Bl=Ul.multi([[".%L",function(e){return e.getMilliseconds()}],[":%S",function(e){return e.getSeconds()}],["%I:%M",function(e){return e.getMinutes()}],["%I %p",function(e){return e.getHours()}],["%a %d",function(e){return e.getDay()&&1!=e.getDate()}],["%b %d",function(e){return 1!=e.getDate()}],["%B",function(e){return e.getMonth()}],["%Y",Mt]]),Yl={range:function(e,t,n){return na.range(Math.ceil(e/n)*n,+t,n).map(Xo)},floor:y,ceil:y};zl.year=os.year,os.scale=function(){return Qo(na.scale.linear(),zl,Bl)};var Wl=zl.map(function(e){return[e[0].utc,e[1]]}),Gl=Hl.multi([[".%L",function(e){return e.getUTCMilliseconds()}],[":%S",function(e){return e.getUTCSeconds()}],["%I:%M",function(e){return e.getUTCMinutes()}],["%I %p",function(e){return e.getUTCHours()}],["%a %d",function(e){return e.getUTCDay()&&1!=e.getUTCDate()}],["%b %d",function(e){return 1!=e.getUTCDate()}],["%B",function(e){return e.getUTCMonth()}],["%Y",Mt]]);Wl.year=os.year.utc,os.scale.utc=function(){return Qo(na.scale.linear(),Wl,Gl)},na.text=_e(function(e){return e.responseText}),na.json=function(e,t){return Me(e,"application/json",ea,t)},na.html=function(e,t){return Me(e,"text/html",ta,t)},na.xml=_e(function(e){return e.responseXML}),"function"==typeof define&&define.amd?define("common/d3",na):"object"==typeof module&&module.exports&&(module.exports=na),this.d3=na}(),function(){function e(e,t){if(e!==t){var n=null===e,r=e===$,i=e===e,o=null===t,a=t===$,s=t===t;if(e>t&&!o||!i||n&&!a&&s||r&&s)return 1;if(e=e&&9<=e&&13>=e||32==e||160==e||5760==e||6158==e||8192<=e&&(8202>=e||8232==e||8233==e||8239==e||8287==e||12288==e||65279==e)}function m(e,t){for(var n=-1,r=e.length,i=-1,o=[];++n=I&&gi&&ci?new Ue(t):null,u=t.length;l&&(a=He,s=!1,t=l);e:for(;++oa(t,l,0)&&i.push(l);return i}function st(e,t){var n=!0;return Ri(e,function(e,r,i){return n=!!t(e,r,i)}),n}function lt(e,t,n,r){var i=r,o=i;return Ri(e,function(e,a,s){a=+t(e,a,s),(n(a,i)||a===r&&a===o)&&(i=a,o=e)}),o}function ut(e,t){var n=[];return Ri(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}function ct(e,t,n,r){var i;return n(e,function(e,n,o){return t(e,n,o)?(i=r?n:e,!1):void 0}),i}function ft(e,t,n,r){r||(r=[]);for(var i=-1,o=e.length;++it&&(t=-t>i?0:i+t),n=n===$||n>i?i:+n||0,0>n&&(n+=i),i=t>n?0:n-t>>>0,t>>>=0,n=Ur(i);++r=u)break e;o=r[o],i*="asc"===o||!0===o?1:-1;break e}i=t.b-n.b}return i})}function Ot(e,t){var n=0;return Ri(e,function(e,r,i){n+=+t(e,r,i)||0}),n}function Nt(e,t){var r=-1,i=xn(),o=e.length,a=i===n,s=a&&o>=I,l=s&&gi&&ci?new Ue(void 0):null,u=[];l?(i=He,a=!1):(s=!1,l=t?[]:u);e:for(;++ri(l,f,0)&&((t||s)&&l.push(f),u.push(c))}return u}function Rt(e,t){for(var n=-1,r=t.length,i=Ur(r);++n>>1,a=e[o];(n?a<=t:ai?$:o,i=1);++r=I)return t.plant(r).value();for(var i=0,e=n?o[i].apply(this,e):r;++iarguments.length;return"function"==typeof r&&o===$&&Mo(n)?e(n,r,i,a):_t(n,$n(r,o,4),i,a,t)}}function fn(e,t,n,r,i,o,a,s,l,u){function c(){for(var b=arguments.length,w=b,k=Ur(b);w--;)k[w]=arguments[w];if(r&&(k=Ht(k,r,i)),o&&(k=qt(k,o,a)),h||v){var w=c.placeholder,E=m(k,w),b=b-E.length;if(bt?0:t)):[]}function zn(e,t,n){var r=e?e.length:0;return r?((n?An(e,t,n):null==t)&&(t=1),t=r-(+t||0),Mt(e,0,0>t?0:t)):[]}function Bn(e){return e?e[0]:$}function Yn(e,t,r){var i=e?e.length:0;if(!i)return-1;if("number"==typeof r)r=0>r?wi(i+r,0):r;else if(r)return r=Ft(e,t),rn?wi(i+n,0):n||0,"string"==typeof e||!Mo(e)&&wr(e)?n<=i&&-1t?0:+t||0,r);++n=e&&(t=$),n}}function lr(e,t,n){function r(t,n){n&&ai(n),l=d=p=$,t&&(h=ho(),u=e.apply(f,s),d||l||(s=f=$))}function i(){var e=t-(ho()-c);0>=e||e>t?r(p,l):d=fi(i,e)}function o(){r(g,d)}function a(){if(s=arguments,c=ho(),f=this,p=g&&(d||!v),!1===m)var n=v&&!d;else{l||v||(h=c);var r=m-(c-h),a=0>=r||r>m;a?(l&&(l=ai(l)),h=c,u=e.apply(f,s)):l||(l=fi(o,r))}return a&&d?d=ai(d):d||t===m||(d=fi(i,t)),n&&(a=!0,u=e.apply(f,s)),!a||d||l||(s=f=$),u}var s,l,u,c,f,d,p,h=0,m=!1,g=!0;if("function"!=typeof e)throw new Kr(j);if(t=0>t?0:+t||0,!0===n)var v=!0,g=!1;else gr(n)&&(v=!!n.leading,m="maxWait"in n&&wi(+n.maxWait||0,t),g="trailing"in n?!!n.trailing:g);return a.cancel=function(){d&&ai(d),l&&ai(l),h=0,l=d=p=$},a}function ur(e,t){function n(){var r=arguments,i=t?t.apply(this,r):r[0],o=n.cache;return o.has(i)?o.get(i):(r=e.apply(this,r),n.cache=o.set(i,r),r)}if("function"!=typeof e||t&&"function"!=typeof t)throw new Kr(j);return n.cache=new ur.Cache,n}function cr(e,t){if("function"!=typeof e)throw new Kr(j);return t=wi(t===$?e.length-1:+t||0,0),function(){for(var n=arguments,r=-1,i=wi(n.length-t,0),o=Ur(i);++rt}function dr(e){return p(e)&&Tn(e)&&ei.call(e,"callee")&&!ui.call(e,"callee")}function pr(e,t,n,r){return r=(n="function"==typeof n?Lt(n,r,3):$)?n(e,t):$,r===$?vt(e,t,n):!!r}function hr(e){return p(e)&&"string"==typeof e.message&&ni.call(e)==z}function mr(e){return gr(e)&&ni.call(e)==B}function gr(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function vr(e){return null!=e&&(mr(e)?ii.test(Xr.call(e)):p(e)&&Se.test(e))}function yr(e){return"number"==typeof e||p(e)&&ni.call(e)==Y}function br(e){var t;if(!p(e)||ni.call(e)!=W||dr(e)||!(ei.call(e,"constructor")||"function"!=typeof(t=e.constructor)||t instanceof t))return!1;var n;return dt(e,function(e,t){n=t}),n===$||ei.call(e,n)}function $r(e){return gr(e)&&ni.call(e)==G}function wr(e){return"string"==typeof e||p(e)&&ni.call(e)==K}function xr(e){return p(e)&&Rn(e.length)&&!!Ne[ni.call(e)]}function Cr(e,t){return e(t=+t)||!e||!bi(t))return n;do{t%2&&(n+=e),t=vi(t/2),e+=e}while(t);return n}function Or(e,t,n){var r=e;return(e=i(e))?(n?An(r,t,n):null==t)?e.slice(g(e),v(e)+1):(t+="",e.slice(o(e,t),a(e,t)+1)):e}function Nr(e,t,n){return n&&An(e,t,n)&&(t=$),e=i(e),e.match(t||Ae)||[]}function Rr(e,t,n){return n&&An(e,t,n)&&(t=$),p(e)?Pr(e):rt(e,t)}function Ir(e){return e}function Pr(e){return $t(it(e,!0))}function Fr(e,t,n){if(null==n){var r=gr(t),i=r?Lo(t):$;((i=i&&i.length?mt(t,i):$)?i.length:r)||(i=!1,n=t,t=e,e=this)}i||(i=mt(t,Lo(t)));var o=!0,r=-1,a=mr(e),s=i.length;!1===n?o=!1:gr(n)&&"chain"in n&&(o=n.chain);for(;++r=N)return n}else e=0;return ji(n,r)}}(),qi=cr(function(e,t){return p(e)&&Tn(e)?at(e,ft(t,!1,!0)):[]}),Vi=en(),zi=en(!0),Bi=cr(function(e){for(var t=e.length,r=t,i=Ur(c),o=xn(),a=o===n,s=[];r--;){var l=e[r]=Tn(l=e[r])?l:[];i[r]=a&&120<=l.length&&gi&&ci?new Ue(r&&l):null}var a=e[0],u=-1,c=a?a.length:0,f=i[0];e:for(;++u(f?He(f,l):o(s,l,0))){for(r=t;--r;){var d=i[r];if(0>(d?He(d,l):o(e[r],l,0)))continue e}f&&f.push(l),s.push(l)}return s}),Yi=cr(function(t,n){n=ft(n);var r=tt(t,n);return Et(t,n.sort(e)),r}),Wi=mn(),Gi=mn(!0),Ki=cr(function(e){return Nt(ft(e,!1,!0))}),Zi=cr(function(e,t){return Tn(e)?at(e,t):[]}),Ji=cr(Zn),Qi=cr(function(e){var t=e.length,n=2--e?t.apply(this,arguments):void 0}},Ie.ary=function(e,t,n){return n&&An(e,t,n)&&(t=$),t=e&&null==t?e.length:wi(+t||0,0),gn(e,T,$,$,$,$,t)},Ie.assign=Do,Ie.at=eo,Ie.before=sr,Ie.bind=mo,Ie.bindAll=go,Ie.bindKey=vo,Ie.callback=Rr,Ie.chain=Xn,Ie.chunk=function(e,t,n){t=(n?An(e,t,n):null==t)?1:wi(vi(t)||1,1),n=0;for(var r=e?e.length:0,i=-1,o=Ur(mi(r/t));nn&&(n=-n>i?0:i+n),r=r===$||r>i?i:+r||0,0>r&&(r+=i),i=n>r?0:r>>>0,n>>>=0;nt?0:t)):[]},Ie.takeRight=function(e,t,n){var r=e?e.length:0;return r?((n?An(e,t,n):null==t)&&(t=1),t=r-(+t||0),Mt(e,0>t?0:t)):[]},Ie.takeRightWhile=function(e,t,n){return e&&e.length?It(e,$n(t,n,3),!1,!0):[]},Ie.takeWhile=function(e,t,n){return e&&e.length?It(e,$n(t,n,3)):[]},Ie.tap=function(e,t,n){return t.call(n,e),e},Ie.throttle=function(e,t,n){var r=!0,i=!0;if("function"!=typeof e)throw new Kr(j);return!1===n?r=!1:gr(n)&&(r="leading"in n?!!n.leading:r,i="trailing"in n?!!n.trailing:i),lr(e,t,{leading:r,maxWait:+t,trailing:i})},Ie.thru=er,Ie.times=function(e,t,n){if(1>(e=vi(e))||!bi(e))return[];var r=-1,i=Ur(xi(e,4294967295));for(t=Lt(t,n,1);++rr?i[r]=t(r):t(r);return i},Ie.toArray=kr,Ie.toPlainObject=Er,Ie.transform=function(e,t,n,r){var i=Mo(e)||xr(e);return t=$n(t,r,4),null==n&&(i||gr(e)?(r=e.constructor,n=i?Mo(e)?new r:[]:Ni(mr(r)?r.prototype:$)):n={}),(i?Ve:pt)(e,function(e,r,i){return t(n,e,r,i)}),n},Ie.union=Ki,Ie.uniq=Kn,Ie.unzip=Zn,Ie.unzipWith=Jn,Ie.values=Tr,Ie.valuesIn=function(e){return Rt(e,_r(e))},Ie.where=function(e,t){return nr(e,$t(t))},Ie.without=Zi,Ie.wrap=function(e,t){return t=null==t?Ir:t,gn(t,_,$,[e],[])},Ie.xor=function(){for(var e=-1,t=arguments.length;++en?0:+n||0,r),0<=(n-=t.length)&&e.indexOf(t,n)==n},Ie.escape=function(e){return(e=i(e))&&de.test(e)?e.replace(ce,u):e},Ie.escapeRegExp=function(e){return(e=i(e))&&$e.test(e)?e.replace(be,c):e||"(?:)"},Ie.every=tr,Ie.find=no,Ie.findIndex=Vi,Ie.findKey=No,Ie.findLast=ro,Ie.findLastIndex=zi,Ie.findLastKey=Ro,Ie.findWhere=function(e,t){return no(e,$t(t))},Ie.first=Bn,Ie.floor=ea,Ie.get=function(e,t,n){return e=null==e?$:gt(e,Hn(t),t+""),e===$?n:e},Ie.gt=fr,Ie.gte=function(e,t){return e>=t},Ie.has=function(e,t){if(null==e)return!1;var n=ei.call(e,t);if(!n&&!On(t)){if(t=Hn(t),null==(e=1==t.length?e:gt(e,Mt(t,0,-1))))return!1;t=Wn(t),n=ei.call(e,t)}return n||Rn(e.length)&&Dn(t,e.length)&&(Mo(e)||dr(e))},Ie.identity=Ir,Ie.includes=rr,Ie.indexOf=Yn,Ie.inRange=function(e,t,n){return t=+t||0,n===$?(n=t,t=0):n=+n||0,e>=xi(t,n)&&en?wi(r+n,0):xi(n||0,r-1))+1;else if(n)return i=Ft(e,t,!0)-1,e=e[i],(t===t?t===e:e!==e)?i:-1;if(t!==t)return d(e,i,!0);for(;i--;)if(e[i]===t)return i;return-1},Ie.lt=Cr,Ie.lte=function(e,t){return e<=t},Ie.max=ta,Ie.min=na,Ie.noConflict=function(){return Ye._=ri,this},Ie.noop=jr,Ie.now=ho,Ie.pad=function(e,t,n){e=i(e),t=+t;var r=e.length;return rn?0:+n||0,e.length), e.lastIndexOf(t,n)==n},Ie.sum=function(e,t,n){if(n&&An(e,t,n)&&(t=$),t=$n(t,n,3),1==t.length){e=Mo(e)?e:Ln(e),n=e.length;for(var r=0;n--;)r+=+t(e[n])||0;e=r}else e=Ot(e,t);return e},Ie.template=function(e,t,n){var r=Ie.templateSettings;n&&An(e,t,n)&&(t=n=$),e=i(e),t=Xe(et({},n||t),r,Qe),n=Xe(et({},t.imports),r.imports,Qe);var o,a,s=Lo(n),l=Rt(n,s),u=0;n=t.interpolate||Te;var c="__p+='";n=Wr((t.escape||Te).source+"|"+n.source+"|"+(n===me?Ce:Te).source+"|"+(t.evaluate||Te).source+"|$","g");var d="sourceURL"in t?"//# sourceURL="+t.sourceURL+"\n":"";if(e.replace(n,function(t,n,r,i,s,l){return r||(r=i),c+=e.slice(u,l).replace(De,f),n&&(o=!0,c+="'+__e("+n+")+'"),s&&(a=!0,c+="';"+s+";\n__p+='"),r&&(c+="'+((__t=("+r+"))==null?'':__t)+'"),u=l+t.length,t}),c+="';",(t=t.variable)||(c="with(obj){"+c+"}"),c=(a?c.replace(ae,""):c).replace(se,"$1").replace(le,"$1;"),c="function("+(t||"obj")+"){"+(t?"":"obj||(obj={});")+"var __t,__p=''"+(o?",__e=_.escape":"")+(a?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+c+"return __p}",t=Zo(function(){return Vr(s,d+"return "+c).apply($,l)}),t.source=c,hr(t))throw t;return t},Ie.trim=Or,Ie.trimLeft=function(e,t,n){var r=e;return(e=i(e))?e.slice((n?An(r,t,n):null==t)?g(e):o(e,t+"")):e},Ie.trimRight=function(e,t,n){var r=e;return(e=i(e))?(n?An(r,t,n):null==t)?e.slice(0,v(e)+1):e.slice(0,a(e,t+"")+1):e},Ie.trunc=function(e,t,n){n&&An(e,t,n)&&(t=$);var r=A;if(n=O,null!=t)if(gr(t)){var o="separator"in t?t.separator:o,r="length"in t?+t.length||0:r;n="omission"in t?i(t.omission):n}else r=+t||0;if(e=i(e),r>=e.length)return e;if(1>(r-=n.length))return n;if(t=e.slice(0,r),null==o)return t+n;if($r(o)){if(e.slice(r).search(o)){var a,s=e.slice(0,r);for(o.global||(o=Wr(o.source,(ke.exec(o)||"")+"g")),o.lastIndex=0;e=o.exec(s);)a=e.index;t=t.slice(0,null==a?r:a)}}else e.indexOf(o,r)!=r&&-1<(o=t.lastIndexOf(o))&&(t=t.slice(0,o));return t+n},Ie.unescape=function(e){return(e=i(e))&&fe.test(e)?e.replace(ue,y):e},Ie.uniqueId=function(e){var t=++ti;return i(e)+t},Ie.words=Nr,Ie.all=tr,Ie.any=ar,Ie.contains=rr,Ie.eq=pr,Ie.detect=no,Ie.foldl=co,Ie.foldr=fo,Ie.head=Bn,Ie.include=rr,Ie.inject=co,Fr(Ie,function(){var e={};return pt(Ie,function(t,n){Ie.prototype[n]||(e[n]=t)}),e}(),!1),Ie.sample=or,Ie.prototype.sample=function(e){return this.__chain__||null!=e?this.thru(function(t){return or(t,e)}):or(this.value())},Ie.VERSION=w,Ve("bind bindKey curry curryRight partial partialRight".split(" "),function(e){Ie[e].placeholder=Ie}),Ve(["drop","take"],function(e,t){je.prototype[e]=function(n){var r=this.__filtered__;if(r&&!t)return new je(this);n=null==n?1:wi(vi(n)||0,0);var i=this.clone();return r?i.__takeCount__=xi(i.__takeCount__,n):i.__views__.push({size:n,type:e+(0>i.__dir__?"Right":"")}),i},je.prototype[e+"Right"]=function(t){return this.reverse()[e](t).reverse()}}),Ve(["filter","map","takeWhile"],function(e,t){var n=t+1,r=n!=F;je.prototype[e]=function(e,t){var i=this.clone();return i.__iteratees__.push({iteratee:$n(e,t,1),type:n}),i.__filtered__=i.__filtered__||r,i}}),Ve(["first","last"],function(e,t){var n="take"+(t?"Right":"");je.prototype[e]=function(){return this[n](1).value()[0]}}),Ve(["initial","rest"],function(e,t){var n="drop"+(t?"":"Right");je.prototype[e]=function(){return this.__filtered__?new je(this):this[n](1)}}),Ve(["pluck","where"],function(e,t){var n=t?"filter":"map",r=t?$t:Lr;je.prototype[e]=function(e){return this[n](r(e))}}),je.prototype.compact=function(){return this.filter(Ir)},je.prototype.reject=function(e,t){return e=$n(e,t,1),this.filter(function(t){return!e(t)})},je.prototype.slice=function(e,t){e=null==e?0:+e||0;var n=this;return n.__filtered__&&(0t)?new je(n):(0>e?n=n.takeRight(-e):e&&(n=n.drop(e)),t!==$&&(t=+t||0,n=0>t?n.dropRight(-t):n.take(t-e)),n)},je.prototype.takeRightWhile=function(e,t){return this.reverse().takeWhile(e,t).reverse()},je.prototype.toArray=function(){return this.take(_i)},pt(je.prototype,function(e,t){var n=/^(?:filter|map|reject)|While$/.test(t),r=/^(?:first|last)$/.test(t),i=Ie[r?"take"+("last"==t?"Right":""):t];i&&(Ie.prototype[t]=function(){function t(e){return r&&a?i(e,1)[0]:i.apply($,Ke([e],o))}var o=r?[1]:arguments,a=this.__chain__,s=this.__wrapped__,l=!!this.__actions__.length,u=s instanceof je,c=o[0],f=u||Mo(s);return f&&n&&"function"==typeof c&&1!=c.length&&(u=f=!1),c={func:er,args:[t],thisArg:$},l=u&&!l,r&&!a?l?(s=s.clone(),s.__actions__.push(c),e.call(s)):i.call($,this.value())[0]:!r&&f?(s=l?s:new je(this),s=e.apply(s,o),s.__actions__.push(c),new Fe(s,a)):this.thru(t)})}),Ve("join pop push replace shift sort splice split unshift".split(" "),function(e){var t=(/^(?:replace|split)$/.test(e)?Qr:Zr)[e],n=/^(?:push|sort|unshift)$/.test(e)?"tap":"thru",r=/^(?:join|pop|replace|shift)$/.test(e);Ie.prototype[e]=function(){var e=arguments;return r&&!this.__chain__?t.apply(this.value(),e):this[n](function(n){return t.apply(n,e)})}}),pt(je.prototype,function(e,t){var n=Ie[t];if(n){var r=n.name+"";(Oi[r]||(Oi[r]=[])).push({name:t,func:n})}}),Oi[fn($,C).name]=[{name:"wrapper",func:$}],je.prototype.clone=function(){var e=new je(this.__wrapped__);return e.__actions__=qe(this.__actions__),e.__dir__=this.__dir__,e.__filtered__=this.__filtered__,e.__iteratees__=qe(this.__iteratees__),e.__takeCount__=this.__takeCount__,e.__views__=qe(this.__views__),e},je.prototype.reverse=function(){if(this.__filtered__){var e=new je(this);e.__dir__=-1,e.__filtered__=!0}else e=this.clone(),e.__dir__*=-1;return e},je.prototype.value=function(){var e,t=this.__wrapped__.value(),n=this.__dir__,r=Mo(t),i=0>n,o=r?t.length:0;e=o;for(var a=this.__views__,s=0,l=-1,u=a.length;++l"'`]/g,fe=RegExp(ue.source),de=RegExp(ce.source),pe=/<%-([\s\S]+?)%>/g,he=/<%([\s\S]+?)%>/g,me=/<%=([\s\S]+?)%>/g,ge=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/,ve=/^\w*$/,ye=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g,be=/^[:!,]|[\\^$.*+?()[\]{}|\/]|(^[0-9a-fA-Fnrtuvx])|([\n\r\u2028\u2029])/g,$e=RegExp(be.source),we=/[\u0300-\u036f\ufe20-\ufe23]/g,xe=/\\(\\)?/g,Ce=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,ke=/\w*$/,Ee=/^0[xX]/,Se=/^\[object .+?Constructor\]$/,_e=/^\d+$/,Me=/[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g,Te=/($^)/,De=/['\n\r\u2028\u2029\\]/g,Ae=RegExp("[A-Z\\xc0-\\xd6\\xd8-\\xde]+(?=[A-Z\\xc0-\\xd6\\xd8-\\xde][a-z\\xdf-\\xf6\\xf8-\\xff]+)|[A-Z\\xc0-\\xd6\\xd8-\\xde]?[a-z\\xdf-\\xf6\\xf8-\\xff]+|[A-Z\\xc0-\\xd6\\xd8-\\xde]+|[0-9]+","g"),Oe="Array ArrayBuffer Date Error Float32Array Float64Array Function Int8Array Int16Array Int32Array Math Number Object RegExp Set String _ clearTimeout isFinite parseFloat parseInt setTimeout TypeError Uint8Array Uint8ClampedArray Uint16Array Uint32Array WeakMap".split(" "),Ne={};Ne[J]=Ne[Q]=Ne[X]=Ne[ee]=Ne[te]=Ne[ne]=Ne[re]=Ne[ie]=Ne[oe]=!0,Ne[U]=Ne[H]=Ne[Z]=Ne[q]=Ne[V]=Ne[z]=Ne[B]=Ne["[object Map]"]=Ne[Y]=Ne[W]=Ne[G]=Ne["[object Set]"]=Ne[K]=Ne["[object WeakMap]"]=!1;var Re={};Re[U]=Re[H]=Re[Z]=Re[q]=Re[V]=Re[J]=Re[Q]=Re[X]=Re[ee]=Re[te]=Re[Y]=Re[W]=Re[G]=Re[K]=Re[ne]=Re[re]=Re[ie]=Re[oe]=!0,Re[z]=Re[B]=Re["[object Map]"]=Re["[object Set]"]=Re["[object WeakMap]"]=!1;var Ie={"À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","Ç":"C","ç":"c","Ð":"D","ð":"d","È":"E","É":"E","Ê":"E","Ë":"E","è":"e","é":"e","ê":"e","ë":"e","Ì":"I","Í":"I","Î":"I","Ï":"I","ì":"i","í":"i","î":"i","ï":"i","Ñ":"N","ñ":"n","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","Ù":"U","Ú":"U","Û":"U","Ü":"U","ù":"u","ú":"u","û":"u","ü":"u","Ý":"Y","ý":"y","ÿ":"y","Æ":"Ae","æ":"ae","Þ":"Th","þ":"th","ß":"ss"},Pe={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},Fe={"&":"&","<":"<",">":">",""":'"',"'":"'","`":"`"},je={function:!0,object:!0},Le={0:"x30",1:"x31",2:"x32",3:"x33",4:"x34",5:"x35",6:"x36",7:"x37",8:"x38",9:"x39",A:"x41",B:"x42",C:"x43",D:"x44",E:"x45",F:"x46",a:"x61",b:"x62",c:"x63",d:"x64",e:"x65",f:"x66",n:"x6e",r:"x72",t:"x74",u:"x75",v:"x76",x:"x78"},Ue={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},He=je[typeof exports]&&exports&&!exports.nodeType&&exports,qe=je[typeof module]&&module&&!module.nodeType&&module,Ve=je[typeof self]&&self&&self.Object&&self,ze=je[typeof window]&&window&&window.Object&&window,Be=qe&&qe.exports===He&&He,Ye=He&&qe&&"object"==typeof global&&global&&global.Object&&global||ze!==(this&&this.window)&&ze||Ve||this,We=b();"function"==typeof define&&"object"==typeof define.amd&&define.amd?(Ye._=We,define("common/lodash",[],function(){return We})):He&&qe?Be?(qe.exports=We)._=We:He._=We:Ye._=We}.call(this),function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define("common/moment",t):e.moment=t()}(this,function(){"use strict";function e(){return Yn.apply(null,arguments)}function t(e){return"[object Array]"===Object.prototype.toString.call(e)}function n(e){return e instanceof Date||"[object Date]"===Object.prototype.toString.call(e)}function r(e,t){var n,r=[];for(n=0;n0)for(n in Gn)r=Gn[n],i=t[r],f(i)||(e[r]=i);return e}function p(t){d(this,t),this._d=new Date(null!=t._d?t._d.getTime():NaN),!1===Kn&&(Kn=!0,e.updateOffset(this),Kn=!1)}function h(e){return e instanceof p||null!=e&&null!=e._isAMomentObject}function m(e){return 0>e?Math.ceil(e):Math.floor(e)}function g(e){var t=+e,n=0;return 0!==t&&isFinite(t)&&(n=m(t)),n}function v(e,t,n){var r,i=Math.min(e.length,t.length),o=Math.abs(e.length-t.length),a=0;for(r=0;i>r;r++)(n&&e[r]!==t[r]||!n&&g(e[r])!==g(t[r]))&&a++;return a+o}function y(){}function b(e){return e?e.toLowerCase().replace("_","-"):e}function $(e){for(var t,n,r,i,o=0;o0;){if(r=w(i.slice(0,t).join("-")))return r;if(n&&n.length>=t&&v(i,n,!0)>=t-1)break;t--}o++}return null}function w(e){var t=null;if(!Zn[e]&&"undefined"!=typeof module&&module&&module.exports)try{t=Wn._abbr,require("./locale/"+e),x(t)}catch(e){}return Zn[e]}function x(e,t){var n;return e&&(n=f(t)?k(e):C(e,t))&&(Wn=n),Wn._abbr}function C(e,t){return null!==t?(t.abbr=e,Zn[e]=Zn[e]||new y,Zn[e].set(t),x(e),Zn[e]):(delete Zn[e],null)}function k(e){var n;if(e&&e._locale&&e._locale._abbr&&(e=e._locale._abbr),!e)return Wn;if(!t(e)){if(n=w(e))return n;e=[e]}return $(e)}function E(e,t){var n=e.toLowerCase();Jn[n]=Jn[n+"s"]=Jn[t]=e}function S(e){return"string"==typeof e?Jn[e]||Jn[e.toLowerCase()]:void 0}function _(e){var t,n,r={};for(n in e)i(e,n)&&(t=S(n))&&(r[t]=e[n]);return r}function M(e){return e instanceof Function||"[object Function]"===Object.prototype.toString.call(e)}function T(t,n){return function(r){return null!=r?(A(this,t,r),e.updateOffset(this,n),this):D(this,t)}}function D(e,t){return e.isValid()?e._d["get"+(e._isUTC?"UTC":"")+t]():NaN}function A(e,t,n){e.isValid()&&e._d["set"+(e._isUTC?"UTC":"")+t](n)}function O(e,t){var n;if("object"==typeof e)for(n in e)this.set(n,e[n]);else if(e=S(e),M(this[e]))return this[e](t);return this}function N(e,t,n){var r=""+Math.abs(e),i=t-r.length;return(e>=0?n?"+":"":"-")+Math.pow(10,Math.max(0,i)).toString().substr(1)+r}function R(e,t,n,r){var i=r;"string"==typeof r&&(i=function(){return this[r]()}),e&&(tr[e]=i),t&&(tr[t[0]]=function(){return N(i.apply(this,arguments),t[1],t[2])}),n&&(tr[n]=function(){return this.localeData().ordinal(i.apply(this,arguments),e)})}function I(e){return e.match(/\[[\s\S]/)?e.replace(/^\[|\]$/g,""):e.replace(/\\/g,"")}function P(e){var t,n,r=e.match(Qn);for(t=0,n=r.length;n>t;t++)tr[r[t]]?r[t]=tr[r[t]]:r[t]=I(r[t]);return function(i){var o="";for(t=0;n>t;t++)o+=r[t]instanceof Function?r[t].call(i,e):r[t];return o}}function F(e,t){return e.isValid()?(t=j(t,e.localeData()),er[t]=er[t]||P(t),er[t](e)):e.localeData().invalidDate()}function j(e,t){function n(e){return t.longDateFormat(e)||e}var r=5;for(Xn.lastIndex=0;r>=0&&Xn.test(e);)e=e.replace(Xn,n),Xn.lastIndex=0,r-=1;return e}function L(e,t,n){br[e]=M(t)?t:function(e,r){return e&&n?n:t}}function U(e,t){return i(br,e)?br[e](t._strict,t._locale):new RegExp(H(e))}function H(e){return q(e.replace("\\","").replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g,function(e,t,n,r,i){return t||n||r||i}))}function q(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}function V(e,t){var n,r=t;for("string"==typeof e&&(e=[e]),"number"==typeof t&&(r=function(e,n){n[t]=g(e)}),n=0;nr;r++){if(i=a([2e3,r]),n&&!this._longMonthsParse[r]&&(this._longMonthsParse[r]=new RegExp("^"+this.months(i,"").replace(".","")+"$","i"),this._shortMonthsParse[r]=new RegExp("^"+this.monthsShort(i,"").replace(".","")+"$","i")),n||this._monthsParse[r]||(o="^"+this.months(i,"")+"|^"+this.monthsShort(i,""),this._monthsParse[r]=new RegExp(o.replace(".",""),"i")),n&&"MMMM"===t&&this._longMonthsParse[r].test(e))return r;if(n&&"MMM"===t&&this._shortMonthsParse[r].test(e))return r;if(!n&&this._monthsParse[r].test(e))return r}}function Z(e,t){var n;return e.isValid()?"string"==typeof t&&"number"!=typeof(t=e.localeData().monthsParse(t))?e:(n=Math.min(e.date(),Y(e.year(),t)),e._d["set"+(e._isUTC?"UTC":"")+"Month"](t,n),e):e}function J(t){return null!=t?(Z(this,t),e.updateOffset(this,!0),this):D(this,"Month")}function Q(){return Y(this.year(),this.month())}function X(e){return this._monthsParseExact?(i(this,"_monthsRegex")||te.call(this),e?this._monthsShortStrictRegex:this._monthsShortRegex):this._monthsShortStrictRegex&&e?this._monthsShortStrictRegex:this._monthsShortRegex}function ee(e){return this._monthsParseExact?(i(this,"_monthsRegex")||te.call(this),e?this._monthsStrictRegex:this._monthsRegex):this._monthsStrictRegex&&e?this._monthsStrictRegex:this._monthsRegex}function te(){function e(e,t){return t.length-e.length}var t,n,r=[],i=[],o=[];for(t=0;12>t;t++)n=a([2e3,t]),r.push(this.monthsShort(n,"")),i.push(this.months(n,"")),o.push(this.months(n,"")),o.push(this.monthsShort(n,""));for(r.sort(e),i.sort(e),o.sort(e),t=0;12>t;t++)r[t]=q(r[t]),i[t]=q(i[t]),o[t]=q(o[t]);this._monthsRegex=new RegExp("^("+o.join("|")+")","i"),this._monthsShortRegex=this._monthsRegex,this._monthsStrictRegex=new RegExp("^("+i.join("|")+")$","i"),this._monthsShortStrictRegex=new RegExp("^("+r.join("|")+")$","i")}function ne(e){var t,n=e._a;return n&&-2===l(e).overflow&&(t=n[xr]<0||n[xr]>11?xr:n[Cr]<1||n[Cr]>Y(n[wr],n[xr])?Cr:n[kr]<0||n[kr]>24||24===n[kr]&&(0!==n[Er]||0!==n[Sr]||0!==n[_r])?kr:n[Er]<0||n[Er]>59?Er:n[Sr]<0||n[Sr]>59?Sr:n[_r]<0||n[_r]>999?_r:-1,l(e)._overflowDayOfYear&&(wr>t||t>Cr)&&(t=Cr),l(e)._overflowWeeks&&-1===t&&(t=Mr),l(e)._overflowWeekday&&-1===t&&(t=Tr),l(e).overflow=t),e}function re(t){!1===e.suppressDeprecationWarnings&&"undefined"!=typeof console&&console.warn&&console.warn("Deprecation warning: "+t)}function ie(e,t){var n=!0;return o(function(){return n&&(re(e+"\nArguments: "+Array.prototype.slice.call(arguments).join(", ")+"\n"+(new Error).stack),n=!1),t.apply(this,arguments)},t)}function oe(e,t){Ir[e]||(re(t),Ir[e]=!0)}function ae(e){var t,n,r,i,o,a,s=e._i,u=Pr.exec(s)||Fr.exec(s);if(u){for(l(e).iso=!0,t=0,n=Lr.length;n>t;t++)if(Lr[t][1].exec(u[1])){i=Lr[t][0],r=!1!==Lr[t][2];break}if(null==i)return void(e._isValid=!1);if(u[3]){for(t=0,n=Ur.length;n>t;t++)if(Ur[t][1].exec(u[3])){o=(u[2]||" ")+Ur[t][0];break}if(null==o)return void(e._isValid=!1)}if(!r&&null!=o)return void(e._isValid=!1);if(u[4]){if(!jr.exec(u[4]))return void(e._isValid=!1);a="Z"}e._f=i+(o||"")+(a||""),we(e)}else e._isValid=!1}function se(t){var n=Hr.exec(t._i);return null!==n?void(t._d=new Date(+n[1])):(ae(t),void(!1===t._isValid&&(delete t._isValid,e.createFromInputFallback(t))))}function le(e,t,n,r,i,o,a){var s=new Date(e,t,n,r,i,o,a);return 100>e&&e>=0&&isFinite(s.getFullYear())&&s.setFullYear(e),s}function ue(e){var t=new Date(Date.UTC.apply(null,arguments));return 100>e&&e>=0&&isFinite(t.getUTCFullYear())&&t.setUTCFullYear(e),t}function ce(e){return fe(e)?366:365}function fe(e){return e%4==0&&e%100!=0||e%400==0}function de(){return fe(this.year())}function pe(e,t,n){var r=7+t-n;return-(7+ue(e,0,r).getUTCDay()-t)%7+r-1}function he(e,t,n,r,i){var o,a,s=(7+n-r)%7,l=pe(e,r,i),u=1+7*(t-1)+s+l;return 0>=u?(o=e-1,a=ce(o)+u):u>ce(e)?(o=e+1,a=u-ce(e)):(o=e,a=u),{year:o,dayOfYear:a}}function me(e,t,n){var r,i,o=pe(e.year(),t,n),a=Math.floor((e.dayOfYear()-o-1)/7)+1;return 1>a?(i=e.year()-1,r=a+ge(i,t,n)):a>ge(e.year(),t,n)?(r=a-ge(e.year(),t,n),i=e.year()+1):(i=e.year(),r=a),{week:r,year:i}}function ge(e,t,n){var r=pe(e,t,n),i=pe(e+1,t,n);return(ce(e)-r+i)/7}function ve(e,t,n){return null!=e?e:null!=t?t:n}function ye(t){var n=new Date(e.now());return t._useUTC?[n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate()]:[n.getFullYear(),n.getMonth(),n.getDate()]}function be(e){var t,n,r,i,o=[];if(!e._d){for(r=ye(e),e._w&&null==e._a[Cr]&&null==e._a[xr]&&$e(e),e._dayOfYear&&(i=ve(e._a[wr],r[wr]),e._dayOfYear>ce(i)&&(l(e)._overflowDayOfYear=!0),n=ue(i,0,e._dayOfYear),e._a[xr]=n.getUTCMonth(),e._a[Cr]=n.getUTCDate()),t=0;3>t&&null==e._a[t];++t)e._a[t]=o[t]=r[t];for(;7>t;t++)e._a[t]=o[t]=null==e._a[t]?2===t?1:0:e._a[t];24===e._a[kr]&&0===e._a[Er]&&0===e._a[Sr]&&0===e._a[_r]&&(e._nextDay=!0,e._a[kr]=0),e._d=(e._useUTC?ue:le).apply(null,o),null!=e._tzm&&e._d.setUTCMinutes(e._d.getUTCMinutes()-e._tzm),e._nextDay&&(e._a[kr]=24)}}function $e(e){var t,n,r,i,o,a,s,u;t=e._w,null!=t.GG||null!=t.W||null!=t.E?(o=1,a=4,n=ve(t.GG,e._a[wr],me(Te(),1,4).year),r=ve(t.W,1),(1>(i=ve(t.E,1))||i>7)&&(u=!0)):(o=e._locale._week.dow,a=e._locale._week.doy,n=ve(t.gg,e._a[wr],me(Te(),o,a).year),r=ve(t.w,1),null!=t.d?(0>(i=t.d)||i>6)&&(u=!0):null!=t.e?(i=t.e+o,(t.e<0||t.e>6)&&(u=!0)):i=o),1>r||r>ge(n,o,a)?l(e)._overflowWeeks=!0:null!=u?l(e)._overflowWeekday=!0:(s=he(n,r,i,o,a),e._a[wr]=s.year,e._dayOfYear=s.dayOfYear)}function we(t){if(t._f===e.ISO_8601)return void ae(t);t._a=[],l(t).empty=!0;var n,r,i,o,a,s=""+t._i,u=s.length,c=0;for(i=j(t._f,t._locale).match(Qn)||[],n=0;n0&&l(t).unusedInput.push(a),s=s.slice(s.indexOf(r)+r.length),c+=r.length),tr[o]?(r?l(t).empty=!1:l(t).unusedTokens.push(o),B(o,r,t)):t._strict&&!r&&l(t).unusedTokens.push(o);l(t).charsLeftOver=u-c,s.length>0&&l(t).unusedInput.push(s),!0===l(t).bigHour&&t._a[kr]<=12&&t._a[kr]>0&&(l(t).bigHour=void 0),t._a[kr]=xe(t._locale,t._a[kr],t._meridiem),be(t),ne(t)}function xe(e,t,n){var r;return null==n?t:null!=e.meridiemHour?e.meridiemHour(t,n):null!=e.isPM?(r=e.isPM(n),r&&12>t&&(t+=12),r||12!==t||(t=0),t):t}function Ce(e){var t,n,r,i,a;if(0===e._f.length)return l(e).invalidFormat=!0,void(e._d=new Date(NaN));for(i=0;ia)&&(r=a,n=t));o(e,n||t)}function ke(e){if(!e._d){var t=_(e._i);e._a=r([t.year,t.month,t.day||t.date,t.hour,t.minute,t.second,t.millisecond],function(e){return e&&parseInt(e,10)}),be(e)}}function Ee(e){var t=new p(ne(Se(e)));return t._nextDay&&(t.add(1,"d"),t._nextDay=void 0),t}function Se(e){var r=e._i,i=e._f;return e._locale=e._locale||k(e._l),null===r||void 0===i&&""===r?c({nullInput:!0}):("string"==typeof r&&(e._i=r=e._locale.preparse(r)),h(r)?new p(ne(r)):(t(i)?Ce(e):i?we(e):n(r)?e._d=r:_e(e),u(e)||(e._d=null),e))}function _e(i){var o=i._i;void 0===o?i._d=new Date(e.now()):n(o)?i._d=new Date(+o):"string"==typeof o?se(i):t(o)?(i._a=r(o.slice(0),function(e){return parseInt(e,10)}),be(i)):"object"==typeof o?ke(i):"number"==typeof o?i._d=new Date(o):e.createFromInputFallback(i)}function Me(e,t,n,r,i){var o={};return"boolean"==typeof n&&(r=n,n=void 0),o._isAMomentObject=!0,o._useUTC=o._isUTC=i,o._l=n,o._i=e,o._f=t,o._strict=r,Ee(o)}function Te(e,t,n,r){return Me(e,t,n,r,!1)}function De(e,n){var r,i;if(1===n.length&&t(n[0])&&(n=n[0]),!n.length)return Te();for(r=n[0],i=1;ie&&(e=-e,n="-"),n+N(~~(e/60),2)+t+N(~~e%60,2)})}function Pe(e,t){var n=(t||"").match(e)||[],r=n[n.length-1]||[],i=(r+"").match(Yr)||["-",0,0],o=60*i[1]+g(i[2]);return"+"===i[0]?o:-o}function Fe(t,r){var i,o;return r._isUTC?(i=r.clone(),o=(h(t)||n(t)?+t:+Te(t))-+i,i._d.setTime(+i._d+o),e.updateOffset(i,!1),i):Te(t).local()}function je(e){return 15*-Math.round(e._d.getTimezoneOffset()/15)}function Le(t,n){var r,i=this._offset||0;return this.isValid()?null!=t?("string"==typeof t?t=Pe(gr,t):Math.abs(t)<16&&(t*=60),!this._isUTC&&n&&(r=je(this)),this._offset=t,this._isUTC=!0,null!=r&&this.add(r,"m"),i!==t&&(!n||this._changeInProgress?tt(this,Ze(t-i,"m"),1,!1):this._changeInProgress||(this._changeInProgress=!0,e.updateOffset(this,!0),this._changeInProgress=null)),this):this._isUTC?i:je(this):null!=t?this:NaN}function Ue(e,t){return null!=e?("string"!=typeof e&&(e=-e),this.utcOffset(e,t),this):-this.utcOffset()}function He(e){return this.utcOffset(0,e)}function qe(e){return this._isUTC&&(this.utcOffset(0,e),this._isUTC=!1,e&&this.subtract(je(this),"m")),this}function Ve(){return this._tzm?this.utcOffset(this._tzm):"string"==typeof this._i&&this.utcOffset(Pe(mr,this._i)),this}function ze(e){return!!this.isValid()&&(e=e?Te(e).utcOffset():0,(this.utcOffset()-e)%60==0)}function Be(){return this.utcOffset()>this.clone().month(0).utcOffset()||this.utcOffset()>this.clone().month(5).utcOffset()}function Ye(){if(!f(this._isDSTShifted))return this._isDSTShifted;var e={};if(d(e,this),e=Se(e),e._a){var t=e._isUTC?a(e._a):Te(e._a);this._isDSTShifted=this.isValid()&&v(e._a,t.toArray())>0}else this._isDSTShifted=!1;return this._isDSTShifted}function We(){return!!this.isValid()&&!this._isUTC}function Ge(){return!!this.isValid()&&this._isUTC}function Ke(){return!!this.isValid()&&(this._isUTC&&0===this._offset)}function Ze(e,t){var n,r,o,a=e,s=null;return Re(e)?a={ms:e._milliseconds,d:e._days,M:e._months}:"number"==typeof e?(a={},t?a[t]=e:a.milliseconds=e):(s=Wr.exec(e))?(n="-"===s[1]?-1:1,a={y:0,d:g(s[Cr])*n,h:g(s[kr])*n,m:g(s[Er])*n,s:g(s[Sr])*n,ms:g(s[_r])*n}):(s=Gr.exec(e))?(n="-"===s[1]?-1:1,a={y:Je(s[2],n),M:Je(s[3],n),d:Je(s[4],n),h:Je(s[5],n),m:Je(s[6],n),s:Je(s[7],n),w:Je(s[8],n)}):null==a?a={}:"object"==typeof a&&("from"in a||"to"in a)&&(o=Xe(Te(a.from),Te(a.to)),a={},a.ms=o.milliseconds,a.M=o.months),r=new Ne(a),Re(e)&&i(e,"_locale")&&(r._locale=e._locale),r}function Je(e,t){var n=e&&parseFloat(e.replace(",","."));return(isNaN(n)?0:n)*t}function Qe(e,t){var n={milliseconds:0,months:0};return n.months=t.month()-e.month()+12*(t.year()-e.year()),e.clone().add(n.months,"M").isAfter(t)&&--n.months,n.milliseconds=+t-+e.clone().add(n.months,"M"),n}function Xe(e,t){var n;return e.isValid()&&t.isValid()?(t=Fe(t,e),e.isBefore(t)?n=Qe(e,t):(n=Qe(t,e),n.milliseconds=-n.milliseconds,n.months=-n.months),n):{milliseconds:0,months:0}}function et(e,t){return function(n,r){var i,o;return null===r||isNaN(+r)||(oe(t,"moment()."+t+"(period, number) is deprecated. Please use moment()."+t+"(number, period)."),o=n,n=r,r=o),n="string"==typeof n?+n:n,i=Ze(n,r),tt(this,i,e),this}}function tt(t,n,r,i){var o=n._milliseconds,a=n._days,s=n._months;t.isValid()&&(i=null==i||i,o&&t._d.setTime(+t._d+o*r),a&&A(t,"Date",D(t,"Date")+a*r),s&&Z(t,D(t,"Month")+s*r),i&&e.updateOffset(t,a||s))}function nt(e,t){var n=e||Te(),r=Fe(n,this).startOf("day"),i=this.diff(r,"days",!0),o=-6>i?"sameElse":-1>i?"lastWeek":0>i?"lastDay":1>i?"sameDay":2>i?"nextDay":7>i?"nextWeek":"sameElse",a=t&&(M(t[o])?t[o]():t[o]);return this.format(a||this.localeData().calendar(o,this,Te(n)))}function rt(){return new p(this)}function it(e,t){var n=h(e)?e:Te(e);return!(!this.isValid()||!n.isValid())&&(t=S(f(t)?"millisecond":t),"millisecond"===t?+this>+n:+n<+this.clone().startOf(t))}function ot(e,t){var n=h(e)?e:Te(e);return!(!this.isValid()||!n.isValid())&&(t=S(f(t)?"millisecond":t),"millisecond"===t?+n>+this:+this.clone().endOf(t)<+n)}function at(e,t,n){return this.isAfter(e,n)&&this.isBefore(t,n)}function st(e,t){var n,r=h(e)?e:Te(e);return!(!this.isValid()||!r.isValid())&&(t=S(t||"millisecond"),"millisecond"===t?+this==+r:(n=+r,+this.clone().startOf(t)<=n&&n<=+this.clone().endOf(t)))}function lt(e,t){return this.isSame(e,t)||this.isAfter(e,t)}function ut(e,t){return this.isSame(e,t)||this.isBefore(e,t)}function ct(e,t,n){var r,i,o,a;return this.isValid()?(r=Fe(e,this),r.isValid()?(i=6e4*(r.utcOffset()-this.utcOffset()),t=S(t),"year"===t||"month"===t||"quarter"===t?(a=ft(this,r),"quarter"===t?a/=3:"year"===t&&(a/=12)):(o=this-r,a="second"===t?o/1e3:"minute"===t?o/6e4:"hour"===t?o/36e5:"day"===t?(o-i)/864e5:"week"===t?(o-i)/6048e5:o),n?a:m(a)):NaN):NaN}function ft(e,t){var n,r,i=12*(t.year()-e.year())+(t.month()-e.month()),o=e.clone().add(i,"months");return 0>t-o?(n=e.clone().add(i-1,"months"),r=(t-o)/(o-n)):(n=e.clone().add(i+1,"months"),r=(t-o)/(n-o)),-(i+r)}function dt(){return this.clone().locale("en").format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ")}function pt(){var e=this.clone().utc();return 0o&&(t=o),Lt.call(this,e,t,n,r,i))}function Lt(e,t,n,r,i){var o=he(e,t,n,r,i),a=ue(o.year,0,o.dayOfYear);return this.year(a.getUTCFullYear()),this.month(a.getUTCMonth()), -this.date(a.getUTCDate()),this}function Ut(e){return null==e?Math.ceil((this.month()+1)/3):this.month(3*(e-1)+this.month()%3)}function Ht(e){return me(e,this._week.dow,this._week.doy).week}function qt(){return this._week.dow}function Vt(){return this._week.doy}function zt(e){var t=this.localeData().week(this);return null==e?t:this.add(7*(e-t),"d")}function Bt(e){var t=me(this,1,4).week;return null==e?t:this.add(7*(e-t),"d")}function Yt(e,t){return"string"!=typeof e?e:isNaN(e)?(e=t.weekdaysParse(e),"number"==typeof e?e:null):parseInt(e,10)}function Wt(e,n){return t(this._weekdays)?this._weekdays[e.day()]:this._weekdays[this._weekdays.isFormat.test(n)?"format":"standalone"][e.day()]}function Gt(e){return this._weekdaysShort[e.day()]}function Kt(e){return this._weekdaysMin[e.day()]}function Zt(e,t,n){var r,i,o;for(this._weekdaysParse||(this._weekdaysParse=[],this._minWeekdaysParse=[],this._shortWeekdaysParse=[],this._fullWeekdaysParse=[]),r=0;7>r;r++){if(i=Te([2e3,1]).day(r),n&&!this._fullWeekdaysParse[r]&&(this._fullWeekdaysParse[r]=new RegExp("^"+this.weekdays(i,"").replace(".",".?")+"$","i"),this._shortWeekdaysParse[r]=new RegExp("^"+this.weekdaysShort(i,"").replace(".",".?")+"$","i"),this._minWeekdaysParse[r]=new RegExp("^"+this.weekdaysMin(i,"").replace(".",".?")+"$","i")),this._weekdaysParse[r]||(o="^"+this.weekdays(i,"")+"|^"+this.weekdaysShort(i,"")+"|^"+this.weekdaysMin(i,""),this._weekdaysParse[r]=new RegExp(o.replace(".",""),"i")),n&&"dddd"===t&&this._fullWeekdaysParse[r].test(e))return r;if(n&&"ddd"===t&&this._shortWeekdaysParse[r].test(e))return r;if(n&&"dd"===t&&this._minWeekdaysParse[r].test(e))return r;if(!n&&this._weekdaysParse[r].test(e))return r}}function Jt(e){if(!this.isValid())return null!=e?this:NaN;var t=this._isUTC?this._d.getUTCDay():this._d.getDay();return null!=e?(e=Yt(e,this.localeData()),this.add(e-t,"d")):t}function Qt(e){if(!this.isValid())return null!=e?this:NaN;var t=(this.day()+7-this.localeData()._week.dow)%7;return null==e?t:this.add(e-t,"d")}function Xt(e){return this.isValid()?null==e?this.day()||7:this.day(this.day()%7?e:e-7):null!=e?this:NaN}function en(e){var t=Math.round((this.clone().startOf("day")-this.clone().startOf("year"))/864e5)+1;return null==e?t:this.add(e-t,"d")}function tn(){return this.hours()%12||12}function nn(e,t){R(e,0,0,function(){return this.localeData().meridiem(this.hours(),this.minutes(),t)})}function rn(e,t){return t._meridiemParse}function on(e){return"p"===(e+"").toLowerCase().charAt(0)}function an(e,t,n){return e>11?n?"pm":"PM":n?"am":"AM"}function sn(e,t){t[_r]=g(1e3*("0."+e))}function ln(){return this._isUTC?"UTC":""}function un(){return this._isUTC?"Coordinated Universal Time":""}function cn(e){return Te(1e3*e)}function fn(){return Te.apply(null,arguments).parseZone()}function dn(e,t,n){var r=this._calendar[e];return M(r)?r.call(t,n):r}function pn(e){var t=this._longDateFormat[e],n=this._longDateFormat[e.toUpperCase()];return t||!n?t:(this._longDateFormat[e]=n.replace(/MMMM|MM|DD|dddd/g,function(e){return e.slice(1)}),this._longDateFormat[e])}function hn(){return this._invalidDate}function mn(e){return this._ordinal.replace("%d",e)}function gn(e){return e}function vn(e,t,n,r){var i=this._relativeTime[n];return M(i)?i(e,t,n,r):i.replace(/%d/i,e)}function yn(e,t){var n=this._relativeTime[e>0?"future":"past"];return M(n)?n(t):n.replace(/%s/i,t)}function bn(e){var t,n;for(n in e)t=e[n],M(t)?this[n]=t:this["_"+n]=t;this._ordinalParseLenient=new RegExp(this._ordinalParse.source+"|"+/\d{1,2}/.source)}function $n(e,t,n,r){var i=k(),o=a().set(r,t);return i[n](o,e)}function wn(e,t,n,r,i){if("number"==typeof e&&(t=e,e=void 0),e=e||"",null!=t)return $n(e,t,n,i);var o,a=[];for(o=0;r>o;o++)a[o]=$n(e,o,n,i);return a}function xn(e,t){return wn(e,t,"months",12,"month")}function Cn(e,t){return wn(e,t,"monthsShort",12,"month")}function kn(e,t){return wn(e,t,"weekdays",7,"day")}function En(e,t){return wn(e,t,"weekdaysShort",7,"day")}function Sn(e,t){return wn(e,t,"weekdaysMin",7,"day")}function _n(){var e=this._data;return this._milliseconds=gi(this._milliseconds),this._days=gi(this._days),this._months=gi(this._months),e.milliseconds=gi(e.milliseconds),e.seconds=gi(e.seconds),e.minutes=gi(e.minutes),e.hours=gi(e.hours),e.months=gi(e.months),e.years=gi(e.years),this}function Mn(e,t,n,r){var i=Ze(t,n);return e._milliseconds+=r*i._milliseconds,e._days+=r*i._days,e._months+=r*i._months,e._bubble()}function Tn(e,t){return Mn(this,e,t,1)}function Dn(e,t){return Mn(this,e,t,-1)}function An(e){return 0>e?Math.floor(e):Math.ceil(e)}function On(){var e,t,n,r,i,o=this._milliseconds,a=this._days,s=this._months,l=this._data;return o>=0&&a>=0&&s>=0||0>=o&&0>=a&&0>=s||(o+=864e5*An(Rn(s)+a),a=0,s=0),l.milliseconds=o%1e3,e=m(o/1e3),l.seconds=e%60,t=m(e/60),l.minutes=t%60,n=m(t/60),l.hours=n%24,a+=m(n/24),i=m(Nn(a)),s+=i,a-=An(Rn(i)),r=m(s/12),s%=12,l.days=a,l.months=s,l.years=r,this}function Nn(e){return 4800*e/146097}function Rn(e){return 146097*e/4800}function In(e){var t,n,r=this._milliseconds;if("month"===(e=S(e))||"year"===e)return t=this._days+r/864e5,n=this._months+Nn(t),"month"===e?n:n/12;switch(t=this._days+Math.round(Rn(this._months)),e){case"week":return t/7+r/6048e5;case"day":return t+r/864e5;case"hour":return 24*t+r/36e5;case"minute":return 1440*t+r/6e4;case"second":return 86400*t+r/1e3;case"millisecond":return Math.floor(864e5*t)+r;default:throw new Error("Unknown unit "+e)}}function Pn(){return this._milliseconds+864e5*this._days+this._months%12*2592e6+31536e6*g(this._months/12)}function Fn(e){return function(){return this.as(e)}}function jn(e){return e=S(e),this[e+"s"]()}function Ln(e){return function(){return this._data[e]}}function Un(){return m(this.days()/7)}function Hn(e,t,n,r,i){return i.relativeTime(t||1,!!n,e,r)}function qn(e,t,n){var r=Ze(e).abs(),i=Oi(r.as("s")),o=Oi(r.as("m")),a=Oi(r.as("h")),s=Oi(r.as("d")),l=Oi(r.as("M")),u=Oi(r.as("y")),c=i=o&&["m"]||o=a&&["h"]||a=s&&["d"]||s=l&&["M"]||l=u&&["y"]||["yy",u];return c[2]=t,c[3]=+e>0,c[4]=n,Hn.apply(null,c)}function Vn(e,t){return void 0!==Ni[e]&&(void 0===t?Ni[e]:(Ni[e]=t,!0))}function zn(e){var t=this.localeData(),n=qn(this,!e,t);return e&&(n=t.pastFuture(+this,n)),t.postformat(n)}function Bn(){var e,t,n,r=Ri(this._milliseconds)/1e3,i=Ri(this._days),o=Ri(this._months);e=m(r/60),t=m(e/60),r%=60,e%=60,n=m(o/12),o%=12;var a=n,s=o,l=i,u=t,c=e,f=r,d=this.asSeconds();return d?(0>d?"-":"")+"P"+(a?a+"Y":"")+(s?s+"M":"")+(l?l+"D":"")+(u||c||f?"T":"")+(u?u+"H":"")+(c?c+"M":"")+(f?f+"S":""):"P0D"}var Yn,Wn,Gn=e.momentProperties=[],Kn=!1,Zn={},Jn={},Qn=/(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,Xn=/(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g,er={},tr={},nr=/\d/,rr=/\d\d/,ir=/\d{3}/,or=/\d{4}/,ar=/[+-]?\d{6}/,sr=/\d\d?/,lr=/\d\d\d\d?/,ur=/\d\d\d\d\d\d?/,cr=/\d{1,3}/,fr=/\d{1,4}/,dr=/[+-]?\d{1,6}/,pr=/\d+/,hr=/[+-]?\d+/,mr=/Z|[+-]\d\d:?\d\d/gi,gr=/Z|[+-]\d\d(?::?\d\d)?/gi,vr=/[+-]?\d+(\.\d{1,3})?/,yr=/[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i,br={},$r={},wr=0,xr=1,Cr=2,kr=3,Er=4,Sr=5,_r=6,Mr=7,Tr=8;R("M",["MM",2],"Mo",function(){return this.month()+1}),R("MMM",0,0,function(e){return this.localeData().monthsShort(this,e)}),R("MMMM",0,0,function(e){return this.localeData().months(this,e)}),E("month","M"),L("M",sr),L("MM",sr,rr),L("MMM",function(e,t){return t.monthsShortRegex(e)}),L("MMMM",function(e,t){return t.monthsRegex(e)}),V(["M","MM"],function(e,t){t[xr]=g(e)-1}),V(["MMM","MMMM"],function(e,t,n,r){var i=n._locale.monthsParse(e,r,n._strict);null!=i?t[xr]=i:l(n).invalidMonth=e});var Dr=/D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?/,Ar="January_February_March_April_May_June_July_August_September_October_November_December".split("_"),Or="Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),Nr=yr,Rr=yr,Ir={};e.suppressDeprecationWarnings=!1;var Pr=/^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/,Fr=/^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/,jr=/Z|[+-]\d\d(?::?\d\d)?/,Lr=[["YYYYYY-MM-DD",/[+-]\d{6}-\d\d-\d\d/],["YYYY-MM-DD",/\d{4}-\d\d-\d\d/],["GGGG-[W]WW-E",/\d{4}-W\d\d-\d/],["GGGG-[W]WW",/\d{4}-W\d\d/,!1],["YYYY-DDD",/\d{4}-\d{3}/],["YYYY-MM",/\d{4}-\d\d/,!1],["YYYYYYMMDD",/[+-]\d{10}/],["YYYYMMDD",/\d{8}/],["GGGG[W]WWE",/\d{4}W\d{3}/],["GGGG[W]WW",/\d{4}W\d{2}/,!1],["YYYYDDD",/\d{7}/]],Ur=[["HH:mm:ss.SSSS",/\d\d:\d\d:\d\d\.\d+/],["HH:mm:ss,SSSS",/\d\d:\d\d:\d\d,\d+/],["HH:mm:ss",/\d\d:\d\d:\d\d/],["HH:mm",/\d\d:\d\d/],["HHmmss.SSSS",/\d\d\d\d\d\d\.\d+/],["HHmmss,SSSS",/\d\d\d\d\d\d,\d+/],["HHmmss",/\d\d\d\d\d\d/],["HHmm",/\d\d\d\d/],["HH",/\d\d/]],Hr=/^\/?Date\((\-?\d+)/i;e.createFromInputFallback=ie("moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to https://github.com/moment/moment/issues/1407 for more info.",function(e){e._d=new Date(e._i+(e._useUTC?" UTC":""))}),R("Y",0,0,function(){var e=this.year();return 9999>=e?""+e:"+"+e}),R(0,["YY",2],0,function(){return this.year()%100}),R(0,["YYYY",4],0,"year"),R(0,["YYYYY",5],0,"year"),R(0,["YYYYYY",6,!0],0,"year"),E("year","y"),L("Y",hr),L("YY",sr,rr),L("YYYY",fr,or),L("YYYYY",dr,ar),L("YYYYYY",dr,ar),V(["YYYYY","YYYYYY"],wr),V("YYYY",function(t,n){n[wr]=2===t.length?e.parseTwoDigitYear(t):g(t)}),V("YY",function(t,n){n[wr]=e.parseTwoDigitYear(t)}),V("Y",function(e,t){t[wr]=parseInt(e,10)}),e.parseTwoDigitYear=function(e){return g(e)+(g(e)>68?1900:2e3)};var qr=T("FullYear",!1);e.ISO_8601=function(){};var Vr=ie("moment().min is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548",function(){var e=Te.apply(null,arguments);return this.isValid()&&e.isValid()?this>e?this:e:c()}),zr=ie("moment().max is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548",function(){var e=Te.apply(null,arguments);return this.isValid()&&e.isValid()?e>this?this:e:c()}),Br=function(){return Date.now?Date.now():+new Date};Ie("Z",":"),Ie("ZZ",""),L("Z",gr),L("ZZ",gr),V(["Z","ZZ"],function(e,t,n){n._useUTC=!0,n._tzm=Pe(gr,e)});var Yr=/([\+\-]|\d\d)/gi;e.updateOffset=function(){};var Wr=/(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/,Gr=/^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/;Ze.fn=Ne.prototype;var Kr=et(1,"add"),Zr=et(-1,"subtract");e.defaultFormat="YYYY-MM-DDTHH:mm:ssZ";var Jr=ie("moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.",function(e){return void 0===e?this.localeData():this.locale(e)});R(0,["gg",2],0,function(){return this.weekYear()%100}),R(0,["GG",2],0,function(){return this.isoWeekYear()%100}),Nt("gggg","weekYear"),Nt("ggggg","weekYear"),Nt("GGGG","isoWeekYear"),Nt("GGGGG","isoWeekYear"),E("weekYear","gg"),E("isoWeekYear","GG"),L("G",hr),L("g",hr),L("GG",sr,rr),L("gg",sr,rr),L("GGGG",fr,or),L("gggg",fr,or),L("GGGGG",dr,ar),L("ggggg",dr,ar),z(["gggg","ggggg","GGGG","GGGGG"],function(e,t,n,r){t[r.substr(0,2)]=g(e)}),z(["gg","GG"],function(t,n,r,i){n[i]=e.parseTwoDigitYear(t)}),R("Q",0,"Qo","quarter"),E("quarter","Q"),L("Q",nr),V("Q",function(e,t){t[xr]=3*(g(e)-1)}),R("w",["ww",2],"wo","week"),R("W",["WW",2],"Wo","isoWeek"),E("week","w"),E("isoWeek","W"),L("w",sr),L("ww",sr,rr),L("W",sr),L("WW",sr,rr),z(["w","ww","W","WW"],function(e,t,n,r){t[r.substr(0,1)]=g(e)});var Qr={dow:0,doy:6};R("D",["DD",2],"Do","date"),E("date","D"),L("D",sr),L("DD",sr,rr),L("Do",function(e,t){return e?t._ordinalParse:t._ordinalParseLenient}),V(["D","DD"],Cr),V("Do",function(e,t){t[Cr]=g(e.match(sr)[0],10)});var Xr=T("Date",!0);R("d",0,"do","day"),R("dd",0,0,function(e){return this.localeData().weekdaysMin(this,e)}),R("ddd",0,0,function(e){return this.localeData().weekdaysShort(this,e)}),R("dddd",0,0,function(e){return this.localeData().weekdays(this,e)}),R("e",0,0,"weekday"),R("E",0,0,"isoWeekday"),E("day","d"),E("weekday","e"),E("isoWeekday","E"),L("d",sr),L("e",sr),L("E",sr),L("dd",yr),L("ddd",yr),L("dddd",yr),z(["dd","ddd","dddd"],function(e,t,n,r){var i=n._locale.weekdaysParse(e,r,n._strict);null!=i?t.d=i:l(n).invalidWeekday=e}),z(["d","e","E"],function(e,t,n,r){t[r]=g(e)});var ei="Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),ti="Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),ni="Su_Mo_Tu_We_Th_Fr_Sa".split("_");R("DDD",["DDDD",3],"DDDo","dayOfYear"),E("dayOfYear","DDD"),L("DDD",cr),L("DDDD",ir),V(["DDD","DDDD"],function(e,t,n){n._dayOfYear=g(e)}),R("H",["HH",2],0,"hour"),R("h",["hh",2],0,tn),R("hmm",0,0,function(){return""+tn.apply(this)+N(this.minutes(),2)}),R("hmmss",0,0,function(){return""+tn.apply(this)+N(this.minutes(),2)+N(this.seconds(),2)}),R("Hmm",0,0,function(){return""+this.hours()+N(this.minutes(),2)}),R("Hmmss",0,0,function(){return""+this.hours()+N(this.minutes(),2)+N(this.seconds(),2)}),nn("a",!0),nn("A",!1),E("hour","h"),L("a",rn),L("A",rn),L("H",sr),L("h",sr),L("HH",sr,rr),L("hh",sr,rr),L("hmm",lr),L("hmmss",ur),L("Hmm",lr),L("Hmmss",ur),V(["H","HH"],kr),V(["a","A"],function(e,t,n){n._isPm=n._locale.isPM(e),n._meridiem=e}),V(["h","hh"],function(e,t,n){t[kr]=g(e),l(n).bigHour=!0}),V("hmm",function(e,t,n){var r=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r)),l(n).bigHour=!0}),V("hmmss",function(e,t,n){var r=e.length-4,i=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r,2)),t[Sr]=g(e.substr(i)),l(n).bigHour=!0}),V("Hmm",function(e,t,n){var r=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r))}),V("Hmmss",function(e,t,n){var r=e.length-4,i=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r,2)),t[Sr]=g(e.substr(i))});var ri=/[ap]\.?m?\.?/i,ii=T("Hours",!0);R("m",["mm",2],0,"minute"),E("minute","m"),L("m",sr),L("mm",sr,rr),V(["m","mm"],Er);var oi=T("Minutes",!1);R("s",["ss",2],0,"second"),E("second","s"),L("s",sr),L("ss",sr,rr),V(["s","ss"],Sr);var ai=T("Seconds",!1);R("S",0,0,function(){return~~(this.millisecond()/100)}),R(0,["SS",2],0,function(){return~~(this.millisecond()/10)}),R(0,["SSS",3],0,"millisecond"),R(0,["SSSS",4],0,function(){return 10*this.millisecond()}),R(0,["SSSSS",5],0,function(){return 100*this.millisecond()}),R(0,["SSSSSS",6],0,function(){return 1e3*this.millisecond()}),R(0,["SSSSSSS",7],0,function(){return 1e4*this.millisecond()}),R(0,["SSSSSSSS",8],0,function(){return 1e5*this.millisecond()}),R(0,["SSSSSSSSS",9],0,function(){return 1e6*this.millisecond()}),E("millisecond","ms"),L("S",cr,nr),L("SS",cr,rr),L("SSS",cr,ir);var si;for(si="SSSS";si.length<=9;si+="S")L(si,pr);for(si="S";si.length<=9;si+="S")V(si,sn);var li=T("Milliseconds",!1);R("z",0,0,"zoneAbbr"),R("zz",0,0,"zoneName");var ui=p.prototype;ui.add=Kr,ui.calendar=nt,ui.clone=rt,ui.diff=ct,ui.endOf=xt,ui.format=ht,ui.from=mt,ui.fromNow=gt,ui.to=vt,ui.toNow=yt,ui.get=O,ui.invalidAt=At,ui.isAfter=it,ui.isBefore=ot,ui.isBetween=at,ui.isSame=st,ui.isSameOrAfter=lt,ui.isSameOrBefore=ut,ui.isValid=Tt,ui.lang=Jr,ui.locale=bt,ui.localeData=$t,ui.max=zr,ui.min=Vr,ui.parsingFlags=Dt,ui.set=O,ui.startOf=wt,ui.subtract=Zr,ui.toArray=St,ui.toObject=_t,ui.toDate=Et,ui.toISOString=pt,ui.toJSON=Mt,ui.toString=dt,ui.unix=kt,ui.valueOf=Ct,ui.creationData=Ot,ui.year=qr,ui.isLeapYear=de,ui.weekYear=Rt,ui.isoWeekYear=It,ui.quarter=ui.quarters=Ut,ui.month=J,ui.daysInMonth=Q,ui.week=ui.weeks=zt,ui.isoWeek=ui.isoWeeks=Bt,ui.weeksInYear=Ft,ui.isoWeeksInYear=Pt,ui.date=Xr,ui.day=ui.days=Jt,ui.weekday=Qt,ui.isoWeekday=Xt,ui.dayOfYear=en,ui.hour=ui.hours=ii,ui.minute=ui.minutes=oi,ui.second=ui.seconds=ai,ui.millisecond=ui.milliseconds=li,ui.utcOffset=Le,ui.utc=He,ui.local=qe,ui.parseZone=Ve,ui.hasAlignedHourOffset=ze,ui.isDST=Be,ui.isDSTShifted=Ye,ui.isLocal=We,ui.isUtcOffset=Ge,ui.isUtc=Ke,ui.isUTC=Ke,ui.zoneAbbr=ln,ui.zoneName=un,ui.dates=ie("dates accessor is deprecated. Use date instead.",Xr),ui.months=ie("months accessor is deprecated. Use month instead",J),ui.years=ie("years accessor is deprecated. Use year instead",qr),ui.zone=ie("moment().zone is deprecated, use moment().utcOffset instead. https://github.com/moment/moment/issues/1779",Ue);var ci=ui,fi={sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"},di={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},pi=/\d{1,2}/,hi={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},mi=y.prototype;mi._calendar=fi,mi.calendar=dn,mi._longDateFormat=di,mi.longDateFormat=pn,mi._invalidDate="Invalid date",mi.invalidDate=hn,mi._ordinal="%d",mi.ordinal=mn,mi._ordinalParse=pi,mi.preparse=gn,mi.postformat=gn,mi._relativeTime=hi,mi.relativeTime=vn,mi.pastFuture=yn,mi.set=bn,mi.months=W,mi._months=Ar,mi.monthsShort=G,mi._monthsShort=Or,mi.monthsParse=K,mi._monthsRegex=Rr,mi.monthsRegex=ee,mi._monthsShortRegex=Nr,mi.monthsShortRegex=X,mi.week=Ht,mi._week=Qr,mi.firstDayOfYear=Vt,mi.firstDayOfWeek=qt,mi.weekdays=Wt,mi._weekdays=ei,mi.weekdaysMin=Kt,mi._weekdaysMin=ni,mi.weekdaysShort=Gt,mi._weekdaysShort=ti,mi.weekdaysParse=Zt,mi.isPM=on,mi._meridiemParse=ri,mi.meridiem=an,x("en",{ordinalParse:/\d{1,2}(th|st|nd|rd)/,ordinal:function(e){var t=e%10;return e+(1===g(e%100/10)?"th":1===t?"st":2===t?"nd":3===t?"rd":"th")}}),e.lang=ie("moment.lang is deprecated. Use moment.locale instead.",x),e.langData=ie("moment.langData is deprecated. Use moment.localeData instead.",k);var gi=Math.abs,vi=Fn("ms"),yi=Fn("s"),bi=Fn("m"),$i=Fn("h"),wi=Fn("d"),xi=Fn("w"),Ci=Fn("M"),ki=Fn("y"),Ei=Ln("milliseconds"),Si=Ln("seconds"),_i=Ln("minutes"),Mi=Ln("hours"),Ti=Ln("days"),Di=Ln("months"),Ai=Ln("years"),Oi=Math.round,Ni={s:45,m:45,h:22,d:26,M:11},Ri=Math.abs,Ii=Ne.prototype;return Ii.abs=_n,Ii.add=Tn,Ii.subtract=Dn,Ii.as=In,Ii.asMilliseconds=vi,Ii.asSeconds=yi,Ii.asMinutes=bi,Ii.asHours=$i,Ii.asDays=wi,Ii.asWeeks=xi,Ii.asMonths=Ci,Ii.asYears=ki,Ii.valueOf=Pn,Ii._bubble=On,Ii.get=jn,Ii.milliseconds=Ei,Ii.seconds=Si,Ii.minutes=_i,Ii.hours=Mi,Ii.days=Ti,Ii.weeks=Un,Ii.months=Di,Ii.years=Ai,Ii.humanize=zn,Ii.toISOString=Bn,Ii.toString=Bn,Ii.toJSON=Bn,Ii.locale=bt,Ii.localeData=$t,Ii.toIsoString=ie("toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)",Bn),Ii.lang=Jr,R("X",0,0,"unix"),R("x",0,0,"valueOf"),L("x",hr),L("X",vr),V("X",function(e,t,n){n._d=new Date(1e3*parseFloat(e,10))}),V("x",function(e,t,n){n._d=new Date(g(e))}),e.version="2.11.1",function(e){Yn=e}(Te),e.fn=ci,e.min=Ae,e.max=Oe,e.now=Br,e.utc=a,e.unix=cn,e.months=xn,e.isDate=n,e.locale=x,e.invalid=c,e.duration=Ze,e.isMoment=h,e.weekdays=kn,e.parseZone=fn,e.localeData=k,e.isDuration=Re,e.monthsShort=Cn,e.weekdaysMin=Sn,e.defineLocale=C,e.weekdaysShort=En,e.normalizeUnits=S,e.relativeTimeThreshold=Vn,e.prototype=ci,e}),define("common/bundles/vendors",["common/require","common/angular","common/angularAnimate","common/angularBootstrap","common/angular-file-upload","common/angularMocks","common/angularResource","common/angularRoute","common/angularXeditable","common/text-angular","common/ui-select","common/d3","common/lodash","common/moment"],function(){}),define("common/modules/apis",["common/angular"],function(e){"use strict";return e.module("common.apis",[])}),define("common/services/api",["common/angular","common/lodash","common/modules/apis"],function(e,t,n){"use strict";n.factory("api",["$cacheFactory","$log","$http","$httpParamSerializer","$q","$timeout",function(n,r,i,o,a,s){function l(e){return e.data.is_error?(r.error(e.data),a.reject(e.data.error_message)):e.data}function u(e){var n={options:{limit:0}};return JSON.stringify(t.merge(n,e||{}))}function c(e){return"?"+Object.keys(e).sort().map(function(t){return(encodeURIComponent(t)+"="+encodeURIComponent(e[t])).replace(/%3A/g,":").replace(/%2C/g,",")}).join("&")}r.debug("api");return{extend:function(t){return e.extend(Object.create(this),t)},getAll:function(e,n,i,o,s,l,u){return r.debug("api.all"),n=n||{},l=l||"get",a.all([function(){var r=t.assign({},n,s||{},{options:t.assign({},n.options,{sort:o||"id DESC"})});return i&&(r.options.offset=(i.page-1)*i.size,r.options.limit=i.size),this.sendGET(e,l,r,u)}.bind(this)(),function(){if(!i)return a.resolve();var r=t.assign({},n,{return:"id"});return r=t.omit(r,function(e,n){return t.startsWith(n,"api.")}),this.sendGET(e,l,r,u)}.bind(this)()]).then(function(e){var n=e[0],r=i?e[1]:n;return{list:n.values,total:r.count,allIds:t.compact(r.values.map(function(e){return e.id})).join(",")}})},mockGET:function(e,t){var n=a.defer();return s(function(){n.resolve(e)},t||0),n.promise},mockPOST:function(e,t){return this.mockGET.apply(this,arguments)},sendGET:function(e,t,r,o){var a={action:t,entity:e,json:u(r),sequential:1};return!1===o&&n.get("$http").remove("/civicrm/ajax/rest"+c(a)),i({method:"GET",url:"/civicrm/ajax/rest",cache:!0,responseType:"json",params:a}).then(l)},sendPOST:function(e,t,n){return r.debug("api.sendPOST"),i({method:"POST",url:"/civicrm/ajax/rest",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},responseType:"json",data:{json:u(n),sequential:1,entity:e,action:t},transformRequest:o}).then(l)}}}])}),define("common/services/api/appraisal",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.appraisal",["$log","api",function(e,t){return e.debug("api.appraisal"),t.extend({all:function(t,n,r){return e.debug("api.appraisal.api"),this.getAll("Appraisal",t,n,r)},create:function(t){return e.debug("api.appraisal.create"),this.sendPOST("Appraisal","create",t).then(function(e){return e.values[0]})},find:function(t){return e.debug("api.appraisal.find"),this.sendGET("Appraisal","get",{id:""+t},!1).then(function(e){return e.values[0]})}})}])}),define("common/services/api/option-group",["common/lodash","common/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("api.optionGroup",["$log","api",function(t,n){function r(t){return t.values.map(function(t){var n=e.clone(t);return n.option_group_name=n["option_group_id.name"],delete n["option_group_id.name"],n})}function i(t){return e.transform(t,function(e,t){var n=t.option_group_name;e[n]=e[n]||[],e[n].push(t)})}return t.debug("api.optionGroup"),n.extend({valuesOf:function(t,n,o){var a=e.isArray(t);return this.sendGET("OptionValue","get",e.assign({"option_group_id.name":{IN:a?t:[t]},is_active:"1",return:["option_group_id.name","option_group_id","id","name","label","value","weight","is_active","is_reserved"]},n),o).then(r).then(function(e){return a?i(e):e})}})}])}),define("common/services/api/appraisal-cycle",["common/lodash","common/modules/apis","common/services/api","common/services/api/option-group"],function(e,t){"use strict";t.factory("api.appraisal-cycle",["$q","$log","api","api.optionGroup",function(t,n,r,i){return n.debug("api.appraisal-cycle"),r.extend({all:function(e,t,r){return n.debug("api.appraisal-cycle.all"),this.getAll("AppraisalCycle",e,t,r,{"api.AppraisalCycle.getappraisalsperstep":{}})},create:function(t){return n.debug("api.appraisal-cycle.create"),this.sendPOST("AppraisalCycle","create",e.assign(t,{"api.AppraisalCycle.getappraisalsperstep":{}})).then(function(e){return e.values[0]})},find:function(e){n.debug("api.appraisal-cycle.find");var t={id:""+e,"api.AppraisalCycle.getappraisalsperstep":{}};return this.sendGET("AppraisalCycle","get",t,!1).then(function(e){return e.values[0]})},grades:function(){return n.debug("grades"),this.mockGET([{label:1,value:17},{label:2,value:74},{label:3,value:90},{label:4,value:30}])},statuses:function(){return n.debug("api.appraisal-cycle.statuses"),i.valuesOf("appraisal_status")},statusOverview:function(e){return n.debug("api.appraisal-cycle.statusOverview"),this.sendGET("AppraisalCycle","getstatusoverview",e).then(function(e){return e.values})},update:function(t){return n.debug("api.appraisal-cycle.update"),this.sendPOST("AppraisalCycle","create",e.assign(t,{"api.AppraisalCycle.getappraisalsperstep":{}})).then(function(e){return e.values[0]})},total:function(e){return n.debug("api.appraisal-cycle.total"),this.sendGET("AppraisalCycle","getcount",e||{}).then(function(e){return e.result})},types:function(){return n.debug("api.appraisal-cycle.types"),i.valuesOf("appraisal_cycle_type")}})}])}),define("common/services/api/contact-job-role-api.api",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("ContactJobRoleAPI",["$log","api",function(e,t){return e.debug("ContactJobRoleAPI"),t.extend({all:function(t,n,r,i){return e.debug("ContactJobRoleAPI.all()"),this.getAll("ContactHrJobRoles",t,n,r,i)}})}])}),define("common/bundles/apis",["common/services/api/appraisal","common/services/api/appraisal-cycle","common/services/api/contact-job-role-api.api","common/services/api/option-group"],function(){}),define("common/modules/services",["common/angular","common/angular-file-upload"],function(e){"use strict";return e.module("common.services",["angularFileUpload"])}),define("common/services/before-hash-query-params.service",["common/lodash","common/modules/services"],function(e,t){"use strict";t.factory("beforeHashQueryParams",["$log","$window",function(t,n){function r(e){var t=e||n.location.href,r=o(t);return-1===r.indexOf("?")?{}:i(a(r))}function i(t){return t.length?e.transform(t,function(e,t){var n=t.split("=");n[0]&&(e[n[0]]=n[1]?decodeURI(n[1]):null)},{}):{}}function o(e){var t=e.indexOf("#");return e.substring(0,-1!==t?t:e.length)}function a(e){var t=e.indexOf("?");return e.substr(t+1).split("&")}return t.debug("Service: beforeHashQueryParams"),{parse:r}}])}),function(e){define("common/services/check-permissions",["common/lodash","common/modules/services"],function(t,n){"use strict";n.factory("checkPermissions",["$q",function(n){return function(r){return r=t.isArray(r)?r:[r],n.resolve(r.every(function(t){return e.checkPerm(t)}))}}])})}(CRM),function(e){define("common/services/crm-ang.service",["common/lodash","common/modules/services"],function(t,n){"use strict";function r(t,n){return e.loadForm(t,n)}n.factory("crmAngService",function(){return{loadForm:r}})})}(CRM),define("common/services/detect-device.service",["common/modules/services"],function(e){"use strict";e.factory("detectDevice",[function(){return{isMobile:function(){return document.getElementsByTagName("body")[0].classList.contains("mobile")}}}])}),define("common/services/dom-event-trigger",["common/modules/services"],function(e){"use strict";!function(t){e.factory("DOMEventTrigger",function(){return function(e,n){t(document).trigger(e,n)}})}(CRM.$)}),define("common/services/file-mime-types",["common/lodash","common/modules/services"],function(e,t){"use strict";t.factory("fileMimeTypes",["$q",function(e){var t={txt:"plain",png:"png",jpeg:"jpeg",bmp:"bmp",gif:"gif",pdf:"pdf",doc:"msword",docx:"vnd.openxmlformats-officedocument.wordprocessingml.document",xls:"vnd.ms-excel",xlsx:"vnd.openxmlformats-officedocument.spreadsheetml.sheet",ppt:"vnd.ms-powerpoint",pptx:"vnd.openxmlformats-officedocument.presentationml.presentation"};return{getMimeTypeFor:function(n){return e.resolve(t[n])}}}])}),define("common/services/file-upload",["common/modules/services","common/lodash","common/angular-file-upload"],function(e,t){"use strict";e.factory("FileUpload",["$q","$log","FileUploader",function(e,n,r){function i(e){throw new Error(e+" missing from parameter")}function o(e,t,r,i){n.error(" ===== Item Error: "+r+" ======"),n.error(" ===== - item ======"),n.error(e),n.error(" ===== - response ======"),n.error(t),n.error(" ===== - headers ======"),n.error(i)}function a(e){return t.defaults(e,{allowedMimeTypes:{txt:"plain",png:"png",jpeg:"jpeg",bmp:"bmp",gif:"gif",pdf:"pdf"},url:"/civicrm/ajax/attachment",queueLimit:1})}return{uploader:function(n){var s,l,u,c=[];return n?(n=a(n),s=new r({url:n.url,queueLimit:+n.queueLimit,onCompleteItem:function(e,t){c.push(t)},onCompleteAll:function(){u.resolve(c)},onErrorItem:function(e){o.apply(null,arguments),u.reject("Could not upload file: "+e.file.name)},formData:[{entity_table:n.entityTable||i("entityTable"),crm_attachment_token:n.crmAttachmentToken||i("crmAttachmentToken")}],filters:[{name:"fileFormatFilter",fn:function(e){var r=e.type.slice(e.type.lastIndexOf("/")+1);return t.includes(t.values(n.allowedMimeTypes),r)}}]}),s.uploadAll=function(){return l=s.uploadAll,function(n){return u=e.defer(),s.onBeforeUploadItem=function(e){t.each(n,function(n,r){var i={};i[t.snakeCase(r)]=n,e.formData.push(i)})},l.apply(s),u.promise}}(),s):i("custom settings")}}}])}),define("common/services/file.service",["common/modules/services"],function(e){"use strict";e.factory("fileService",["$http","$window","$log",function(e,t,n){return n.debug("Service: fileService"),{openFile:function(n){return e.get(n.url,{responseType:"arraybuffer"}).success(function(e){var r=new Blob([e],{type:n.fileType});t.navigator.msSaveOrOpenBlob?t.navigator.msSaveOrOpenBlob(r,n.name):t.open(URL.createObjectURL(r),"_blank")})}}}])}),define("common/services/hr-settings",["common/modules/services"],function(e){"use strict";e.factory("HR_settings",function(){return{DATE_FORMAT:null}})}),function(e){define("common/services/notification.service",["common/lodash","common/modules/services"],function(t,n){"use strict";n.factory("notificationService",function(){return t(["alert","success","info","error"]).map(function(t){return[t,function(n,r,i){return e.alert(r,n,t,i)}]}).zipObject().value()})})}(CRM),define("common/services/pub-sub",["common/modules/services"],function(e){"use strict";var t=Object.create(null);e.factory("pubSub",["$rootScope",function(e){return{subscribe:function(n,r){var i;return t[n]=t[n]||[],r.$rootScope=e,i=t[n].push(r)-1,{remove:function(){delete t[n][i]}}},publish:function(e,n){t[e]&&(n=void 0!=n?n:{},t[e].forEach(function(e){e.$rootScope.$applyAsync(function(){e(n)})}))}}}])}),define("common/bundles/services",["common/services/before-hash-query-params.service","common/services/check-permissions","common/services/crm-ang.service","common/services/detect-device.service","common/services/dom-event-trigger","common/services/file-mime-types","common/services/file-upload","common/services/file.service","common/services/hr-settings","common/services/notification.service","common/services/pub-sub"],function(){}),define("common/modules/components",["common/angular"],function(e){return e.module("common.components",[])}),define("common/components/heatmap.component",["common/lodash","common/moment","common/modules/components"],function(e,t,n){function r(){function n(e){e.values&&(u(),l(),c())}function r(){return Object.values(d.values).filter(function(e){return!1!==e})}function i(e,t){return e.reduce(function(e,n){return Math.abs(n.value-t)');r(n,t),e.after(n)}function r(e,n){function r(){n.isOpen=!0,n.$apply()}t.isMobile()||(e.on("click",r),n.$on("$destroy",function(){e.off("click",r)}))}var i=e[0],o=i.compile;return i.compile=function(){var e=o.apply(this,arguments);return function(t,i,o){e.apply(this,arguments),n(i,t),r(i,t)}},e}]}),define("common/decorators/uib-datepicker-mobile-version.decorator",["common/moment","common/services/detect-device.service"],function(e){"use strict";return["$delegate","detectDevice",function(t,n){function r(t){return t?e(t).format("Y-MM-DD"):""}var i=t[0],o=i.compile;return i.require=["ngModel","uibDatepickerPopup"],i.compile=function(){var e=o.apply(this,arguments);return function(t,i,o,a){n.isMobile()?(i.prop("type","date"),o.ngReadonly=!1,a[0].$formatters.push(function(e){return r(e)}),t.$watch("datepickerOptions.minDate",function(e){o.$set("min",r(e))}),t.$watch("datepickerOptions.maxDate",function(e){o.$set("max",r(e))})):e.apply(this,arguments)}},t}]}),define("common/decorators/xeditable-disable-calendar-icon.decorator",[],function(){"use strict";return["$delegate",function(e){var t=e[0],n=t.compile;return t.compile=function(){var e=n.apply(this,arguments);return function(t,n,r){e.apply(this,arguments),r.eShowCalendarButton=!1}},e}]}),define("common/decorators/ui-bootstrap/uib-tabset",[],function(){"use strict";return["$delegate",function(e){return e[0].bindToController.customHeaderClass="@",e}]}),define("common/decorators/ui-bootstrap/uib-modal.decorator",["common/angular"],function(e){"use strict";return["$delegate","$document",function(t,n){function r(){var t,r=[{item:e.element(n[0].body),styles:[{name:"overflow",old:null,new:"hidden"},{name:"height",old:null,new:"100%"},{name:"width",old:null,new:"100%"}]},{item:e.element(n[0].getElementsByTagName("html")[0]),styles:[{name:"overflow",old:null,new:"hidden"},{name:"height",old:null,new:"100%"},{name:"width",old:null,new:"100%"}]}];return r.forEach(function(e){e.styles.forEach(function(t){t.old=e.item.css(t.name),e.item.css(t.name,t.new)})}),t=i.apply(this,arguments),t.closed.then(function(){r.forEach(function(e){e.styles.forEach(function(t){e.item.css(t.name,t.old)})})}),t}var i=t.open;return t.open=r,t}]}),define("common/modules/templates",["common/angular"],function(e){"use strict";return e.module("common.templates",[]).run(["$templateCache",function(e){e.put("dialog.html",'\n\n\n'),e.put("help-text.html",'\n'),e.put("loading.html",'
    \n
    \n
    \n
    \n'),e.put("time-amount-picker.html",'
    \n
    \n \n \n
    \n h\n
    \n \n \n
    \n m\n
    \n'),e.put("timepicker-select.html",'\n\n'),e.put("civihr-ui-select/choices.tpl.html",'
      \n
    • \n
      \n
        \n
      • \n
        \n
      • \n
      \n
    • \n
    \n'),e.put("civihr-ui-select/match-multiple.tpl.html",'\n
  • \n \n \n
  • \n\n'),e.put("civihr-ui-select/match.tpl.html",'\n {{$select.contactList ? \'-select-\' : $select.placeholder}}\n \n \n \n\n'),e.put("civihr-ui-select/select-contacts-multiple.tpl.html",'
    \n
    \n
      \n \n
    • \n \n
    • \n
    \n\n \n\n \n
    \n
    \n'),e.put("civihr-ui-select/select-contacts.tpl.html",'
    \n
    \n \n
    \n'),e.put("civihr-ui-select/select-multiple.tpl.html",'
    \n
    \n
      \n \n
    • \n \n
    • \n
    \n \n
    \n
    \n'),e.put("civihr-ui-select/select.tpl.html",'
    \n
    \n \n
    \n'),e.put("components/heatmap.html",'
      \n
    • \n {{day.name.short}}\n
    • \n
    \n'),e.put("contact-actions/contact-actions.html",'
    \n \n \n
    \n'),e.put("contact-actions/modals/form.html",'
    \n \n \n \n
    \n')}])}),define("common/modules/controllers",["common/angular","common/angularBootstrap","common/modules/apis"],function(e){"use strict";return e.module("common.controllers",["ui.bootstrap","common.apis"])}),define("common/modules/directives",["common/angular","common/decorators/ui-select-focus.decorator","common/decorators/uib-datepicker-calendar-icon.decorator","common/decorators/uib-datepicker-mobile-version.decorator","common/decorators/xeditable-disable-calendar-icon.decorator","common/decorators/ui-bootstrap/uib-tabset","common/decorators/ui-bootstrap/uib-modal.decorator","common/angularBootstrap","common/angularXeditable","common/ui-select","common/modules/templates","common/modules/controllers","common/modules/services","common/modules/apis"],function(e,t,n,r,i,o,a){"use strict";return e.module("common.directives",["common.templates","common.controllers","ui.select","ui.bootstrap","xeditable"]).config(["$provide",function(e){e.decorator("uibDatepickerPopupDirective",r),e.decorator("uibDatepickerPopupDirective",n),e.decorator("uibTabsetDirective",o),e.decorator("$uibModal",a),e.decorator("editableBsdateDirective",i),e.decorator("uiSelectDirective",t)}]).run(["$templateCache",function(e){var t="uib/template/tabs/tabset.html",n=jQuery(e.get(t));n.find("ul").addClass("{{tabset.customHeaderClass}}"),e.put(t,n.wrap("
    ").parent().html())}])}),define("common/services/api/contact-actions",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.contactActions",["$q","api",function(e,t){function n(e,n){return t.sendGET(e,"getoptions",{field:n,context:"search"}).then(function(e){return e.values})}function r(e){return t.sendGET("UFField","get",{uf_group_id:e,is_active:!0}).then(function(e){return e.values})}function i(n,r){return e(function(e,i){if(r.contact_type=n,r.email)return t.sendGET("CustomField","get",{return:["id"],custom_group_id:"Emergency_Contacts",name:"email"}).then(function(t){r["custom_"+t.id]=r.email,delete r.email,e()});e()}).then(function(){return t.sendPOST("Contact","create",r).then(function(e){return e.values[0]})})}return t.extend({getOptions:{forContactType:function(){return n.call(this,"Contact","contact_type")},forGroup:function(){return n.call(this,"GroupContact","group_id")},forTag:function(){return n.call(this,"EntityTag","tag_id")},forStateProvince:function(){return n.call(this,"Address","state_province_id")},forCountry:function(){return n.call(this,"Address","country_id")},forGender:function(){return n.call(this,"Contact","gender_id")},forDeceased:function(){return n.call(this,"Contact","is_deceased")}},save:{newIndividual:function(e){return i.call(this,"Individual",e)},newOrganization:function(e){return i.call(this,"Organization",e)},newHousehold:function(e){return i.call(this,"Household",e)}},getFormFields:{forNewIndividual:function(){return r.call(this,"new_individual")},forNewOrganization:function(){return r.call(this,"new_organization")},forNewHousehold:function(){return r.call(this,"new_household")}}})}])}),define("common/controllers/contact-actions/modal-ctrl",[],function(){"use strict";return function(e,t){this.errorMsg="",this.loading=!0,this.formFields=[],this.init=function(e){e().then(function(e){this.loading=!1,this.formFields=e}.bind(this)).catch(function(){this.loading=!1,this.errorMsg="Error while loading form fields"}.bind(this))},this.cancel=function(){t.dismiss("cancel")},this.save=function(n,r){this.loading=!0,n(this.formFields.reduce(function(e,t){return e[t.field_name]=t.value,e},{})).then(function(n){this.loading=!1,e.$broadcast(r,n),t.dismiss("cancel")}.bind(this)).catch(function(){this.loading=!1,this.errorMsg="Error while saving data"}.bind(this))}}}),define("common/controllers/contact-actions/new-individual-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Individual",i.init(r.getFormFields.forNewIndividual),i.submit=function(){i.save(r.save.newIndividual,"newIndividualCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewIndividualModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/new-household-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Household",i.init(r.getFormFields.forNewHousehold),i.submit=function(){i.save(r.save.newHousehold,"newHouseholdCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewHouseholdModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/new-organization-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Organization",i.init(r.getFormFields.forNewOrganization),i.submit=function(){i.save(r.save.newOrganization,"newOrganizationCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewOrganizationModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/contact-actions-ctrl",["common/modules/controllers","common/services/api/contact-actions","common/controllers/contact-actions/new-individual-ctrl","common/controllers/contact-actions/new-household-ctrl","common/controllers/contact-actions/new-organization-ctrl"],function(e){"use strict";e.controller("ContactActionsCtrl",["$scope","$rootElement","$uibModal","api.contactActions",function(e,t,n,r){var i=this;e.$watch(function(){return i.refineSearch.selected},function(t,n){t!==n&&e.$emit("contactRefineSearch",{field:t.field?t.field.label:null,option:t.option?t.option.value:null})},!0),i.refineSearch={selected:{field:null,option:null},availableFields:[{label:"Contact Type",getOptions:r.getOptions.forContactType},{label:"Group",getOptions:r.getOptions.forGroup},{label:"Tag",getOptions:r.getOptions.forTag},{label:"State / Province",getOptions:r.getOptions.forStateProvince},{label:"Country",getOptions:r.getOptions.forCountry},{label:"Gender",getOptions:r.getOptions.forGender},{label:"Deceased",getOptions:r.getOptions.forDeceased}],availableOptions:{refresh:function(){i.refineSearch.selected.field?(this.options=null,i.refineSearch.selected.field.getOptions().then(function(e){this.options=e}.bind(this))):this.options=[]},options:[]}},i.showNewIndividualModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewIndividualModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})},i.showNewHouseholdModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewHouseholdModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})},i.showNewOrganizationModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewOrganizationModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})}}])}),define("common/directives/prevent-animations",["common/modules/directives"],function(e){"use strict";e.directive("preventAnimations",["$animate",function(e){return{restrict:"A",link:function(t,n,r){e.enabled(n,!1)}}}])}),define("common/directives/loading",["common/modules/directives","common/directives/prevent-animations"],function(e){"use strict";e.directive("crmLoading",["$templateCache",function(e){return{scope:{show:"="},restrict:"E",replace:!0,transclude:!0,template:e.get("loading.html")}}])}),define("common/directives/contact-actions/contact-actions",["common/modules/directives","common/controllers/contact-actions/contact-actions-ctrl","common/directives/loading"],function(e){"use strict";e.directive("contactActions",[function(){return{restrict:"E",templateUrl:"contact-actions/contact-actions.html",controller:"ContactActionsCtrl",controllerAs:"$ctrl",link:function(e,t,n){e.$ctrl.refineSearchVisible=t.parent().parent()[0].hasAttribute("refine-search")}}}])}),define("common/directives/help-text.directive",["common/lodash","common/moment","common/modules/directives","common/services/notification.service"],function(e,t,n){function r(e,t){function n(){var n=e.getHelpText();t.info(e.title||r,n)}var r="Help";this.displayHelpText=n}function i(e,t,n){function r(){return t.find(".help-text").html()}e.getHelpText=r}n.directive("helpText",["$templateCache",function(e){return{restrict:"E",scope:{title:"@?"},transclude:!0,controller:r,controllerAs:"helpText",template:e.get("help-text.html"),link:i}}]),r.$inject=["$scope","notificationService"]}),define("common/directives/scroll-shadows.directive",["common/angular","common/modules/directives"],function(e,t){"use strict";function n(t,n,r){function i(){u(),a(),l(),s()}function o(){var e=f.width(),t=p+"__shadows--show-left",n=p+"__shadows--show-right",r=d.scrollLeft(),i=d.width();if(e<=i)return void d.removeClass(t+" "+n);d[r>0?"addClass":"removeClass"](t),d[r
    ').parent(),d=f.wrap('
    ').parent(),d.wrap('
    ')}var f,d,p="chr_scroll-shadows";!function(){c(),i(),o()}()}t.directive("scrollShadows",[function(){return{restrict:"A",controller:n}}]),n.$inject=["$element","$scope","$window"]}),define("common/directives/timepicker-select.directive",["common/moment","common/modules/directives"],function(e,t){"use strict";function n(t){function n(){var n=+t.timepickerSelectInterval||1,i=e.duration(t.timepickerSelectTimeFrom||"00:00"),o=e.duration(t.timepickerSelectTimeTo||"23:59");for(r.options=[];i.asMinutes()<=o.asMinutes();){var a=e.utc(i.asMilliseconds());r.options.push(a.format("HH:mm")),i.add(n,"minutes")}}var r=this;r.placeholder=t.timepickerSelectPlaceholder,r.options=[],t.$watchGroup(["timepickerSelectTimeFrom","timepickerSelectTimeTo","timepickerSelectInterval"],function(){n()})}t.directive("timepickerSelect",["$templateCache",function(e){return{scope:{timepickerSelectPlaceholder:"@",timepickerSelectTimeFrom:"<",timepickerSelectTimeTo:"<",timepickerSelectInterval:"<"},restrict:"A",controllerAs:"selector",controller:["$scope",n],template:e.get("timepicker-select.html")}}]),n.$inject=["$scope"]}),define("common/directives/time-amount-picker.directive",["common/lodash","common/modules/directives"],function(e,t){"use strict";function n(t){function n(){var e=Math.floor(c);for(d.hoursOptions=[];e<=f;)d.hoursOptions.push(e),e++}function r(){var e,t,n,r=0;for(d.minutesOptions=[];r<60;)t=+d.selectedHours===Math.floor(c)&&rf%1*60,e=t||n,!e&&d.minutesOptions.push(r),r+=u;l()}function i(){u=+t.interval||1,c=isNaN(+t.minAmount)?0:+t.minAmount,f=isNaN(+t.maxAmount)?24:+t.maxAmount,n(),r()}function o(){""!==d.selectedHours&&""!==d.selectedMinutes&&(t.value=+d.selectedHours+d.selectedMinutes/60)}function a(){t.$watch("disabled",function(e){d.disabled=e}),t.$watch("value",function(){s()}),t.$watchGroup(["minAmount","maxAmount","interval"],function(){i()})}function s(){void 0!==t.value&&(d.selectedHours=""+Math.floor(t.value),d.selectedMinutes=""+Math.floor(t.value%1*60)),o()}function l(){d.selectedMinutese.last(d.minutesOptions)&&(d.selectedMinutes=""+e.last(d.minutesOptions))}var u,c,f,d=this;d.hoursOptions=[],d.minutesOptions=[],d.selectedHours="",d.selectedMinutes="",d.buildMinutesOptions=r,d.calculateSelectedValue=o,function(){s(),a()}()}t.directive("timeAmountPicker",["$templateCache",function(e){return{scope:{minAmount:".75?Math.floor(.25*Math.ceil(e/.25))+"h":"",n=e%1&&e%1<=.75&&e%1>0?.25*Math.ceil(e%1/.25)*60+"m":"",r+t+(t&&n?" ":"")+n)}};return function(t,n){var r=void 0===t?0:parseFloat(t);if(isNaN(r))throw new Error("Value must be a number or a numeric string: "+t);return e[n](r)}})}),define("common/bundles/filters",["common/filters/time-unit-applier.filter"],function(){}),define("common/decorators/angular-date/datepicker-popup",["common/lodash"],function(e){return["$delegate","HR_settings",function(t,n){"use strict";var r=t[0].link -;return t[0].compile=function(){return function(t,i,o,a){o.uibDatepickerPopup=o.uibDatepickerPopup||n.DATE_FORMAT||"yyyy-MM-dd",o.showButtonBar=o.showButtonBar||!1,t.datepickerOptions=e.assign({formatDayHeader:"E",showWeeks:!1,startingDay:1},t.datepickerOptions),r.apply(this,arguments)}},t}]}),define("common/decorators/angular-date/date-filter",[],function(){"use strict";return["$delegate",function(e){var t=e;return function(){if("E"===arguments[1]){var e=Array.prototype.slice.call(arguments);return e[1]="EEE",t.apply(this,e)[0]}return t.apply(this,arguments)}}]}),function(e){define("common/modules/angular-date",["common/angular","common/decorators/angular-date/datepicker-popup","common/decorators/angular-date/date-filter","common/modules/services","common/angularBootstrap","common/modules/templates"],function(t,n,r){"use strict";function i(t){var n="uib/template/datepicker/"+t+".html",r=o.get(n);r=r.replace(/glyphicon glyphicon-chevron-(left|right)/gm,"fa fa-chevron-$1"),"day"===t&&(r=function(t){return e(t).find('th[ng-if="showWeeks"]').parent().css({"border-top":"1px solid #DDD"}),e(t).prop("outerHTML")}(e.parseHTML(r))),o.put(n,r)}var o;return t.module("common.angularDate",["common.services","ui.bootstrap","common.templates"]).config(["$provide",function(e){e.decorator("uibDatepickerPopupDirective",n),e.decorator("dateFilter",r)}]).run(["$templateCache",function(e){o=e,["day","month","year"].forEach(i)}])})}(CRM.$),define("common/services/angular-date/date-format",["common/angular","common/modules/angular-date","common/services/hr-settings"],function(e,t){"use strict";t.factory("DateFormat",["$q","HR_settings",function(e,t){return{dateFormat:null,getDateFormat:function(){return this.dateFormat?e.when(this.dateFormat):e.when("dd/MM/yyyy").catch(function(){return"yyyy-MM-dd"}).then(function(e){return t.DATE_FORMAT=e,this.dateFormat=e,e}.bind(this))}}}])}),define("common/filters/angular-date/format-date",["common/moment","common/modules/angular-date","common/services/hr-settings"],function(e,t){"use strict";t.filter("formatDate",["HR_settings",function(t){var n=["DD-MM-YYYY","DD-MM-YYYY HH:mm:ss","YYYY-MM-DD","YYYY-MM-DD HH:mm:ss","DD/MM/YYYY","x","YYYY-MM-DD HH:mm:ss"];return function(r,i,o){var a,s=i||t.DATE_FORMAT||"YYYY-MM-DD",l=e(0);return r instanceof Date&&(r=e(r).format("YYYY-MM-DD HH:mm:ss")),a=e(r,n,!0),a.isValid()&&!a.isSame(l)?i===Date?a.toDate():a.format(s.toUpperCase())+("hours"===o?" "+a.format("HH:mm"):""):"Unspecified"}}])}),define("common/directives/angular-date/date-input",["common/modules/angular-date","common/filters/angular-date/format-date"],function(e){"use strict";e.directive("dateInput",["$filter",function(e){return{require:"ngModel",link:function(t,n,r,i){function o(t){var n=e("formatDate")(t);return n="Unspecified"==n?"":n}i.$formatters.push(o),i.$parsers=[]}}}])}),define("common/bundles/angular-date",["common/services/angular-date/date-format","common/filters/angular-date/format-date","common/directives/angular-date/date-input"],function(){}),define("common/modules/routers/compu-ng-route",["common/angular","common/angularRoute"],function(e){"use strict";return e.module("compuNgRoute",["ngRoute"]).config(["$routeProvider",function(t){var n=t.when;t.resolveForAll=function(e){return t.commonResolve=e,t},t.when=function(r,i){return e.extend(i.resolve||{},t.commonResolve||{}),n.call(t,r,i)}}])}),"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function r(e,t){return L(new(L(function(){},{prototype:e})),t)}function i(e){return j(arguments,function(t){t!==e&&j(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var r in e.path){if(e.path[r]!==t.path[r])break;n.push(e.path[r])}return n}function a(e){if(Object.keys)return Object.keys(e);var t=[];return j(e,function(e,n){t.push(n)}),t}function s(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,r=Number(arguments[2])||0;for(0>(r=0>r?Math.ceil(r):Math.floor(r))&&(r+=n);n>r;r++)if(r in e&&e[r]===t)return r;return-1}function l(e,t,n,r){var i,l=o(n,r),u={},c=[];for(var f in l)if(l[f].params&&(i=a(l[f].params),i.length))for(var d in i)s(c,i[d])>=0||(c.push(i[d]),u[i[d]]=e[i[d]]);return L({},u,t)}function u(e,t,n){if(!n){n=[];for(var r in e)n.push(r)}for(var i=0;i "));if(y[n]=r,I(e))g.push(n,[function(){return t.get(e)}],u);else{var i=t.annotate(e);j(i,function(e){e!==n&&l.hasOwnProperty(e)&&p(l[e],e)}),g.push(n,e,i)}v.pop(),y[n]=o}}function h(e){return P(e)&&e.then&&e.$$promises}if(!P(l))throw new Error("'invocables' must be an object");var m=a(l||{}),g=[],v=[],y={};return j(l,p),l=v=y=null,function(r,o,a){function s(){--b||($||i(y,o.$$values),p.$$values=y,p.$$promises=p.$$promises||!0,delete p.$$inheritedValues,u.resolve(y))}function l(e){p.$$failure=e,u.reject(e)}if(h(r)&&a===n&&(a=o,o=r,r=null),r){if(!P(r))throw new Error("'locals' must be an object")}else r=c;if(o){if(!h(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=f;var u=e.defer(),p=u.promise,v=p.$$promises={},y=L({},r),b=1+g.length/3,$=!1;if(N(o.$$failure))return l(o.$$failure),p;o.$$inheritedValues&&i(y,d(o.$$inheritedValues,m)),L(v,o.$$promises),o.$$values?($=i(y,d(o.$$values,m)),p.$$inheritedValues=d(o.$$values,m),s()):(o.$$inheritedValues&&(p.$$inheritedValues=d(o.$$inheritedValues,m)),o.then(s,l));for(var w=0,x=g.length;x>w;w+=3)r.hasOwnProperty(g[w])?s():function(n,i,o){function u(e){f.reject(e),l(e)}function c(){if(!N(p.$$failure))try{f.resolve(t.invoke(i,a,y)),f.promise.then(function(e){y[n]=e,s()},u)}catch(e){u(e)}}var f=e.defer(),d=0;j(o,function(e){v.hasOwnProperty(e)&&!r.hasOwnProperty(e)&&(d++,v[e].then(function(t){y[e]=t,--d||c()},u))}),d||c(),v[n]=f.promise}(g[w],g[w+1],g[w+2]);return p}},this.resolve=function(e,t,n,r){return this.study(e)(t,n,r)}}function g(e,t,n){this.fromConfig=function(e,t,n){return N(e.template)?this.fromString(e.template,t):N(e.templateUrl)?this.fromUrl(e.templateUrl,t):N(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return R(e)?e(t):e},this.fromUrl=function(n,r){return R(n)&&(n=n(r)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,r){return n.invoke(e,null,r||{params:t})}}function v(e,t,i){function o(t,n,r,i){if(g.push(t),h[t])return h[t];if(!/^\w+(-+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(m[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return m[t]=new H.Param(t,n,r,i),m[t]}function a(e,t,n,r){var i=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:i=["(",")"+(r?"?":"")];break;case!0:i=["?(",")?"];break;default:i=["("+n+"|",")?"]}return o+i[0]+t+i[1]}function s(i,o){var a,s,l,u,c;return a=i[2]||i[3],c=t.params[a],l=e.substring(d,i.index),s=o?i[4]:i[4]||("*"==i[1]?".*":null),u=H.type(s||"string")||r(H.type("string"),{pattern:new RegExp(s,t.caseInsensitive?"i":n)}),{id:a,regexp:s,segment:l,type:u,cfg:c}}t=L({params:{}},P(t)?t:{});var l,u=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,c=/([:]?)([\w\[\]-]+)|\{([\w\[\]-]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,f="^",d=0,p=this.segments=[],h=i?i.params:{},m=this.params=i?i.params.$$new():new H.ParamSet,g=[];this.source=e;for(var v,y,b;(l=u.exec(e))&&(v=s(l,!1),!(v.segment.indexOf("?")>=0));)y=o(v.id,v.type,v.cfg,"path"),f+=a(v.segment,y.type.pattern.source,y.squash,y.isOptional),p.push(v.segment),d=u.lastIndex;b=e.substring(d);var $=b.indexOf("?");if($>=0){var w=this.sourceSearch=b.substring($);if(b=b.substring(0,$),this.sourcePath=e.substring(0,d+$),w.length>0)for(d=0;l=c.exec(w);)v=s(l,!0),y=o(v.id,v.type,v.cfg,"search"),d=u.lastIndex}else this.sourcePath=e,this.sourceSearch="";f+=a(b)+(!1===t.strict?"/?":"")+"$",p.push(b),this.regexp=new RegExp(f,t.caseInsensitive?"i":n),this.prefix=p[0],this.$$paramNames=g}function y(e){L(this,e)}function b(){function e(e){return null!=e?e.toString().replace(/\//g,"%2F"):e}function i(e){return null!=e?e.toString().replace(/%2F/g,"/"):e}function o(){return{strict:m,caseInsensitive:d}}function l(e){return R(e)||F(e)&&R(e[e.length-1])}function u(){for(;x.length;){var e=x.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend($[e.name],f.invoke(e.def))}}function c(e){L(this,e||{})}H=this;var f,d=!1,m=!0,g=!1,$={},w=!0,x=[],C={string:{encode:e,decode:i,is:function(e){return null==e||!N(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return N(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};b.$$getDefaultValue=function(e){if(!l(e.value))return e.value;if(!f)throw new Error("Injectable functions cannot be called at configuration time");return f.invoke(e.value)},this.caseInsensitive=function(e){return N(e)&&(d=e),d},this.strictMode=function(e){return N(e)&&(m=e),m},this.defaultSquashPolicy=function(e){if(!N(e))return g;if(!0!==e&&!1!==e&&!I(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return g=e,e},this.compile=function(e,t){return new v(e,L(o(),t))},this.isMatcher=function(e){if(!P(e))return!1;var t=!0;return j(v.prototype,function(n,r){R(n)&&(t=t&&N(e[r])&&R(e[r]))}),t},this.type=function(e,t,n){if(!N(t))return $[e];if($.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return $[e]=new y(L({name:e},t)),n&&(x.push({name:e,def:n}),w||u()),this},j(C,function(e,t){$[t]=new y(L({name:t},e))}),$=r($,{}),this.$get=["$injector",function(e){return f=e,w=!1,u(),j(C,function(e,t){$[t]||($[t]=new y(e))}),this}],this.Param=function(e,t,r,i){function o(){if(!f)throw new Error("Injectable functions cannot be called at configuration time");var e=f.invoke(r.$$fn);if(null!==e&&e!==n&&!d.type.is(e))throw new Error("Default value ("+e+") for parameter '"+d.id+"' is not an instance of Type ("+d.type.name+")");return e}function u(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=h(p(d.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),N(e)?d.type.$normalize(e):o()}function c(){return"{Param:"+e+" "+t+" squash: '"+b+"' optional: "+v+"}"}var d=this;r=function(e){var t=P(e)?a(e):[];return-1===s(t,"value")&&-1===s(t,"type")&&-1===s(t,"squash")&&-1===s(t,"array")&&(e={value:e}),e.$$fn=l(e.value)?e.value:function(){return e.value},e}(r),t=function(t,n,r){if(t.type&&n)throw new Error("Param '"+e+"' has two type configurations.");return n||(t.type?t.type instanceof y?t.type:new y(t.type):"config"===r?$.any:$.string)}(r,t,i);var m=function(){var t={array:"search"===i&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return L(t,n,r).array}();t=m?t.$asArray(m,"search"===i):t,"string"!==t.name||m||"path"!==i||r.value!==n||(r.value="");var v=r.value!==n,b=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!N(n)||null==n)return g;if(!0===n||I(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,v),w=function(e,t,r,i){var o,a,l=[{from:"",to:r||t?n:""},{from:null,to:r||t?n:""}];return o=F(e.replace)?e.replace:[],I(i)&&o.push({from:i,to:n}),a=h(o,function(e){return e.from}),p(l,function(e){return-1===s(a,e.from)}).concat(o)}(r,m,v,b);L(this,{id:e,type:t,location:i,array:m,squash:b,replace:w,isOptional:v,value:u,dynamic:n,config:r,toString:c})},c.prototype={$$new:function(){return r(this,L(new c,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,r=a(c.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),j(t,function(t){j(a(t),function(t){-1===s(e,t)&&-1===s(r,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return j(n.$$keys(),function(r){t[r]=n[r].value(e&&e[r])}),t},$$equals:function(e,t){var n=!0,r=this;return j(r.$$keys(),function(i){var o=e&&e[i],a=t&&t[i];r[i].type.equals(o,a)||(n=!1)}),n},$$validates:function(e){var r,i,o,a,s,l=this.$$keys();for(r=0;ri;i++)if(t(u[i]))return;c&&t(c)}}function p(){return l=l||i.$on("$locationChangeSuccess",d)}var h,m=a.baseHref(),g=r.url();return f||p(),{sync:function(){d()},listen:function(){return p()},update:function(e){return e?void(g=r.url()):void(r.url()!==g&&(r.url(g),r.replace()))},push:function(e,t,i){var o=e.format(t||{});null!==o&&t&&t["#"]&&(o+="#"+t["#"]),r.url(o),h=i&&i.$$avoidResync?r.url():n,i&&i.replace&&r.replace()},href:function(n,i,o){if(!n.validates(i))return null;var a=e.html5Mode();t.isObject(a)&&(a=a.enabled);var l=n.format(i);if(o=o||{},a||null===l||(l="#"+e.hashPrefix()+l),null!==l&&i&&i["#"]&&(l+="#"+i["#"]),l=s(l,a,o.absolute),!o.absolute||!l)return l;var u=!a&&l?"/":"",c=r.port();return c=80===c||443===c?"":":"+c,[r.protocol(),"://",r.host(),c,u,l].join("")}}}var l,u=[],c=null,f=!1;this.rule=function(e){if(!R(e))throw new Error("'rule' must be a function");return u.push(e),this},this.otherwise=function(e){if(I(e)){var t=e;e=function(){return t}}else if(!R(e))throw new Error("'rule' must be a function");return c=e,this},this.when=function(e,t){var n,s=I(t);if(I(e)&&(e=r.compile(e)),!s&&!R(t)&&!F(t))throw new Error("invalid 'handler' in when()");var l={matcher:function(e,t){return s&&(n=r.compile(t),t=["$match",function(e){return n.format(e)}]),L(function(n,r){return a(n,t,e.exec(r.path(),r.search()))},{prefix:I(e.prefix)?e.prefix:""})},regex:function(e,t){if(e.global||e.sticky)throw new Error("when() RegExp must not be global or sticky");return s&&(n=t,t=["$match",function(e){return o(n,e)}]),L(function(n,r){return a(n,t,e.exec(r.path()))},{prefix:i(e)})}},u={matcher:r.isMatcher(e),regex:e instanceof RegExp};for(var c in u)if(u[c])return this.rule(l[c](e,t));throw new Error("invalid 'what' in when()")},this.deferIntercept=function(e){e===n&&(e=!0),f=e},this.$get=s,s.$inject=["$location","$rootScope","$injector","$browser"]}function w(e,i){function o(e){return 0===e.indexOf(".")||0===e.indexOf("^")}function d(e,t){if(!e)return n;var r=I(e),i=r?e:e.name;if(o(i)){if(!t)throw new Error("No reference point given for path '"+i+"'");t=d(t);for(var a=i.split("."),s=0,l=a.length,u=t;l>s;s++)if(""!==a[s]||0!==s){if("^"!==a[s])break;if(!u.parent)throw new Error("Path '"+i+"' not valid for state '"+t.name+"'");u=u.parent}else u=t;a=a.slice(s).join("."),i=u.name+(u.name&&a?".":"")+a}var c=E[i];return!c||!r&&(r||c!==e&&c.self!==e)?n:c}function p(e,t){S[e]||(S[e]=[]),S[e].push(t)}function m(e){for(var t=S[e]||[];t.length;)g(t.shift())}function g(t){t=r(t,{self:t,resolve:t.resolve||{},toString:function(){return this.name}});var n=t.name;if(!I(n)||n.indexOf("@")>=0)throw new Error("State must have a valid name");if(E.hasOwnProperty(n))throw new Error("State '"+n+"'' is already defined");var i=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):I(t.parent)?t.parent:P(t.parent)&&I(t.parent.name)?t.parent.name:"";if(i&&!E[i])return p(i,t.self);for(var o in M)R(M[o])&&(t[o]=M[o](t,M.$delegates[o]));return E[n]=t,!t[_]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){k.$current.navigable==t&&u(e,n)||k.transitionTo(t,e,{inherit:!0,location:!1})}]),m(n),t}function v(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=k.$current.name.split("."),r=0,i=t.length;i>r;r++)"*"===t[r]&&(n[r]="*");return"**"===t[0]&&(n=n.slice(s(n,t[1])),n.unshift("**")),"**"===t[t.length-1]&&(n.splice(s(n,t[t.length-2])+1,Number.MAX_VALUE),n.push("**")),t.length==n.length&&n.join("")===t.join("")}function b(e,t){return I(e)&&!N(t)?M[e]:R(t)&&I(e)?(M[e]&&!M.$delegates[e]&&(M.$delegates[e]=M[e]),M[e]=t,this):this}function $(e,t){return P(e)?t=e:t.name=e,g(t),this}function w(e,i,o,s,f,p,m,g,b){function $(t,n,r,o){var a=e.$broadcast("$stateNotFound",t,n,r);if(a.defaultPrevented)return m.update(),T;if(!a.retry)return null;if(o.$retry)return m.update(),D;var s=k.transition=i.when(a.retry);return s.then(function(){return s!==k.transition?S:(t.options.$retry=!0,k.transitionTo(t.to,t.toParams,t.options))},function(){return T}),m.update(),s}function w(e,n,r,a,l,u){function d(){var n=[];return j(e.views,function(r,i){var a=r.resolve&&r.resolve!==e.resolve?r.resolve:{};a.$template=[function(){return o.load(i,{view:r,locals:l.globals,params:p,notify:u.notify})||""}],n.push(f.resolve(a,l.globals,l.resolve,e).then(function(n){if(R(r.controllerProvider)||F(r.controllerProvider)){var o=t.extend({},a,l.globals);n.$$controller=s.invoke(r.controllerProvider,null,o)}else n.$$controller=r.controller;n.$$state=e,n.$$controllerAs=r.controllerAs,l[i]=n}))}),i.all(n).then(function(){return l.globals})}var p=r?n:c(e.params.$$keys(),n),h={$stateParams:p};l.resolve=f.resolve(e.resolve,h,l.resolve,e);var m=[l.resolve.then(function(e){l.globals=e})];return a&&m.push(a),i.all(m).then(d).then(function(e){return l})}var S=i.reject(new Error("transition superseded")),M=i.reject(new Error("transition prevented")),T=i.reject(new Error("transition aborted")),D=i.reject(new Error("transition failed"));return C.locals={resolve:null,globals:{$stateParams:{}}},k={params:{},current:C.self,$current:C,transition:null},k.reload=function(e){return k.transitionTo(k.current,p,{reload:e||!0,inherit:!1,notify:!0})},k.go=function(e,t,n){return k.transitionTo(e,t,L({inherit:!0,relative:k.$current},n))},k.transitionTo=function(t,n,o){n=n||{},o=L({location:!0,inherit:!1,relative:null,notify:!0,reload:!1,$retry:!1},o||{});var a,u=k.$current,f=k.params,h=u.path,g=d(t,o.relative),v=n["#"];if(!N(g)){var y={to:t,toParams:n,options:o},b=$(y,u.self,f,o);if(b)return b;if(t=y.to,n=y.toParams,o=y.options,g=d(t,o.relative),!N(g)){if(!o.relative)throw new Error("No such state '"+t+"'");throw new Error("Could not resolve '"+t+"' from state '"+o.relative+"'")}}if(g[_])throw new Error("Cannot transition to abstract state '"+t+"'");if(o.inherit&&(n=l(p,n||{},k.$current,g)),!g.params.$$validates(n))return D;n=g.params.$$values(n),t=g;var E=t.path,T=0,A=E[T],O=C.locals,R=[];if(o.reload){if(I(o.reload)||P(o.reload)){if(P(o.reload)&&!o.reload.name)throw new Error("Invalid reload state object");var F=!0===o.reload?h[0]:d(o.reload);if(o.reload&&!F)throw new Error("No such reload state '"+(I(o.reload)?o.reload:o.reload.name)+"'");for(;A&&A===h[T]&&A!==F;)O=R[T]=A.locals,T++,A=E[T]}}else for(;A&&A===h[T]&&A.ownParams.$$equals(n,f);)O=R[T]=A.locals,T++,A=E[T];if(x(t,n,u,f,O,o))return v&&(n["#"]=v),k.params=n,U(k.params,p),o.location&&t.navigable&&t.navigable.url&&(m.push(t.navigable.url,n,{$$avoidResync:!0,replace:"replace"===o.location}),m.update(!0)),k.transition=null,i.when(k.current);if(n=c(t.params.$$keys(),n||{}),o.notify&&e.$broadcast("$stateChangeStart",t.self,n,u.self,f).defaultPrevented)return e.$broadcast("$stateChangeCancel",t.self,n,u.self,f),m.update(),M;for(var j=i.when(O),H=T;H=T;r--)a=h[r],a.self.onExit&&s.invoke(a.self.onExit,a.self,a.locals.globals),a.locals=null;for(r=T;r=0?i:i+"@"+(o?o.state.name:"")}function _(e,t){var n,r=e.match(/^\s*({[^}]*})\s*$/);if(r&&(e=t+"("+r[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function M(e){var t=e.parent().inheritedData("$uiView");return t&&t.state&&t.state.name?t.state:void 0}function T(e,n){var r=["location","inherit","reload","absolute"];return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(i,o,a,s){var l=_(a.uiSref,e.current.name),u=null,c=M(o)||e.$current,f="[object SVGAnimatedString]"===Object.prototype.toString.call(o.prop("href"))?"xlink:href":"href",d=null,p="A"===o.prop("tagName").toUpperCase(),h="FORM"===o[0].nodeName,m=h?"action":f,g=!0,v={relative:c,inherit:!0},y=i.$eval(a.uiSrefOpts)||{};t.forEach(r,function(e){e in y&&(v[e]=y[e])});var b=function(n){if(n&&(u=t.copy(n)),g){d=e.href(l.state,u,v);var r=s[1]||s[0];return r&&r.$$addStateInfo(l.state,u),null===d?(g=!1,!1):void a.$set(m,d)}};l.paramExpr&&(i.$watch(l.paramExpr,function(e,t){e!==u&&b(e)},!0),u=t.copy(i.$eval(l.paramExpr))),b(),h||o.bind("click",function(t){if(!((t.which||t.button)>1||t.ctrlKey||t.metaKey||t.shiftKey||o.attr("target"))){var r=n(function(){e.go(l.state,u,v)});t.preventDefault();var i=p&&!d?1:0;t.preventDefault=function(){i--<=0&&n.cancel(r)}}})}}}function D(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs",function(t,r,i){function o(){a()?r.addClass(l):r.removeClass(l)}function a(){for(var e=0;er;r++){o=a[r];var c=this.params[o],f=n[r+1];for(i=0;ir;r++)o=a[r],u[o]=this.params[o].value(t[o]);return u},v.prototype.parameters=function(e){return N(e)?this.params[e]||null:this.$$paramNames},v.prototype.validates=function(e){return this.params.$$validates(e)},v.prototype.format=function(e){function t(e){return encodeURIComponent(e).replace(/-/g,function(e){return"%5C%"+e.charCodeAt(0).toString(16).toUpperCase()})}e=e||{};var n=this.segments,r=this.parameters(),i=this.params;if(!this.validates(e))return null;var o,a=!1,s=n.length-1,l=r.length,u=n[0];for(o=0;l>o;o++){var c=s>o,f=r[o],d=i[f],p=d.value(e[f]),m=d.isOptional&&d.type.equals(d.value(),p),g=!!m&&d.squash,v=d.type.encode(p);if(c){var y=n[o+1];if(!1===g)null!=v&&(u+=F(v)?h(v,t).join("-"):encodeURIComponent(v)),u+=y;else if(!0===g){var b=u.match(/\/$/)?/\/?(.*)/:/(.*)/;u+=y.match(b)[1]}else I(g)&&(u+=g+y)}else{if(null==v||m&&!1!==g)continue;F(v)||(v=[v]),v=h(v,encodeURIComponent).join("&"+f+"="),u+=(a?"&":"?")+f+"="+v,a=!0}}return u},y.prototype.is=function(e,t){return!0},y.prototype.encode=function(e,t){return e},y.prototype.decode=function(e,t){return e},y.prototype.equals=function(e,t){return e==t},y.prototype.$subPattern=function(){var e=this.pattern.toString();return e.substr(1,e.length-2)},y.prototype.pattern=/.*/,y.prototype.toString=function(){return"{Type:"+this.name+"}"},y.prototype.$normalize=function(e){return this.is(e)?e:this.decode(e)},y.prototype.$asArray=function(e,t){function r(e,t){function r(e,t){return function(){return e[t].apply(e,arguments)}}function i(e){return F(e)?e:N(e)?[e]:[]}function o(e){switch(e.length){case 0:return n;case 1:return"auto"===t?e[0]:e;default:return e}}function a(e){return!e}function s(e,t){return function(n){n=i(n);var r=h(n,e) -;return!0===t?0===p(r,a).length:o(r)}}this.encode=s(r(e,"encode")),this.decode=s(r(e,"decode")),this.is=s(r(e,"is"),!0),this.equals=function(e){return function(t,n){var r=i(t),o=i(n);if(r.length!==o.length)return!1;for(var a=0;a=":n(e.from)}:{"<=":n(e.to)}}function o(e){return e.in?{IN:e.in}:{"NOT IN":e.nin}}return{extend:function(t){return e.assign(Object.create(this),t)},compactFilters:function(t){return t?e.pick(t,function(e){return 0===e||!1===e||!!e}):null},processFilters:function(t){return t?(t=this.compactFilters(t),e.transform(t,function(e,t,n){t.from||t.to?e[n]=i(t):t.in||t.nin?e[n]=o(t):e[n]=t},{})):null}}})}),define("common/models/contact-job-role.model",["common/modules/models","common/models/model","common/instances/contact-job-role-instance.instance","common/services/api/contact-job-role-api.api"],function(e){"use strict";e.factory("ContactJobRole",["$log","Model","ContactJobRoleAPI","ContactJobRoleInstance",function(e,t,n,r){return e.debug("ContactJobRole"),t.extend({all:function(e){return n.all(e).then(function(e){return e.list.map(function(e){return r.init(e,!0)})})}})}])}),define("common/models/instances/group-instance",["common/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("GroupInstance",["ModelInstance",function(e){var t=["id","name","title","description"];return e.extend({fromAPIFilter:function(e,n,r){_.includes(t,r)&&(e[r]=this[r])}})}])}),define("common/mocks/module",["common/angular"],function(e){"use strict";return e.module("common.mocks",[])}),define("common/mocks/services/api/group-mock",["common/lodash","common/mocks/module"],function(e,t){"use strict";t.factory("api.group.mock",["$q",function(t){function n(e){var n=t.defer();return n.resolve(e),n.promise}return{all:function(e,t,r){var i,o,a;return i=r||this.mockedGroups().list,e&&(i=i.filter(function(t){return Object.keys(e).every(function(n){return t[n]===e[n]})})),t&&(o=(t.page-1)*t.size,a=o+t.size,i=i.slice(o,a)),n({list:i,total:i.length,allIds:i.map(function(e){return e.id}).join(",")})},find:function(e,t){return n(t||this.mockedGroups().list.filter(function(t){return t.id===e})[0])},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedGroups:function(){return{total:5,list:[{id:"1",name:"Administrators",title:"Administrators",description:"Contacts in this group are assigned Administrator role permissions.",is_active:"1",visibility:"User and User Admin Only",group_type:["1"],is_hidden:"0",is_reserved:"0"},{id:"2",name:"Newsletter Subscribers",title:"Newsletter Subscribers",is_active:'"1',visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"3",name:"Summer Program Volunteers",title:"Summer Program Volunteers",is_active:"1",visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"4",name:"Advisory Board",title:"Advisory Board",is_active:"1",visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"5",name:"Case_Resources",title:"Case Resources",description:"Contacts in this group are listed with their phone number and email when viewing case. You also can send copies of case activities to these contacts.",is_active:"1",visibility:"User and User Admin Only",where_clause:"...",select_tables:"...",where_tables:"...",group_type:"2",is_hidden:"0",is_reserved:"0"}]}}}}])}),define("common/mocks/data/contact.data",[],function(){return{all:{is_error:0,version:3,count:26,values:[{id:"1",contact_id:"1",display_name:"Dr. Kiara Jensen-Parker",email:"kh.jensen-parker@testing.info",contact_type:"Individual"},{id:"2",contact_id:"2",display_name:"jacobc82@lol.co.pl",email:"cruz.v.jacob@spamalot.com",contact_type:"Individual"},{id:"3",contact_id:"3",display_name:"Mei Müller-Nielsen",email:"mz.mller-nielsen75@infomail.co.pl",contact_type:"Individual"},{id:"4",contact_id:"4",display_name:"Ms. Brigette Deforest",email:"deforest.p.brigette9@fakemail.info",contact_type:"Individual"},{id:"5",contact_id:"5",display_name:"robertsc@testing.net",email:"clintr56@mymail.org",contact_type:"Individual"},{id:"6",contact_id:"6",display_name:"Dr. Allen Samuels Sr.",email:"samuelsa@mymail.org",contact_type:"Individual"},{id:"7",contact_id:"7",display_name:"Mei Wilson",email:"wilson.u.mei59@sample.org",contact_type:"Individual"},{id:"8",contact_id:"8",display_name:"Dr. Betty Díaz",email:"dazb@sample.co.nz",contact_type:"Individual"},{id:"9",contact_id:"9",display_name:"Bob Jones-Dimitrov",email:"bobj@testmail.biz",contact_type:"Individual"},{id:"10",contact_id:"10",display_name:"Truman Samuels III",email:"trumans@spamalot.org",contact_type:"Individual"},{id:"11",contact_id:"11",display_name:"Iris Wagner",email:"iwagner75@notmail.info",contact_type:"Individual"},{id:"12",contact_id:"12",display_name:"Mr. Rosario McReynolds",email:"rosariomcreynolds@testmail.org",contact_type:"Individual"},{id:"13",contact_id:"13",display_name:"Shad Jones-Dimitrov III",email:"shadj@lol.net",contact_type:"Individual"},{id:"14",contact_id:"14",display_name:"Toby Cruz Sr.",email:"",contact_type:"Individual"},{id:"15",contact_id:"15",display_name:"lareedaz61@testing.com",email:"lareedaz61@testing.com",contact_type:"Individual"},{id:"16",contact_id:"16",display_name:"Dr. Jay Deforest",email:"jayd@fishmail.org",contact_type:"Individual"},{id:"17",contact_id:"17",display_name:"Mr. Norris Cruz",email:"norriscruz@spamalot.info",contact_type:"Individual"},{id:"18",contact_id:"18",display_name:"herminiac@fishmail.com",email:"herminiac@fishmail.com",contact_type:"Individual"},{id:"19",contact_id:"19",display_name:"Ashley Terrell",email:"terrell.ashley@testmail.info",contact_type:"Individual"},{id:"20",contact_id:"20",display_name:"Kandace Parker-Díaz",email:"parker-daz.kandace67@fishmail.co.uk",contact_type:"Individual"},{id:"21",contact_id:"21",display_name:"Nicole Samuels",email:"ng.samuels@testmail.net",contact_type:"Individual"},{id:"22",contact_id:"22",display_name:"Dr. Kandace Wattson",email:"kandacewattson@testing.info",contact_type:"Individual"},{id:"23",contact_id:"23",display_name:"Brittney Cruz",email:"cruz.brittney@spamalot.co.nz",contact_type:"Individual"},{id:"24",contact_id:"24",display_name:"Shauna Olsen",email:"",contact_type:"Individual"},{id:"202",contact_id:"202",display_name:"civihr_staff@compucorp.co.uk",email:"civihr_staff@compucorp.co.uk",contact_type:"Individual"},{id:"203",contact_id:"203",display_name:"civihr_manager@compucorp.co.uk",email:"civihr_manager@compucorp.co.uk",contact_type:"Individual"}]}}}),define("common/mocks/services/api/contact-mock",["common/lodash","common/mocks/module","common/mocks/data/contact.data"],function(e,t,n){"use strict";t.factory("api.contact.mock",["$q",function(t){function r(e){var n=t.defer();return n.resolve(e),n.promise}return{all:function(t,i,o,a,s){var l,u,c;return l=s||n.all.values,t&&(l=l.filter(function(n){return Object.keys(t).every(function(r){return null===t[r]||("display_name"===r?new RegExp(t[r],"i").test(n[r]):t[r].IN?e.includes(t[r].IN,n[r]):n[r]===t[r])})})),i&&(u=(i.page-1)*i.size,c=u+i.size,l=l.slice(u,c)),r({list:l,total:l.length,allIds:l.map(function(e){return e.id}).join(",")})},find:function(e,t){return r(t||n.all.values.filter(function(t){return t.id===e})[0])},leaveManagees:function(){return r(this.mockedContacts().list)},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedContacts:function(){var e=n.all.values;return{total:e.length,list:e.map(function(e){return e})}}}}])}),define("common/mocks/services/api/group-contact-mock",["common/lodash","common/mocks/module","common/mocks/services/api/contact-mock","common/mocks/services/api/group-mock"],function(e,t){"use strict";t.factory("api.group-contact.mock",["$q","api.contact.mock","api.group.mock",function(t,n,r){function i(t){return e.sample(t)}function o(e){var n=t.defer();return n.resolve(e),n.promise}var a=n.mockedContacts().list,s=r.mockedGroups().list;return{all:function(e,t,n){var r,i,a;return r=n||this.mockedGroupsContacts.list,e&&(r=r.filter(function(t){return Object.keys(e).every(function(n){return t[n]===e[n]})})),t&&(i=(t.page-1)*t.size,a=i+t.size,r=r.slice(i,a)),o({list:r,total:r.length,allIds:r.map(function(e){return e.id}).join(",")})},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedGroupsContacts:{total:a.length,list:function(){var e=1;return a.map(function(t){return{id:""+e++,group_id:i(s).id,contact_id:t.id,status:"Added"}})}()}}}])}),define("common/models/group",["common/modules/models","common/models/model","common/models/instances/group-instance","common/mocks/services/api/group-mock","common/mocks/services/api/group-contact-mock"],function(e){"use strict";e.factory("Group",["Model","api.group.mock","api.group-contact.mock","GroupInstance",function(e,t,n,r){return e.extend({all:function(e,n){return t.all(this.processFilters(e),n).then(function(e){return e.list=e.list.map(function(e){return r.init(e,!0)}),e})},find:function(e){return t.find(e).then(function(e){return r.init(e,!0)})},contactIdsOf:function(e){return n.all({group_id:e}).then(function(e){return e.list.map(function(e){return e.contact_id})})}})}])}),define("common/models/instances/job-role-instance",["common/lodash","common/moment","common/modules/models-instances","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("JobRoleInstance",["ModelInstance","HR_settings",function(n,r){return n.extend({fromAPIFilter:function(n,i,o){var a=r.DATE_FORMAT.toUpperCase();e.endsWith(o,"_date")?n[o]=t(this[o],"YYYY-MM-DD HH:mm:ss").format(a):"api.HRJobContract.getsingle"===o?(n.contact_id=this[o].contact_id,n.job_contract_id=this[o].id):n[o]=this[o]},toAPIFilter:function(n,i,o){var a=["contact_id","job_contract_id"],s=r.DATE_FORMAT.toUpperCase();if(e.endsWith(o,"_date"))n[o]=t(this[o],s).format("YYYY-MM-DD HH:mm:ss");else{if(e.includes(a,o))return;n[o]=this[o]}}})}])}),define("common/services/api/job-role",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.job-role",["$log","api",function(e,t){return e.debug("api.jobRole"),t.extend({all:function(t,n,r,i){return e.debug("api.jobRole.api"),this.getAll("HrJobRoles",t,n,r,i)},find:function(t){return e.debug("api.jobRole.find"),this.sendGET("HRJobRole","get",{id:""+t},!1).then(function(e){return e.values[0]})}})}])}),define("common/models/job-role",["common/modules/models","common/models/model","common/models/instances/job-role-instance","common/services/api/job-role"],function(e){"use strict";e.factory("JobRole",["Model","api.job-role","JobRoleInstance",function(e,t,n){return e.extend({all:function(e,r){return t.all(this.processFilters(e),r).then(function(e){return e.list=e.list.map(function(e){return n.init(e,!0)}),e})},find:function(e){return t.find(e).then(function(e){return n.init(e,!0)})}})}])}),define("common/services/api/contact",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.contact",["$log","api",function(e,t){return e.debug("api.contact"),t.extend({all:function(t,n,r,i){return e.debug("api.contact.api"),this.getAll("Contact",t,n,r,i)},find:function(t){return e.debug("api.contact.find"),this.sendGET("Contact","get",{id:""+t},!1).then(function(e){return e.values[0]})},leaveManagees:function(t,n){return e.debug("api.contact.leaveManagees"),n=_.assign({},n,{managed_by:t}),this.sendGET("Contact","getleavemanagees",n).then(function(e){return e.values})}})}])}),define("common/models/instances/contact-instance",["common/modules/models-instances","common/models/instances/instance","common/services/api/contact"],function(e){"use strict";e.factory("ContactInstance",["ModelInstance","api.contact",function(e,t){return e.extend({leaveManagees:function(e){return t.leaveManagees(this.id,e)}})}])}),define("common/models/contact",["common/lodash","common/modules/models","common/models/model","common/models/contact-job-role.model","common/models/group","common/models/job-role","common/models/instances/contact-instance","common/services/api/contact"],function(e,t){"use strict";t.factory("Contact",["$q","Model","api.contact","Group","JobRole","ContactJobRole","ContactInstance",function(t,n,r,i,o,a,s){function l(t,n){return!e.isEmpty(e.intersection(e.keys(t),n))}function u(e){return a.all(e).then(function(e){return e.map(function(e){return e.contact_id})})}function c(t,n){return e(t).omit(d).omit(p).assign({id:{in:e.intersection.apply(null,n)}}).value()}function f(n){var r=t.defer(),o=[];return n=this.compactFilters(n),l(n,p)&&o.push(u(e.pick(n,p))),l(n,d)&&o.push(i.contactIdsOf(n.group_id)),e.isEmpty(o)?r.resolve(this.processFilters(n)):t.all(o).then(function(e){n=c(n,e),r.resolve(this.processFilters(n))}.bind(this)),r.promise}var d=["group_id"],p=["region","department","level_type","location"];return n.extend({all:function(e,t,n,i){return f.call(this,e).then(function(e){return e&&e.id&&!e.id.IN.length?{list:[]}:r.all(e,t,n,i)}).then(function(e){return e.list=e.list.map(function(e){return s.init(e,!0)}),e})},find:function(e){return r.find(e).then(function(e){return s.init(e,!0)})},leaveManagees:function(e,t){return f.call(this,t).then(function(t){return t&&t.id&&!t.id.IN.length?[]:r.leaveManagees(e,t)})}})}])}),define("common/models/instances/contract-instance",["common/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("ContractInstance",["ModelInstance",function(e){return e.extend({})}])}),define("common/services/api/contract",["common/lodash","common/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("api.contract",["$log","api",function(t,n){function r(t){var n=e.clone(t);return n.info=n["api.HRJobContract.getfulldetails"],delete n["api.HRJobContract.getfulldetails"],n}return t.debug("api.contract"),n.extend({all:function(e){return t.debug("ContractAPI.all"),e=e||{},e["api.HRJobContract.getfulldetails"]={jobcontract_id:"$value.id"},e.deleted=0,this.sendGET("HRJobContract","get",e,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r)})}})}])}),define("common/models/contract",["common/modules/models","common/models/model","common/models/instances/contract-instance","common/services/api/contract"],function(e){"use strict";e.factory("Contract",["$log","Model","api.contract","ContractInstance",function(e,t,n,r){return e.debug("Contract"),t.extend({all:function(e){return n.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})}})}])}),define("common/models/option-group",["common/modules/models","common/models/model","common/services/api/option-group"],function(e){"use strict";e.factory("OptionGroup",["Model","api.optionGroup",function(e,t){return e.extend({valuesOf:function(e,n,r){return t.valuesOf(e,n,r)}})}])}),function(e,t){define("common/models/session.model",["common/modules/models","common/models/model"],function(n){"use strict";n.factory("Session",["$log","$q","Model",function(n,r,i){return n.debug("Session"),i.extend({get:function(){var n={contactId:e.vars.session?e.vars.session.contact_id:t.settings.currentCiviCRMUserId};if(!n.contactId)throw new Error("Session Error: *Logged In Contact Id* is not defined");return r.resolve(n)}})}])})}(CRM,window.Drupal),define("common/bundles/models",["common/instances/contact-job-role-instance.instance","common/models/model","common/models/contact","common/models/contact-job-role.model","common/models/contract","common/models/group","common/models/job-role","common/models/option-group","common/models/session.model","common/models/instances/instance","common/models/instances/contact-instance","common/models/instances/contract-instance","common/models/instances/group-instance","common/models/instances/job-role-instance"],function(){}),define("common/services/dialog/dialog",["common/lodash","common/modules/services"],function(e,t){"use strict";function n(t,n,r){function i(i){var o;if(!e.isObject(i))throw new Error("Dialog Service: Options passed should be an object");return o=n.children(),t.open({appendTo:o.length?o.eq(0):n,size:"sm",controller:"DialogController",template:r.get("dialog.html"),resolve:{options:function(){return i}}}).result}return{open:i}}t.factory("dialog",n),n.$inject=["$uibModal","$rootElement","$templateCache"]}),define("common/controllers/dialog/dialog-ctrl",["common/lodash","common/modules/controllers"],function(e,t){"use strict";function n(t,n,r,i){function o(t){e.assign(n,e.defaultsDeep(t,{title:"CiviHR",msg:"",copyConfirm:"",copyCancel:"",classConfirm:"btn-primary",loading:!1}))}function a(){r.close(!1)}function s(){n.loading=!0,r.closed.then(n.onCloseAfterConfirm),t.resolve().then(n.onConfirm).then(function(){r.close(!0)})}n.cancel=a,n.confirm=s,function(){o(i),i.optionsPromise&&i.optionsPromise().then(function(e){o(e)})}()}t.controller("DialogController",n),n.$inject=["$q","$scope","$uibModalInstance","options"]}),define("common/modules/dialog",["common/angular","common/services/dialog/dialog","common/controllers/dialog/dialog-ctrl","common/angularBootstrap","common/directives/loading","common/modules/templates"],function(e){"use strict";return e.module("common.dialog",["ui.bootstrap","common.directives","common.templates"])}),define("common/decorators/xeditable-civi/editable-directive-factory",[],function(){"use strict";return["$delegate",function(e){return function(t){var n=e(t);return n.compile=function(e){var t,r=e[0].attributes.getNamedItem("ng-href");return e.append(''),r&&(t=angular.element(""),t.text("Follow link"),t.attr(r.nodeName,r.value),t.attr("ng-click","$event.stopPropagation();"),t.addClass("editable-link"),e.append(t),e.addClass("editable-with-link")),{post:n.link}},n}}]}),define("common/directives/xeditable-civi/editable-ta",[],function(){"use strict";return["editableDirectiveFactory","$timeout",function(e,t){var n,r;return r=e({directiveName:"editableTa",inputTpl:"",render:function(){this.parent.render.call(this),this.inputEl.parent().parent().removeClass("form-inline"),this.inputEl.addClass("editable-ta"),this.inputEl.attr("ng-model","ta.$data"),this.inputEl.attr("ta-toolbar",this.attrs.eTaToolbar||'[["bold","italics","underline","strikeThrough","ul","ol","undo","redo","clear"]]'),t(function(){this.inputEl.find("textarea").hide()}.bind(this),0)},save:function(){this.scope.$data=this.scope.ta.$data,this.parent.save.call(this)},setLocalValue:function(){this.parent.setLocalValue.call(this),this.scope.ta.$data=this.scope.$data}}),n=r.link,r.link=function(e,t,r,i){return e.ta={},n(e,t,r,i)},r}]}),define("common/modules/xeditable-civi",["common/angular","common/decorators/xeditable-civi/editable-directive-factory","common/directives/xeditable-civi/editable-ta","common/angularXeditable","common/text-angular"],function(e,t,n){"use strict";return e.module("xeditable-civi",["xeditable","textAngular"]).directive("editableTa",n)}); +this.date(a.getUTCDate()),this}function Ut(e){return null==e?Math.ceil((this.month()+1)/3):this.month(3*(e-1)+this.month()%3)}function Ht(e){return me(e,this._week.dow,this._week.doy).week}function qt(){return this._week.dow}function Vt(){return this._week.doy}function zt(e){var t=this.localeData().week(this);return null==e?t:this.add(7*(e-t),"d")}function Bt(e){var t=me(this,1,4).week;return null==e?t:this.add(7*(e-t),"d")}function Yt(e,t){return"string"!=typeof e?e:isNaN(e)?(e=t.weekdaysParse(e),"number"==typeof e?e:null):parseInt(e,10)}function Wt(e,n){return t(this._weekdays)?this._weekdays[e.day()]:this._weekdays[this._weekdays.isFormat.test(n)?"format":"standalone"][e.day()]}function Gt(e){return this._weekdaysShort[e.day()]}function Kt(e){return this._weekdaysMin[e.day()]}function Zt(e,t,n){var r,i,o;for(this._weekdaysParse||(this._weekdaysParse=[],this._minWeekdaysParse=[],this._shortWeekdaysParse=[],this._fullWeekdaysParse=[]),r=0;7>r;r++){if(i=Te([2e3,1]).day(r),n&&!this._fullWeekdaysParse[r]&&(this._fullWeekdaysParse[r]=new RegExp("^"+this.weekdays(i,"").replace(".",".?")+"$","i"),this._shortWeekdaysParse[r]=new RegExp("^"+this.weekdaysShort(i,"").replace(".",".?")+"$","i"),this._minWeekdaysParse[r]=new RegExp("^"+this.weekdaysMin(i,"").replace(".",".?")+"$","i")),this._weekdaysParse[r]||(o="^"+this.weekdays(i,"")+"|^"+this.weekdaysShort(i,"")+"|^"+this.weekdaysMin(i,""),this._weekdaysParse[r]=new RegExp(o.replace(".",""),"i")),n&&"dddd"===t&&this._fullWeekdaysParse[r].test(e))return r;if(n&&"ddd"===t&&this._shortWeekdaysParse[r].test(e))return r;if(n&&"dd"===t&&this._minWeekdaysParse[r].test(e))return r;if(!n&&this._weekdaysParse[r].test(e))return r}}function Jt(e){if(!this.isValid())return null!=e?this:NaN;var t=this._isUTC?this._d.getUTCDay():this._d.getDay();return null!=e?(e=Yt(e,this.localeData()),this.add(e-t,"d")):t}function Qt(e){if(!this.isValid())return null!=e?this:NaN;var t=(this.day()+7-this.localeData()._week.dow)%7;return null==e?t:this.add(e-t,"d")}function Xt(e){return this.isValid()?null==e?this.day()||7:this.day(this.day()%7?e:e-7):null!=e?this:NaN}function en(e){var t=Math.round((this.clone().startOf("day")-this.clone().startOf("year"))/864e5)+1;return null==e?t:this.add(e-t,"d")}function tn(){return this.hours()%12||12}function nn(e,t){R(e,0,0,function(){return this.localeData().meridiem(this.hours(),this.minutes(),t)})}function rn(e,t){return t._meridiemParse}function on(e){return"p"===(e+"").toLowerCase().charAt(0)}function an(e,t,n){return e>11?n?"pm":"PM":n?"am":"AM"}function sn(e,t){t[_r]=g(1e3*("0."+e))}function ln(){return this._isUTC?"UTC":""}function un(){return this._isUTC?"Coordinated Universal Time":""}function cn(e){return Te(1e3*e)}function fn(){return Te.apply(null,arguments).parseZone()}function dn(e,t,n){var r=this._calendar[e];return M(r)?r.call(t,n):r}function pn(e){var t=this._longDateFormat[e],n=this._longDateFormat[e.toUpperCase()];return t||!n?t:(this._longDateFormat[e]=n.replace(/MMMM|MM|DD|dddd/g,function(e){return e.slice(1)}),this._longDateFormat[e])}function hn(){return this._invalidDate}function mn(e){return this._ordinal.replace("%d",e)}function gn(e){return e}function vn(e,t,n,r){var i=this._relativeTime[n];return M(i)?i(e,t,n,r):i.replace(/%d/i,e)}function yn(e,t){var n=this._relativeTime[e>0?"future":"past"];return M(n)?n(t):n.replace(/%s/i,t)}function bn(e){var t,n;for(n in e)t=e[n],M(t)?this[n]=t:this["_"+n]=t;this._ordinalParseLenient=new RegExp(this._ordinalParse.source+"|"+/\d{1,2}/.source)}function $n(e,t,n,r){var i=k(),o=a().set(r,t);return i[n](o,e)}function wn(e,t,n,r,i){if("number"==typeof e&&(t=e,e=void 0),e=e||"",null!=t)return $n(e,t,n,i);var o,a=[];for(o=0;r>o;o++)a[o]=$n(e,o,n,i);return a}function xn(e,t){return wn(e,t,"months",12,"month")}function Cn(e,t){return wn(e,t,"monthsShort",12,"month")}function kn(e,t){return wn(e,t,"weekdays",7,"day")}function En(e,t){return wn(e,t,"weekdaysShort",7,"day")}function Sn(e,t){return wn(e,t,"weekdaysMin",7,"day")}function _n(){var e=this._data;return this._milliseconds=gi(this._milliseconds),this._days=gi(this._days),this._months=gi(this._months),e.milliseconds=gi(e.milliseconds),e.seconds=gi(e.seconds),e.minutes=gi(e.minutes),e.hours=gi(e.hours),e.months=gi(e.months),e.years=gi(e.years),this}function Mn(e,t,n,r){var i=Ze(t,n);return e._milliseconds+=r*i._milliseconds,e._days+=r*i._days,e._months+=r*i._months,e._bubble()}function Tn(e,t){return Mn(this,e,t,1)}function Dn(e,t){return Mn(this,e,t,-1)}function An(e){return 0>e?Math.floor(e):Math.ceil(e)}function On(){var e,t,n,r,i,o=this._milliseconds,a=this._days,s=this._months,l=this._data;return o>=0&&a>=0&&s>=0||0>=o&&0>=a&&0>=s||(o+=864e5*An(Rn(s)+a),a=0,s=0),l.milliseconds=o%1e3,e=m(o/1e3),l.seconds=e%60,t=m(e/60),l.minutes=t%60,n=m(t/60),l.hours=n%24,a+=m(n/24),i=m(Nn(a)),s+=i,a-=An(Rn(i)),r=m(s/12),s%=12,l.days=a,l.months=s,l.years=r,this}function Nn(e){return 4800*e/146097}function Rn(e){return 146097*e/4800}function In(e){var t,n,r=this._milliseconds;if("month"===(e=S(e))||"year"===e)return t=this._days+r/864e5,n=this._months+Nn(t),"month"===e?n:n/12;switch(t=this._days+Math.round(Rn(this._months)),e){case"week":return t/7+r/6048e5;case"day":return t+r/864e5;case"hour":return 24*t+r/36e5;case"minute":return 1440*t+r/6e4;case"second":return 86400*t+r/1e3;case"millisecond":return Math.floor(864e5*t)+r;default:throw new Error("Unknown unit "+e)}}function Pn(){return this._milliseconds+864e5*this._days+this._months%12*2592e6+31536e6*g(this._months/12)}function Fn(e){return function(){return this.as(e)}}function jn(e){return e=S(e),this[e+"s"]()}function Ln(e){return function(){return this._data[e]}}function Un(){return m(this.days()/7)}function Hn(e,t,n,r,i){return i.relativeTime(t||1,!!n,e,r)}function qn(e,t,n){var r=Ze(e).abs(),i=Oi(r.as("s")),o=Oi(r.as("m")),a=Oi(r.as("h")),s=Oi(r.as("d")),l=Oi(r.as("M")),u=Oi(r.as("y")),c=i=o&&["m"]||o=a&&["h"]||a=s&&["d"]||s=l&&["M"]||l=u&&["y"]||["yy",u];return c[2]=t,c[3]=+e>0,c[4]=n,Hn.apply(null,c)}function Vn(e,t){return void 0!==Ni[e]&&(void 0===t?Ni[e]:(Ni[e]=t,!0))}function zn(e){var t=this.localeData(),n=qn(this,!e,t);return e&&(n=t.pastFuture(+this,n)),t.postformat(n)}function Bn(){var e,t,n,r=Ri(this._milliseconds)/1e3,i=Ri(this._days),o=Ri(this._months);e=m(r/60),t=m(e/60),r%=60,e%=60,n=m(o/12),o%=12;var a=n,s=o,l=i,u=t,c=e,f=r,d=this.asSeconds();return d?(0>d?"-":"")+"P"+(a?a+"Y":"")+(s?s+"M":"")+(l?l+"D":"")+(u||c||f?"T":"")+(u?u+"H":"")+(c?c+"M":"")+(f?f+"S":""):"P0D"}var Yn,Wn,Gn=e.momentProperties=[],Kn=!1,Zn={},Jn={},Qn=/(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,Xn=/(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g,er={},tr={},nr=/\d/,rr=/\d\d/,ir=/\d{3}/,or=/\d{4}/,ar=/[+-]?\d{6}/,sr=/\d\d?/,lr=/\d\d\d\d?/,ur=/\d\d\d\d\d\d?/,cr=/\d{1,3}/,fr=/\d{1,4}/,dr=/[+-]?\d{1,6}/,pr=/\d+/,hr=/[+-]?\d+/,mr=/Z|[+-]\d\d:?\d\d/gi,gr=/Z|[+-]\d\d(?::?\d\d)?/gi,vr=/[+-]?\d+(\.\d{1,3})?/,yr=/[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i,br={},$r={},wr=0,xr=1,Cr=2,kr=3,Er=4,Sr=5,_r=6,Mr=7,Tr=8;R("M",["MM",2],"Mo",function(){return this.month()+1}),R("MMM",0,0,function(e){return this.localeData().monthsShort(this,e)}),R("MMMM",0,0,function(e){return this.localeData().months(this,e)}),E("month","M"),L("M",sr),L("MM",sr,rr),L("MMM",function(e,t){return t.monthsShortRegex(e)}),L("MMMM",function(e,t){return t.monthsRegex(e)}),V(["M","MM"],function(e,t){t[xr]=g(e)-1}),V(["MMM","MMMM"],function(e,t,n,r){var i=n._locale.monthsParse(e,r,n._strict);null!=i?t[xr]=i:l(n).invalidMonth=e});var Dr=/D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?/,Ar="January_February_March_April_May_June_July_August_September_October_November_December".split("_"),Or="Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),Nr=yr,Rr=yr,Ir={};e.suppressDeprecationWarnings=!1;var Pr=/^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/,Fr=/^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/,jr=/Z|[+-]\d\d(?::?\d\d)?/,Lr=[["YYYYYY-MM-DD",/[+-]\d{6}-\d\d-\d\d/],["YYYY-MM-DD",/\d{4}-\d\d-\d\d/],["GGGG-[W]WW-E",/\d{4}-W\d\d-\d/],["GGGG-[W]WW",/\d{4}-W\d\d/,!1],["YYYY-DDD",/\d{4}-\d{3}/],["YYYY-MM",/\d{4}-\d\d/,!1],["YYYYYYMMDD",/[+-]\d{10}/],["YYYYMMDD",/\d{8}/],["GGGG[W]WWE",/\d{4}W\d{3}/],["GGGG[W]WW",/\d{4}W\d{2}/,!1],["YYYYDDD",/\d{7}/]],Ur=[["HH:mm:ss.SSSS",/\d\d:\d\d:\d\d\.\d+/],["HH:mm:ss,SSSS",/\d\d:\d\d:\d\d,\d+/],["HH:mm:ss",/\d\d:\d\d:\d\d/],["HH:mm",/\d\d:\d\d/],["HHmmss.SSSS",/\d\d\d\d\d\d\.\d+/],["HHmmss,SSSS",/\d\d\d\d\d\d,\d+/],["HHmmss",/\d\d\d\d\d\d/],["HHmm",/\d\d\d\d/],["HH",/\d\d/]],Hr=/^\/?Date\((\-?\d+)/i;e.createFromInputFallback=ie("moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to https://github.com/moment/moment/issues/1407 for more info.",function(e){e._d=new Date(e._i+(e._useUTC?" UTC":""))}),R("Y",0,0,function(){var e=this.year();return 9999>=e?""+e:"+"+e}),R(0,["YY",2],0,function(){return this.year()%100}),R(0,["YYYY",4],0,"year"),R(0,["YYYYY",5],0,"year"),R(0,["YYYYYY",6,!0],0,"year"),E("year","y"),L("Y",hr),L("YY",sr,rr),L("YYYY",fr,or),L("YYYYY",dr,ar),L("YYYYYY",dr,ar),V(["YYYYY","YYYYYY"],wr),V("YYYY",function(t,n){n[wr]=2===t.length?e.parseTwoDigitYear(t):g(t)}),V("YY",function(t,n){n[wr]=e.parseTwoDigitYear(t)}),V("Y",function(e,t){t[wr]=parseInt(e,10)}),e.parseTwoDigitYear=function(e){return g(e)+(g(e)>68?1900:2e3)};var qr=T("FullYear",!1);e.ISO_8601=function(){};var Vr=ie("moment().min is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548",function(){var e=Te.apply(null,arguments);return this.isValid()&&e.isValid()?this>e?this:e:c()}),zr=ie("moment().max is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548",function(){var e=Te.apply(null,arguments);return this.isValid()&&e.isValid()?e>this?this:e:c()}),Br=function(){return Date.now?Date.now():+new Date};Ie("Z",":"),Ie("ZZ",""),L("Z",gr),L("ZZ",gr),V(["Z","ZZ"],function(e,t,n){n._useUTC=!0,n._tzm=Pe(gr,e)});var Yr=/([\+\-]|\d\d)/gi;e.updateOffset=function(){};var Wr=/(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/,Gr=/^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/;Ze.fn=Ne.prototype;var Kr=et(1,"add"),Zr=et(-1,"subtract");e.defaultFormat="YYYY-MM-DDTHH:mm:ssZ";var Jr=ie("moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.",function(e){return void 0===e?this.localeData():this.locale(e)});R(0,["gg",2],0,function(){return this.weekYear()%100}),R(0,["GG",2],0,function(){return this.isoWeekYear()%100}),Nt("gggg","weekYear"),Nt("ggggg","weekYear"),Nt("GGGG","isoWeekYear"),Nt("GGGGG","isoWeekYear"),E("weekYear","gg"),E("isoWeekYear","GG"),L("G",hr),L("g",hr),L("GG",sr,rr),L("gg",sr,rr),L("GGGG",fr,or),L("gggg",fr,or),L("GGGGG",dr,ar),L("ggggg",dr,ar),z(["gggg","ggggg","GGGG","GGGGG"],function(e,t,n,r){t[r.substr(0,2)]=g(e)}),z(["gg","GG"],function(t,n,r,i){n[i]=e.parseTwoDigitYear(t)}),R("Q",0,"Qo","quarter"),E("quarter","Q"),L("Q",nr),V("Q",function(e,t){t[xr]=3*(g(e)-1)}),R("w",["ww",2],"wo","week"),R("W",["WW",2],"Wo","isoWeek"),E("week","w"),E("isoWeek","W"),L("w",sr),L("ww",sr,rr),L("W",sr),L("WW",sr,rr),z(["w","ww","W","WW"],function(e,t,n,r){t[r.substr(0,1)]=g(e)});var Qr={dow:0,doy:6};R("D",["DD",2],"Do","date"),E("date","D"),L("D",sr),L("DD",sr,rr),L("Do",function(e,t){return e?t._ordinalParse:t._ordinalParseLenient}),V(["D","DD"],Cr),V("Do",function(e,t){t[Cr]=g(e.match(sr)[0],10)});var Xr=T("Date",!0);R("d",0,"do","day"),R("dd",0,0,function(e){return this.localeData().weekdaysMin(this,e)}),R("ddd",0,0,function(e){return this.localeData().weekdaysShort(this,e)}),R("dddd",0,0,function(e){return this.localeData().weekdays(this,e)}),R("e",0,0,"weekday"),R("E",0,0,"isoWeekday"),E("day","d"),E("weekday","e"),E("isoWeekday","E"),L("d",sr),L("e",sr),L("E",sr),L("dd",yr),L("ddd",yr),L("dddd",yr),z(["dd","ddd","dddd"],function(e,t,n,r){var i=n._locale.weekdaysParse(e,r,n._strict);null!=i?t.d=i:l(n).invalidWeekday=e}),z(["d","e","E"],function(e,t,n,r){t[r]=g(e)});var ei="Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),ti="Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),ni="Su_Mo_Tu_We_Th_Fr_Sa".split("_");R("DDD",["DDDD",3],"DDDo","dayOfYear"),E("dayOfYear","DDD"),L("DDD",cr),L("DDDD",ir),V(["DDD","DDDD"],function(e,t,n){n._dayOfYear=g(e)}),R("H",["HH",2],0,"hour"),R("h",["hh",2],0,tn),R("hmm",0,0,function(){return""+tn.apply(this)+N(this.minutes(),2)}),R("hmmss",0,0,function(){return""+tn.apply(this)+N(this.minutes(),2)+N(this.seconds(),2)}),R("Hmm",0,0,function(){return""+this.hours()+N(this.minutes(),2)}),R("Hmmss",0,0,function(){return""+this.hours()+N(this.minutes(),2)+N(this.seconds(),2)}),nn("a",!0),nn("A",!1),E("hour","h"),L("a",rn),L("A",rn),L("H",sr),L("h",sr),L("HH",sr,rr),L("hh",sr,rr),L("hmm",lr),L("hmmss",ur),L("Hmm",lr),L("Hmmss",ur),V(["H","HH"],kr),V(["a","A"],function(e,t,n){n._isPm=n._locale.isPM(e),n._meridiem=e}),V(["h","hh"],function(e,t,n){t[kr]=g(e),l(n).bigHour=!0}),V("hmm",function(e,t,n){var r=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r)),l(n).bigHour=!0}),V("hmmss",function(e,t,n){var r=e.length-4,i=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r,2)),t[Sr]=g(e.substr(i)),l(n).bigHour=!0}),V("Hmm",function(e,t,n){var r=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r))}),V("Hmmss",function(e,t,n){var r=e.length-4,i=e.length-2;t[kr]=g(e.substr(0,r)),t[Er]=g(e.substr(r,2)),t[Sr]=g(e.substr(i))});var ri=/[ap]\.?m?\.?/i,ii=T("Hours",!0);R("m",["mm",2],0,"minute"),E("minute","m"),L("m",sr),L("mm",sr,rr),V(["m","mm"],Er);var oi=T("Minutes",!1);R("s",["ss",2],0,"second"),E("second","s"),L("s",sr),L("ss",sr,rr),V(["s","ss"],Sr);var ai=T("Seconds",!1);R("S",0,0,function(){return~~(this.millisecond()/100)}),R(0,["SS",2],0,function(){return~~(this.millisecond()/10)}),R(0,["SSS",3],0,"millisecond"),R(0,["SSSS",4],0,function(){return 10*this.millisecond()}),R(0,["SSSSS",5],0,function(){return 100*this.millisecond()}),R(0,["SSSSSS",6],0,function(){return 1e3*this.millisecond()}),R(0,["SSSSSSS",7],0,function(){return 1e4*this.millisecond()}),R(0,["SSSSSSSS",8],0,function(){return 1e5*this.millisecond()}),R(0,["SSSSSSSSS",9],0,function(){return 1e6*this.millisecond()}),E("millisecond","ms"),L("S",cr,nr),L("SS",cr,rr),L("SSS",cr,ir);var si;for(si="SSSS";si.length<=9;si+="S")L(si,pr);for(si="S";si.length<=9;si+="S")V(si,sn);var li=T("Milliseconds",!1);R("z",0,0,"zoneAbbr"),R("zz",0,0,"zoneName");var ui=p.prototype;ui.add=Kr,ui.calendar=nt,ui.clone=rt,ui.diff=ct,ui.endOf=xt,ui.format=ht,ui.from=mt,ui.fromNow=gt,ui.to=vt,ui.toNow=yt,ui.get=O,ui.invalidAt=At,ui.isAfter=it,ui.isBefore=ot,ui.isBetween=at,ui.isSame=st,ui.isSameOrAfter=lt,ui.isSameOrBefore=ut,ui.isValid=Tt,ui.lang=Jr,ui.locale=bt,ui.localeData=$t,ui.max=zr,ui.min=Vr,ui.parsingFlags=Dt,ui.set=O,ui.startOf=wt,ui.subtract=Zr,ui.toArray=St,ui.toObject=_t,ui.toDate=Et,ui.toISOString=pt,ui.toJSON=Mt,ui.toString=dt,ui.unix=kt,ui.valueOf=Ct,ui.creationData=Ot,ui.year=qr,ui.isLeapYear=de,ui.weekYear=Rt,ui.isoWeekYear=It,ui.quarter=ui.quarters=Ut,ui.month=J,ui.daysInMonth=Q,ui.week=ui.weeks=zt,ui.isoWeek=ui.isoWeeks=Bt,ui.weeksInYear=Ft,ui.isoWeeksInYear=Pt,ui.date=Xr,ui.day=ui.days=Jt,ui.weekday=Qt,ui.isoWeekday=Xt,ui.dayOfYear=en,ui.hour=ui.hours=ii,ui.minute=ui.minutes=oi,ui.second=ui.seconds=ai,ui.millisecond=ui.milliseconds=li,ui.utcOffset=Le,ui.utc=He,ui.local=qe,ui.parseZone=Ve,ui.hasAlignedHourOffset=ze,ui.isDST=Be,ui.isDSTShifted=Ye,ui.isLocal=We,ui.isUtcOffset=Ge,ui.isUtc=Ke,ui.isUTC=Ke,ui.zoneAbbr=ln,ui.zoneName=un,ui.dates=ie("dates accessor is deprecated. Use date instead.",Xr),ui.months=ie("months accessor is deprecated. Use month instead",J),ui.years=ie("years accessor is deprecated. Use year instead",qr),ui.zone=ie("moment().zone is deprecated, use moment().utcOffset instead. https://github.com/moment/moment/issues/1779",Ue);var ci=ui,fi={sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"},di={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},pi=/\d{1,2}/,hi={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},mi=y.prototype;mi._calendar=fi,mi.calendar=dn,mi._longDateFormat=di,mi.longDateFormat=pn,mi._invalidDate="Invalid date",mi.invalidDate=hn,mi._ordinal="%d",mi.ordinal=mn,mi._ordinalParse=pi,mi.preparse=gn,mi.postformat=gn,mi._relativeTime=hi,mi.relativeTime=vn,mi.pastFuture=yn,mi.set=bn,mi.months=W,mi._months=Ar,mi.monthsShort=G,mi._monthsShort=Or,mi.monthsParse=K,mi._monthsRegex=Rr,mi.monthsRegex=ee,mi._monthsShortRegex=Nr,mi.monthsShortRegex=X,mi.week=Ht,mi._week=Qr,mi.firstDayOfYear=Vt,mi.firstDayOfWeek=qt,mi.weekdays=Wt,mi._weekdays=ei,mi.weekdaysMin=Kt,mi._weekdaysMin=ni,mi.weekdaysShort=Gt,mi._weekdaysShort=ti,mi.weekdaysParse=Zt,mi.isPM=on,mi._meridiemParse=ri,mi.meridiem=an,x("en",{ordinalParse:/\d{1,2}(th|st|nd|rd)/,ordinal:function(e){var t=e%10;return e+(1===g(e%100/10)?"th":1===t?"st":2===t?"nd":3===t?"rd":"th")}}),e.lang=ie("moment.lang is deprecated. Use moment.locale instead.",x),e.langData=ie("moment.langData is deprecated. Use moment.localeData instead.",k);var gi=Math.abs,vi=Fn("ms"),yi=Fn("s"),bi=Fn("m"),$i=Fn("h"),wi=Fn("d"),xi=Fn("w"),Ci=Fn("M"),ki=Fn("y"),Ei=Ln("milliseconds"),Si=Ln("seconds"),_i=Ln("minutes"),Mi=Ln("hours"),Ti=Ln("days"),Di=Ln("months"),Ai=Ln("years"),Oi=Math.round,Ni={s:45,m:45,h:22,d:26,M:11},Ri=Math.abs,Ii=Ne.prototype;return Ii.abs=_n,Ii.add=Tn,Ii.subtract=Dn,Ii.as=In,Ii.asMilliseconds=vi,Ii.asSeconds=yi,Ii.asMinutes=bi,Ii.asHours=$i,Ii.asDays=wi,Ii.asWeeks=xi,Ii.asMonths=Ci,Ii.asYears=ki,Ii.valueOf=Pn,Ii._bubble=On,Ii.get=jn,Ii.milliseconds=Ei,Ii.seconds=Si,Ii.minutes=_i,Ii.hours=Mi,Ii.days=Ti,Ii.weeks=Un,Ii.months=Di,Ii.years=Ai,Ii.humanize=zn,Ii.toISOString=Bn,Ii.toString=Bn,Ii.toJSON=Bn,Ii.locale=bt,Ii.localeData=$t,Ii.toIsoString=ie("toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)",Bn),Ii.lang=Jr,R("X",0,0,"unix"),R("x",0,0,"valueOf"),L("x",hr),L("X",vr),V("X",function(e,t,n){n._d=new Date(1e3*parseFloat(e,10))}),V("x",function(e,t,n){n._d=new Date(g(e))}),e.version="2.11.1",function(e){Yn=e}(Te),e.fn=ci,e.min=Ae,e.max=Oe,e.now=Br,e.utc=a,e.unix=cn,e.months=xn,e.isDate=n,e.locale=x,e.invalid=c,e.duration=Ze,e.isMoment=h,e.weekdays=kn,e.parseZone=fn,e.localeData=k,e.isDuration=Re,e.monthsShort=Cn,e.weekdaysMin=Sn,e.defineLocale=C,e.weekdaysShort=En,e.normalizeUnits=S,e.relativeTimeThreshold=Vn,e.prototype=ci,e}),define("common/bundles/vendors",["common/require","common/angular","common/angularAnimate","common/angularBootstrap","common/angular-file-upload","common/angularMocks","common/angularResource","common/angularRoute","common/angularXeditable","common/text-angular","common/ui-select","common/d3","common/lodash","common/moment"],function(){}),define("common/modules/apis",["common/angular"],function(e){"use strict";return e.module("common.apis",[])}),define("common/services/api",["common/angular","common/lodash","common/modules/apis"],function(e,t,n){"use strict";n.factory("api",["$cacheFactory","$log","$http","$httpParamSerializer","$q","$timeout",function(n,r,i,o,a,s){function l(e){return e.data.is_error?(r.error(e.data),a.reject(e.data.error_message)):e.data}function u(e){var n={options:{limit:0}};return JSON.stringify(t.merge(n,e||{}))}r.debug("api");return{extend:function(t){return e.extend(Object.create(this),t)},getAll:function(e,n,i,o,s,l,u){return r.debug("api.all"),n=n||{},l=l||"get",a.all([function(){var r=t.assign({},n,s||{},{options:t.assign({},n.options,{sort:o||"id DESC"})});return i&&(r.options.offset=(i.page-1)*i.size,r.options.limit=i.size),this.sendGET(e,l,r,u)}.bind(this)(),function(){if(!i)return a.resolve();var r=t.assign({},n,{return:"id"});return r=t.omit(r,function(e,n){return t.startsWith(n,"api.")}),this.sendGET(e,l,r,u)}.bind(this)()]).then(function(e){var n=e[0],r=i?e[1]:n;return{list:n.values,total:r.count,allIds:t.compact(r.values.map(function(e){return e.id})).join(",")}})},mockGET:function(e,t){var n=a.defer();return s(function(){n.resolve(e)},t||0),n.promise},mockPOST:function(e,t){return this.mockGET.apply(this,arguments)},sendGET:function(e,t,r,a){var s={action:t,entity:e,json:u(r),sequential:1};return!1===a&&n.get("$http").remove("/civicrm/ajax/rest?"+o(s)),i({method:"GET",url:"/civicrm/ajax/rest",cache:!0,responseType:"json",params:s}).then(l)},sendPOST:function(e,t,n){return r.debug("api.sendPOST"),i({method:"POST",url:"/civicrm/ajax/rest",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},responseType:"json",data:{json:u(n),sequential:1,entity:e,action:t},transformRequest:o}).then(l)}}}])}),define("common/services/api/appraisal",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.appraisal",["$log","api",function(e,t){return e.debug("api.appraisal"),t.extend({all:function(t,n,r){return e.debug("api.appraisal.api"),this.getAll("Appraisal",t,n,r)},create:function(t){return e.debug("api.appraisal.create"),this.sendPOST("Appraisal","create",t).then(function(e){return e.values[0]})},find:function(t){return e.debug("api.appraisal.find"),this.sendGET("Appraisal","get",{id:""+t},!1).then(function(e){return e.values[0]})}})}])}),define("common/services/api/option-group",["common/lodash","common/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("api.optionGroup",["$log","api",function(t,n){function r(t){return t.values.map(function(t){var n=e.clone(t);return n.option_group_name=n["option_group_id.name"],delete n["option_group_id.name"],n})}function i(t){return e.transform(t,function(e,t){var n=t.option_group_name;e[n]=e[n]||[],e[n].push(t)})}return t.debug("api.optionGroup"),n.extend({valuesOf:function(t,n){var o=e.isArray(t);return this.sendGET("OptionValue","get",{"option_group_id.name":{IN:o?t:[t]},is_active:"1",return:["option_group_id.name","option_group_id","id","name","label","value","weight","is_active","is_reserved"]},n).then(r).then(function(e){return o?i(e):e})}})}])}),define("common/services/api/appraisal-cycle",["common/lodash","common/modules/apis","common/services/api","common/services/api/option-group"],function(e,t){"use strict";t.factory("api.appraisal-cycle",["$q","$log","api","api.optionGroup",function(t,n,r,i){return n.debug("api.appraisal-cycle"),r.extend({all:function(e,t,r){return n.debug("api.appraisal-cycle.all"),this.getAll("AppraisalCycle",e,t,r,{"api.AppraisalCycle.getappraisalsperstep":{}})},create:function(t){return n.debug("api.appraisal-cycle.create"),this.sendPOST("AppraisalCycle","create",e.assign(t,{"api.AppraisalCycle.getappraisalsperstep":{}})).then(function(e){return e.values[0]})},find:function(e){n.debug("api.appraisal-cycle.find");var t={id:""+e,"api.AppraisalCycle.getappraisalsperstep":{}};return this.sendGET("AppraisalCycle","get",t,!1).then(function(e){return e.values[0]})},grades:function(){return n.debug("grades"),this.mockGET([{label:1,value:17},{label:2,value:74},{label:3,value:90},{label:4,value:30}])},statuses:function(){return n.debug("api.appraisal-cycle.statuses"),i.valuesOf("appraisal_status")},statusOverview:function(e){return n.debug("api.appraisal-cycle.statusOverview"),this.sendGET("AppraisalCycle","getstatusoverview",e).then(function(e){return e.values})},update:function(t){return n.debug("api.appraisal-cycle.update"),this.sendPOST("AppraisalCycle","create",e.assign(t,{"api.AppraisalCycle.getappraisalsperstep":{}})).then(function(e){return e.values[0]})},total:function(e){return n.debug("api.appraisal-cycle.total"),this.sendGET("AppraisalCycle","getcount",e||{}).then(function(e){return e.result})},types:function(){return n.debug("api.appraisal-cycle.types"),i.valuesOf("appraisal_cycle_type")}})}])}),define("common/services/api/contact-job-role-api.api",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("ContactJobRoleAPI",["$log","api",function(e,t){return e.debug("ContactJobRoleAPI"),t.extend({all:function(t,n,r,i){return e.debug("ContactJobRoleAPI.all()"),this.getAll("ContactHrJobRoles",t,n,r,i)}})}])}),define("common/bundles/apis",["common/services/api/appraisal","common/services/api/appraisal-cycle","common/services/api/contact-job-role-api.api","common/services/api/option-group"],function(){}),define("common/modules/services",["common/angular","common/angular-file-upload"],function(e){"use strict";return e.module("common.services",["angularFileUpload"])}),define("common/services/before-hash-query-params.service",["common/lodash","common/modules/services"],function(e,t){"use strict";t.factory("beforeHashQueryParams",["$log","$window",function(t,n){function r(e){var t=e||n.location.href,r=o(t);return-1===r.indexOf("?")?{}:i(a(r))}function i(t){return t.length?e.transform(t,function(e,t){var n=t.split("=");n[0]&&(e[n[0]]=n[1]?decodeURI(n[1]):null)},{}):{}}function o(e){var t=e.indexOf("#");return e.substring(0,-1!==t?t:e.length)}function a(e){var t=e.indexOf("?");return e.substr(t+1).split("&")}return t.debug("Service: beforeHashQueryParams"),{parse:r}}])}),function(e){define("common/services/check-permissions",["common/lodash","common/modules/services"],function(t,n){"use strict";n.factory("checkPermissions",["$q",function(n){return function(r){return r=t.isArray(r)?r:[r],n.resolve(r.every(function(t){return e.checkPerm(t)}))}}])})}(CRM),function(e){define("common/services/crm-ang.service",["common/lodash","common/modules/services"],function(t,n){"use strict";function r(t,n){return e.loadForm(t,n)}n.factory("crmAngService",function(){return{loadForm:r}})})}(CRM),define("common/services/detect-device.service",["common/modules/services"],function(e){"use strict";e.factory("detectDevice",[function(){return{isMobile:function(){return document.getElementsByTagName("body")[0].classList.contains("mobile")}}}])}),define("common/services/dom-event-trigger",["common/modules/services"],function(e){"use strict";!function(t){e.factory("DOMEventTrigger",function(){return function(e,n){t(document).trigger(e,n)}})}(CRM.$)}),define("common/services/file-mime-types",["common/lodash","common/modules/services"],function(e,t){"use strict";t.factory("fileMimeTypes",["$q",function(e){var t={txt:"plain",png:"png",jpeg:"jpeg",bmp:"bmp",gif:"gif",pdf:"pdf",doc:"msword",docx:"vnd.openxmlformats-officedocument.wordprocessingml.document",xls:"vnd.ms-excel",xlsx:"vnd.openxmlformats-officedocument.spreadsheetml.sheet",ppt:"vnd.ms-powerpoint",pptx:"vnd.openxmlformats-officedocument.presentationml.presentation"};return{getMimeTypeFor:function(n){return e.resolve(t[n])}}}])}),define("common/services/file-upload",["common/modules/services","common/lodash","common/angular-file-upload"],function(e,t){"use strict";e.factory("FileUpload",["$q","$log","FileUploader",function(e,n,r){function i(e){throw new Error(e+" missing from parameter")}function o(e,t,r,i){n.error(" ===== Item Error: "+r+" ======"),n.error(" ===== - item ======"),n.error(e),n.error(" ===== - response ======"),n.error(t),n.error(" ===== - headers ======"),n.error(i)}function a(e){return t.defaults(e,{allowedMimeTypes:{txt:"plain",png:"png",jpeg:"jpeg",bmp:"bmp",gif:"gif",pdf:"pdf"},url:"/civicrm/ajax/attachment",queueLimit:1})}return{uploader:function(n){var s,l,u,c=[];return n?(n=a(n),s=new r({url:n.url,queueLimit:+n.queueLimit,onCompleteItem:function(e,t){c.push(t)},onCompleteAll:function(){u.resolve(c)},onErrorItem:function(e){o.apply(null,arguments),u.reject("Could not upload file: "+e.file.name)},formData:[{entity_table:n.entityTable||i("entityTable"),crm_attachment_token:n.crmAttachmentToken||i("crmAttachmentToken")}],filters:[{name:"fileFormatFilter",fn:function(e){var r=e.type.slice(e.type.lastIndexOf("/")+1);return t.includes(t.values(n.allowedMimeTypes),r)}}]}),s.uploadAll=function(){return l=s.uploadAll,function(n){return u=e.defer(),s.onBeforeUploadItem=function(e){t.each(n,function(n,r){var i={};i[t.snakeCase(r)]=n,e.formData.push(i)})},l.apply(s),u.promise}}(),s):i("custom settings")}}}])}),define("common/services/file.service",["common/modules/services"],function(e){"use strict";e.factory("fileService",["$http","$window","$log",function(e,t,n){return n.debug("Service: fileService"),{openFile:function(n){return e.get(n.url,{responseType:"arraybuffer"}).success(function(e){var r=new Blob([e],{type:n.fileType});t.navigator.msSaveOrOpenBlob?t.navigator.msSaveOrOpenBlob(r,n.name):t.open(URL.createObjectURL(r),"_blank")})}}}])}),define("common/services/hr-settings",["common/modules/services"],function(e){"use strict";e.factory("HR_settings",function(){return{DATE_FORMAT:null}})}),function(e){define("common/services/notification.service",["common/lodash","common/modules/services"],function(t,n){"use strict";n.factory("notificationService",function(){return t(["alert","success","info","error"]).map(function(t){return[t,function(n,r,i){return e.alert(r,n,t,i)}]}).zipObject().value()})})}(CRM),define("common/services/pub-sub",["common/modules/services"],function(e){"use strict";var t=Object.create(null);e.factory("pubSub",["$rootScope",function(e){return{subscribe:function(n,r){var i;return t[n]=t[n]||[],r.$rootScope=e,i=t[n].push(r)-1,{remove:function(){delete t[n][i]}}},publish:function(e,n){t[e]&&(n=void 0!=n?n:{},t[e].forEach(function(e){e.$rootScope.$applyAsync(function(){e(n)})}))}}}])}),define("common/bundles/services",["common/services/before-hash-query-params.service","common/services/check-permissions","common/services/crm-ang.service","common/services/detect-device.service","common/services/dom-event-trigger","common/services/file-mime-types","common/services/file-upload","common/services/file.service","common/services/hr-settings","common/services/notification.service","common/services/pub-sub"],function(){}),define("common/modules/components",["common/angular"],function(e){return e.module("common.components",[])}),define("common/components/heatmap.component",["common/lodash","common/moment","common/modules/components"],function(e,t,n){function r(){function n(e){e.values&&(u(),l(),c())}function r(){return Object.values(d.values).filter(function(e){return!1!==e})}function i(e,t){return e.reduce(function(e,n){return Math.abs(n.value-t)');r(n,t),e.after(n)}function r(e,n){function r(){n.isOpen=!0,n.$apply()}t.isMobile()||(e.on("click",r),n.$on("$destroy",function(){e.off("click",r)}))}var i=e[0],o=i.compile;return i.compile=function(){var e=o.apply(this,arguments);return function(t,i,o){e.apply(this,arguments),n(i,t),r(i,t)}},e}]}),define("common/decorators/uib-datepicker-mobile-version.decorator",["common/moment","common/services/detect-device.service"],function(e){"use strict";return["$delegate","detectDevice",function(t,n){function r(t){return t?e(t).format("Y-MM-DD"):""}var i=t[0],o=i.compile;return i.require=["ngModel","uibDatepickerPopup"],i.compile=function(){var e=o.apply(this,arguments);return function(t,i,o,a){n.isMobile()?(i.prop("type","date"),o.ngReadonly=!1,a[0].$formatters.push(function(e){return r(e)}),t.$watch("datepickerOptions.minDate",function(e){o.$set("min",r(e))}),t.$watch("datepickerOptions.maxDate",function(e){o.$set("max",r(e))})):e.apply(this,arguments)}},t}]}),define("common/decorators/xeditable-disable-calendar-icon.decorator",[],function(){"use strict";return["$delegate",function(e){var t=e[0],n=t.compile;return t.compile=function(){var e=n.apply(this,arguments);return function(t,n,r){e.apply(this,arguments),r.eShowCalendarButton=!1}},e}]}),define("common/decorators/ui-bootstrap/uib-tabset",[],function(){"use strict";return["$delegate",function(e){return e[0].bindToController.customHeaderClass="@",e}]}),define("common/decorators/ui-bootstrap/uib-modal.decorator",["common/angular"],function(e){"use strict";return["$delegate","$document",function(t,n){function r(){var t,r=[{item:e.element(n[0].body),styles:[{name:"overflow",old:null,new:"hidden"},{name:"height",old:null,new:"100%"},{name:"width",old:null,new:"100%"}]},{item:e.element(n[0].getElementsByTagName("html")[0]),styles:[{name:"overflow",old:null,new:"hidden"},{name:"height",old:null,new:"100%"},{name:"width",old:null,new:"100%"}]}];return r.forEach(function(e){e.styles.forEach(function(t){t.old=e.item.css(t.name),e.item.css(t.name,t.new)})}),t=i.apply(this,arguments),t.closed.then(function(){r.forEach(function(e){e.styles.forEach(function(t){e.item.css(t.name,t.old)})})}),t}var i=t.open;return t.open=r,t}]}),define("common/modules/templates",["common/angular"],function(e){"use strict";return e.module("common.templates",[]).run(["$templateCache",function(e){e.put("dialog.html",'\n\n\n'),e.put("help-text.html",'\n'),e.put("loading.html",'
    \n
    \n
    \n
    \n'),e.put("time-amount-picker.html",'
    \n
    \n \n \n
    \n h\n
    \n \n \n
    \n m\n
    \n'),e.put("timepicker-select.html",'\n\n'),e.put("civihr-ui-select/choices.tpl.html",'
      \n
    • \n
      \n
        \n
      • \n
        \n
      • \n
      \n
    • \n
    \n'),e.put("civihr-ui-select/match-multiple.tpl.html",'\n
  • \n \n \n
  • \n\n'),e.put("civihr-ui-select/match.tpl.html",'\n {{$select.contactList ? \'-select-\' : $select.placeholder}}\n \n \n \n\n'),e.put("civihr-ui-select/select-contacts-multiple.tpl.html",'
    \n
    \n
      \n \n
    • \n \n
    • \n
    \n\n \n\n \n
    \n
    \n'),e.put("civihr-ui-select/select-contacts.tpl.html",'
    \n
    \n \n
    \n'),e.put("civihr-ui-select/select-multiple.tpl.html",'
    \n
    \n
      \n \n
    • \n \n
    • \n
    \n \n
    \n
    \n'),e.put("civihr-ui-select/select.tpl.html",'
    \n
    \n \n
    \n'),e.put("components/heatmap.html",'
      \n
    • \n {{day.name.short}}\n
    • \n
    \n'),e.put("contact-actions/contact-actions.html",'
    \n \n \n
    \n'),e.put("contact-actions/modals/form.html",'
    \n \n \n \n
    \n')}])}),define("common/modules/controllers",["common/angular","common/angularBootstrap","common/modules/apis"],function(e){"use strict";return e.module("common.controllers",["ui.bootstrap","common.apis"])}),define("common/modules/directives",["common/angular","common/decorators/ui-select-focus.decorator","common/decorators/uib-datepicker-calendar-icon.decorator","common/decorators/uib-datepicker-mobile-version.decorator","common/decorators/xeditable-disable-calendar-icon.decorator","common/decorators/ui-bootstrap/uib-tabset","common/decorators/ui-bootstrap/uib-modal.decorator","common/angularBootstrap","common/angularXeditable","common/ui-select","common/modules/templates","common/modules/controllers","common/modules/services","common/modules/apis"],function(e,t,n,r,i,o,a){"use strict";return e.module("common.directives",["common.templates","common.controllers","ui.select","ui.bootstrap","xeditable"]).config(["$provide",function(e){e.decorator("uibDatepickerPopupDirective",r),e.decorator("uibDatepickerPopupDirective",n),e.decorator("uibTabsetDirective",o),e.decorator("$uibModal",a),e.decorator("editableBsdateDirective",i),e.decorator("uiSelectDirective",t)}]).run(["$templateCache",function(e){var t="uib/template/tabs/tabset.html",n=jQuery(e.get(t));n.find("ul").addClass("{{tabset.customHeaderClass}}"),e.put(t,n.wrap("
    ").parent().html())}])}),define("common/services/api/contact-actions",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.contactActions",["$q","api",function(e,t){function n(e,n){return t.sendGET(e,"getoptions",{field:n,context:"search"}).then(function(e){return e.values})}function r(e){return t.sendGET("UFField","get",{uf_group_id:e,is_active:!0}).then(function(e){return e.values})}function i(n,r){return e(function(e,i){if(r.contact_type=n,r.email)return t.sendGET("CustomField","get",{return:["id"],custom_group_id:"Emergency_Contacts",name:"email"}).then(function(t){r["custom_"+t.id]=r.email,delete r.email,e()});e()}).then(function(){return t.sendPOST("Contact","create",r).then(function(e){return e.values[0]})})}return t.extend({getOptions:{forContactType:function(){return n.call(this,"Contact","contact_type")},forGroup:function(){return n.call(this,"GroupContact","group_id")},forTag:function(){return n.call(this,"EntityTag","tag_id")},forStateProvince:function(){return n.call(this,"Address","state_province_id")},forCountry:function(){return n.call(this,"Address","country_id")},forGender:function(){return n.call(this,"Contact","gender_id")},forDeceased:function(){return n.call(this,"Contact","is_deceased")}},save:{newIndividual:function(e){return i.call(this,"Individual",e)},newOrganization:function(e){return i.call(this,"Organization",e)},newHousehold:function(e){return i.call(this,"Household",e)}},getFormFields:{forNewIndividual:function(){return r.call(this,"new_individual")},forNewOrganization:function(){return r.call(this,"new_organization")},forNewHousehold:function(){return r.call(this,"new_household")}}})}])}),define("common/controllers/contact-actions/modal-ctrl",[],function(){"use strict";return function(e,t){this.errorMsg="",this.loading=!0,this.formFields=[],this.init=function(e){e().then(function(e){this.loading=!1,this.formFields=e}.bind(this)).catch(function(){this.loading=!1,this.errorMsg="Error while loading form fields"}.bind(this))},this.cancel=function(){t.dismiss("cancel")},this.save=function(n,r){this.loading=!0,n(this.formFields.reduce(function(e,t){return e[t.field_name]=t.value,e},{})).then(function(n){this.loading=!1,e.$broadcast(r,n),t.dismiss("cancel")}.bind(this)).catch(function(){this.loading=!1,this.errorMsg="Error while saving data"}.bind(this))}}}),define("common/controllers/contact-actions/new-individual-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Individual",i.init(r.getFormFields.forNewIndividual),i.submit=function(){i.save(r.save.newIndividual,"newIndividualCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewIndividualModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/new-household-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Household",i.init(r.getFormFields.forNewHousehold),i.submit=function(){i.save(r.save.newHousehold,"newHouseholdCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewHouseholdModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/new-organization-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Organization",i.init(r.getFormFields.forNewOrganization),i.submit=function(){i.save(r.save.newOrganization,"newOrganizationCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewOrganizationModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/contact-actions-ctrl",["common/modules/controllers","common/services/api/contact-actions","common/controllers/contact-actions/new-individual-ctrl","common/controllers/contact-actions/new-household-ctrl","common/controllers/contact-actions/new-organization-ctrl"],function(e){"use strict";e.controller("ContactActionsCtrl",["$scope","$rootElement","$uibModal","api.contactActions",function(e,t,n,r){var i=this;e.$watch(function(){return i.refineSearch.selected},function(t,n){t!==n&&e.$emit("contactRefineSearch",{field:t.field?t.field.label:null,option:t.option?t.option.value:null})},!0),i.refineSearch={selected:{field:null,option:null},availableFields:[{label:"Contact Type",getOptions:r.getOptions.forContactType},{label:"Group",getOptions:r.getOptions.forGroup},{label:"Tag",getOptions:r.getOptions.forTag},{label:"State / Province",getOptions:r.getOptions.forStateProvince},{label:"Country",getOptions:r.getOptions.forCountry},{label:"Gender",getOptions:r.getOptions.forGender},{label:"Deceased",getOptions:r.getOptions.forDeceased}],availableOptions:{refresh:function(){i.refineSearch.selected.field?(this.options=null,i.refineSearch.selected.field.getOptions().then(function(e){this.options=e}.bind(this))):this.options=[]},options:[]}},i.showNewIndividualModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewIndividualModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})},i.showNewHouseholdModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewHouseholdModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})},i.showNewOrganizationModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewOrganizationModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})}}])}),define("common/directives/prevent-animations",["common/modules/directives"],function(e){"use strict";e.directive("preventAnimations",["$animate",function(e){return{restrict:"A",link:function(t,n,r){e.enabled(n,!1)}}}])}),define("common/directives/loading",["common/modules/directives","common/directives/prevent-animations"],function(e){"use strict";e.directive("crmLoading",["$templateCache",function(e){return{scope:{show:"="},restrict:"E",replace:!0,transclude:!0,template:e.get("loading.html")}}])}),define("common/directives/contact-actions/contact-actions",["common/modules/directives","common/controllers/contact-actions/contact-actions-ctrl","common/directives/loading"],function(e){"use strict";e.directive("contactActions",[function(){return{restrict:"E",templateUrl:"contact-actions/contact-actions.html",controller:"ContactActionsCtrl",controllerAs:"$ctrl",link:function(e,t,n){e.$ctrl.refineSearchVisible=t.parent().parent()[0].hasAttribute("refine-search")}}}])}),define("common/directives/help-text.directive",["common/lodash","common/moment","common/modules/directives","common/services/notification.service"],function(e,t,n){function r(e,t){function n(){var n=e.getHelpText();t.info(e.title||r,n)}var r="Help";this.displayHelpText=n}function i(e,t,n){function r(){return t.find(".help-text").html()}e.getHelpText=r}n.directive("helpText",["$templateCache",function(e){return{restrict:"E",scope:{title:"@?"},transclude:!0,controller:r,controllerAs:"helpText",template:e.get("help-text.html"),link:i}}]),r.$inject=["$scope","notificationService"]}),define("common/directives/scroll-shadows.directive",["common/angular","common/modules/directives"],function(e,t){"use strict";function n(t,n,r){function i(){u(),a(),l(),s()}function o(){var e=f.width(),t=p+"__shadows--show-left",n=p+"__shadows--show-right",r=d.scrollLeft(),i=d.width();if(e<=i)return void d.removeClass(t+" "+n);d[r>0?"addClass":"removeClass"](t),d[r
    ').parent(),d=f.wrap('
    ').parent(),d.wrap('
    ')}var f,d,p="chr_scroll-shadows";!function(){c(),i(),o()}()}t.directive("scrollShadows",[function(){return{restrict:"A",controller:n}}]),n.$inject=["$element","$scope","$window"]}),define("common/directives/timepicker-select.directive",["common/moment","common/modules/directives"],function(e,t){"use strict";function n(t){function n(){var n=+t.timepickerSelectInterval||1,i=e.duration(t.timepickerSelectTimeFrom||"00:00"),o=e.duration(t.timepickerSelectTimeTo||"23:59");for(r.options=[];i.asMinutes()<=o.asMinutes();){var a=e.utc(i.asMilliseconds());r.options.push(a.format("HH:mm")),i.add(n,"minutes")}}var r=this;r.placeholder=t.timepickerSelectPlaceholder,r.options=[],t.$watchGroup(["timepickerSelectTimeFrom","timepickerSelectTimeTo","timepickerSelectInterval"],function(){n()})}t.directive("timepickerSelect",["$templateCache",function(e){return{scope:{timepickerSelectPlaceholder:"@",timepickerSelectTimeFrom:"<",timepickerSelectTimeTo:"<",timepickerSelectInterval:"<"},restrict:"A",controllerAs:"selector",controller:["$scope",n],template:e.get("timepicker-select.html")}}]),n.$inject=["$scope"]}),define("common/directives/time-amount-picker.directive",["common/lodash","common/modules/directives"],function(e,t){"use strict";function n(t){function n(){var e=Math.floor(c);for(d.hoursOptions=[];e<=f;)d.hoursOptions.push(e),e++}function r(){var e,t,n,r=0;for(d.minutesOptions=[];r<60;)t=+d.selectedHours===Math.floor(c)&&rf%1*60,e=t||n,!e&&d.minutesOptions.push(r),r+=u;l()}function i(){u=+t.interval||1,c=isNaN(+t.minAmount)?0:+t.minAmount,f=isNaN(+t.maxAmount)?24:+t.maxAmount,n(),r()}function o(){""!==d.selectedHours&&""!==d.selectedMinutes&&(t.value=+d.selectedHours+d.selectedMinutes/60)}function a(){t.$watch("disabled",function(e){d.disabled=e}),t.$watch("value",function(){s()}),t.$watchGroup(["minAmount","maxAmount","interval"],function(){i()})}function s(){void 0!==t.value&&(d.selectedHours=""+Math.floor(t.value),d.selectedMinutes=""+Math.floor(t.value%1*60)),o()}function l(){d.selectedMinutese.last(d.minutesOptions)&&(d.selectedMinutes=""+e.last(d.minutesOptions))}var u,c,f,d=this;d.hoursOptions=[],d.minutesOptions=[],d.selectedHours="",d.selectedMinutes="",d.buildMinutesOptions=r,d.calculateSelectedValue=o,function(){s(),a()}()}t.directive("timeAmountPicker",["$templateCache",function(e){return{scope:{minAmount:".75?Math.floor(.25*Math.ceil(e/.25))+"h":"",n=e%1&&e%1<=.75&&e%1>0?.25*Math.ceil(e%1/.25)*60+"m":"",r+t+(t&&n?" ":"")+n)}};return function(t,n){var r=void 0===t?0:parseFloat(t);if(isNaN(r))throw new Error("Value must be a number or a numeric string: "+t);return e[n](r)}})}),define("common/bundles/filters",["common/filters/time-unit-applier.filter"],function(){}),define("common/decorators/angular-date/datepicker-popup",["common/lodash"],function(e){return["$delegate","HR_settings",function(t,n){"use strict";var r=t[0].link;return t[0].compile=function(){return function(t,i,o,a){o.uibDatepickerPopup=o.uibDatepickerPopup||n.DATE_FORMAT||"yyyy-MM-dd",o.showButtonBar=o.showButtonBar||!1,t.datepickerOptions=e.assign({formatDayHeader:"E",showWeeks:!1, +startingDay:1},t.datepickerOptions),r.apply(this,arguments)}},t}]}),define("common/decorators/angular-date/date-filter",[],function(){"use strict";return["$delegate",function(e){var t=e;return function(){if("E"===arguments[1]){var e=Array.prototype.slice.call(arguments);return e[1]="EEE",t.apply(this,e)[0]}return t.apply(this,arguments)}}]}),function(e){define("common/modules/angular-date",["common/angular","common/decorators/angular-date/datepicker-popup","common/decorators/angular-date/date-filter","common/modules/services","common/angularBootstrap","common/modules/templates"],function(t,n,r){"use strict";function i(t){var n="uib/template/datepicker/"+t+".html",r=o.get(n);r=r.replace(/glyphicon glyphicon-chevron-(left|right)/gm,"fa fa-chevron-$1"),"day"===t&&(r=function(t){return e(t).find('th[ng-if="showWeeks"]').parent().css({"border-top":"1px solid #DDD"}),e(t).prop("outerHTML")}(e.parseHTML(r))),o.put(n,r)}var o;return t.module("common.angularDate",["common.services","ui.bootstrap","common.templates"]).config(["$provide",function(e){e.decorator("uibDatepickerPopupDirective",n),e.decorator("dateFilter",r)}]).run(["$templateCache",function(e){o=e,["day","month","year"].forEach(i)}])})}(CRM.$),define("common/services/angular-date/date-format",["common/angular","common/modules/angular-date","common/services/hr-settings"],function(e,t){"use strict";t.factory("DateFormat",["$q","HR_settings",function(e,t){return{dateFormat:null,getDateFormat:function(){return this.dateFormat?e.when(this.dateFormat):e.when("dd/MM/yyyy").catch(function(){return"yyyy-MM-dd"}).then(function(e){return t.DATE_FORMAT=e,this.dateFormat=e,e}.bind(this))}}}])}),define("common/filters/angular-date/format-date",["common/moment","common/modules/angular-date","common/services/hr-settings"],function(e,t){"use strict";t.filter("formatDate",["HR_settings",function(t){var n=["DD-MM-YYYY","DD-MM-YYYY HH:mm:ss","YYYY-MM-DD","YYYY-MM-DD HH:mm:ss","DD/MM/YYYY","x","YYYY-MM-DD HH:mm:ss"];return function(r,i,o){var a,s=i||t.DATE_FORMAT||"YYYY-MM-DD",l=e(0);return r instanceof Date&&(r=e(r).format("YYYY-MM-DD HH:mm:ss")),a=e(r,n,!0),a.isValid()&&!a.isSame(l)?i===Date?a.toDate():a.format(s.toUpperCase())+("hours"===o?" "+a.format("HH:mm"):""):"Unspecified"}}])}),define("common/directives/angular-date/date-input",["common/modules/angular-date","common/filters/angular-date/format-date"],function(e){"use strict";e.directive("dateInput",["$filter",function(e){return{require:"ngModel",link:function(t,n,r,i){function o(t){var n=e("formatDate")(t);return n="Unspecified"==n?"":n}i.$formatters.push(o),i.$parsers=[]}}}])}),define("common/bundles/angular-date",["common/services/angular-date/date-format","common/filters/angular-date/format-date","common/directives/angular-date/date-input"],function(){}),define("common/modules/routers/compu-ng-route",["common/angular","common/angularRoute"],function(e){"use strict";return e.module("compuNgRoute",["ngRoute"]).config(["$routeProvider",function(t){var n=t.when;t.resolveForAll=function(e){return t.commonResolve=e,t},t.when=function(r,i){return e.extend(i.resolve||{},t.commonResolve||{}),n.call(t,r,i)}}])}),"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function r(e,t){return L(new(L(function(){},{prototype:e})),t)}function i(e){return j(arguments,function(t){t!==e&&j(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var r in e.path){if(e.path[r]!==t.path[r])break;n.push(e.path[r])}return n}function a(e){if(Object.keys)return Object.keys(e);var t=[];return j(e,function(e,n){t.push(n)}),t}function s(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,r=Number(arguments[2])||0;for(0>(r=0>r?Math.ceil(r):Math.floor(r))&&(r+=n);n>r;r++)if(r in e&&e[r]===t)return r;return-1}function l(e,t,n,r){var i,l=o(n,r),u={},c=[];for(var f in l)if(l[f].params&&(i=a(l[f].params),i.length))for(var d in i)s(c,i[d])>=0||(c.push(i[d]),u[i[d]]=e[i[d]]);return L({},u,t)}function u(e,t,n){if(!n){n=[];for(var r in e)n.push(r)}for(var i=0;i "));if(y[n]=r,I(e))g.push(n,[function(){return t.get(e)}],u);else{var i=t.annotate(e);j(i,function(e){e!==n&&l.hasOwnProperty(e)&&p(l[e],e)}),g.push(n,e,i)}v.pop(),y[n]=o}}function h(e){return P(e)&&e.then&&e.$$promises}if(!P(l))throw new Error("'invocables' must be an object");var m=a(l||{}),g=[],v=[],y={};return j(l,p),l=v=y=null,function(r,o,a){function s(){--b||($||i(y,o.$$values),p.$$values=y,p.$$promises=p.$$promises||!0,delete p.$$inheritedValues,u.resolve(y))}function l(e){p.$$failure=e,u.reject(e)}if(h(r)&&a===n&&(a=o,o=r,r=null),r){if(!P(r))throw new Error("'locals' must be an object")}else r=c;if(o){if(!h(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=f;var u=e.defer(),p=u.promise,v=p.$$promises={},y=L({},r),b=1+g.length/3,$=!1;if(N(o.$$failure))return l(o.$$failure),p;o.$$inheritedValues&&i(y,d(o.$$inheritedValues,m)),L(v,o.$$promises),o.$$values?($=i(y,d(o.$$values,m)),p.$$inheritedValues=d(o.$$values,m),s()):(o.$$inheritedValues&&(p.$$inheritedValues=d(o.$$inheritedValues,m)),o.then(s,l));for(var w=0,x=g.length;x>w;w+=3)r.hasOwnProperty(g[w])?s():function(n,i,o){function u(e){f.reject(e),l(e)}function c(){if(!N(p.$$failure))try{f.resolve(t.invoke(i,a,y)),f.promise.then(function(e){y[n]=e,s()},u)}catch(e){u(e)}}var f=e.defer(),d=0;j(o,function(e){v.hasOwnProperty(e)&&!r.hasOwnProperty(e)&&(d++,v[e].then(function(t){y[e]=t,--d||c()},u))}),d||c(),v[n]=f.promise}(g[w],g[w+1],g[w+2]);return p}},this.resolve=function(e,t,n,r){return this.study(e)(t,n,r)}}function g(e,t,n){this.fromConfig=function(e,t,n){return N(e.template)?this.fromString(e.template,t):N(e.templateUrl)?this.fromUrl(e.templateUrl,t):N(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return R(e)?e(t):e},this.fromUrl=function(n,r){return R(n)&&(n=n(r)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,r){return n.invoke(e,null,r||{params:t})}}function v(e,t,i){function o(t,n,r,i){if(g.push(t),h[t])return h[t];if(!/^\w+(-+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(m[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return m[t]=new H.Param(t,n,r,i),m[t]}function a(e,t,n,r){var i=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:i=["(",")"+(r?"?":"")];break;case!0:i=["?(",")?"];break;default:i=["("+n+"|",")?"]}return o+i[0]+t+i[1]}function s(i,o){var a,s,l,u,c;return a=i[2]||i[3],c=t.params[a],l=e.substring(d,i.index),s=o?i[4]:i[4]||("*"==i[1]?".*":null),u=H.type(s||"string")||r(H.type("string"),{pattern:new RegExp(s,t.caseInsensitive?"i":n)}),{id:a,regexp:s,segment:l,type:u,cfg:c}}t=L({params:{}},P(t)?t:{});var l,u=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,c=/([:]?)([\w\[\]-]+)|\{([\w\[\]-]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,f="^",d=0,p=this.segments=[],h=i?i.params:{},m=this.params=i?i.params.$$new():new H.ParamSet,g=[];this.source=e;for(var v,y,b;(l=u.exec(e))&&(v=s(l,!1),!(v.segment.indexOf("?")>=0));)y=o(v.id,v.type,v.cfg,"path"),f+=a(v.segment,y.type.pattern.source,y.squash,y.isOptional),p.push(v.segment),d=u.lastIndex;b=e.substring(d);var $=b.indexOf("?");if($>=0){var w=this.sourceSearch=b.substring($);if(b=b.substring(0,$),this.sourcePath=e.substring(0,d+$),w.length>0)for(d=0;l=c.exec(w);)v=s(l,!0),y=o(v.id,v.type,v.cfg,"search"),d=u.lastIndex}else this.sourcePath=e,this.sourceSearch="";f+=a(b)+(!1===t.strict?"/?":"")+"$",p.push(b),this.regexp=new RegExp(f,t.caseInsensitive?"i":n),this.prefix=p[0],this.$$paramNames=g}function y(e){L(this,e)}function b(){function e(e){return null!=e?e.toString().replace(/\//g,"%2F"):e}function i(e){return null!=e?e.toString().replace(/%2F/g,"/"):e}function o(){return{strict:m,caseInsensitive:d}}function l(e){return R(e)||F(e)&&R(e[e.length-1])}function u(){for(;x.length;){var e=x.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend($[e.name],f.invoke(e.def))}}function c(e){L(this,e||{})}H=this;var f,d=!1,m=!0,g=!1,$={},w=!0,x=[],C={string:{encode:e,decode:i,is:function(e){return null==e||!N(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return N(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};b.$$getDefaultValue=function(e){if(!l(e.value))return e.value;if(!f)throw new Error("Injectable functions cannot be called at configuration time");return f.invoke(e.value)},this.caseInsensitive=function(e){return N(e)&&(d=e),d},this.strictMode=function(e){return N(e)&&(m=e),m},this.defaultSquashPolicy=function(e){if(!N(e))return g;if(!0!==e&&!1!==e&&!I(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return g=e,e},this.compile=function(e,t){return new v(e,L(o(),t))},this.isMatcher=function(e){if(!P(e))return!1;var t=!0;return j(v.prototype,function(n,r){R(n)&&(t=t&&N(e[r])&&R(e[r]))}),t},this.type=function(e,t,n){if(!N(t))return $[e];if($.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return $[e]=new y(L({name:e},t)),n&&(x.push({name:e,def:n}),w||u()),this},j(C,function(e,t){$[t]=new y(L({name:t},e))}),$=r($,{}),this.$get=["$injector",function(e){return f=e,w=!1,u(),j(C,function(e,t){$[t]||($[t]=new y(e))}),this}],this.Param=function(e,t,r,i){function o(){if(!f)throw new Error("Injectable functions cannot be called at configuration time");var e=f.invoke(r.$$fn);if(null!==e&&e!==n&&!d.type.is(e))throw new Error("Default value ("+e+") for parameter '"+d.id+"' is not an instance of Type ("+d.type.name+")");return e}function u(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=h(p(d.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),N(e)?d.type.$normalize(e):o()}function c(){return"{Param:"+e+" "+t+" squash: '"+b+"' optional: "+v+"}"}var d=this;r=function(e){var t=P(e)?a(e):[];return-1===s(t,"value")&&-1===s(t,"type")&&-1===s(t,"squash")&&-1===s(t,"array")&&(e={value:e}),e.$$fn=l(e.value)?e.value:function(){return e.value},e}(r),t=function(t,n,r){if(t.type&&n)throw new Error("Param '"+e+"' has two type configurations.");return n||(t.type?t.type instanceof y?t.type:new y(t.type):"config"===r?$.any:$.string)}(r,t,i);var m=function(){var t={array:"search"===i&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return L(t,n,r).array}();t=m?t.$asArray(m,"search"===i):t,"string"!==t.name||m||"path"!==i||r.value!==n||(r.value="");var v=r.value!==n,b=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!N(n)||null==n)return g;if(!0===n||I(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,v),w=function(e,t,r,i){var o,a,l=[{from:"",to:r||t?n:""},{from:null,to:r||t?n:""}];return o=F(e.replace)?e.replace:[],I(i)&&o.push({from:i,to:n}),a=h(o,function(e){return e.from}),p(l,function(e){return-1===s(a,e.from)}).concat(o)}(r,m,v,b);L(this,{id:e,type:t,location:i,array:m,squash:b,replace:w,isOptional:v,value:u,dynamic:n,config:r,toString:c})},c.prototype={$$new:function(){return r(this,L(new c,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,r=a(c.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),j(t,function(t){j(a(t),function(t){-1===s(e,t)&&-1===s(r,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return j(n.$$keys(),function(r){t[r]=n[r].value(e&&e[r])}),t},$$equals:function(e,t){var n=!0,r=this;return j(r.$$keys(),function(i){var o=e&&e[i],a=t&&t[i];r[i].type.equals(o,a)||(n=!1)}),n},$$validates:function(e){var r,i,o,a,s,l=this.$$keys();for(r=0;ri;i++)if(t(u[i]))return;c&&t(c)}}function p(){return l=l||i.$on("$locationChangeSuccess",d)}var h,m=a.baseHref(),g=r.url();return f||p(),{sync:function(){d()},listen:function(){return p()},update:function(e){return e?void(g=r.url()):void(r.url()!==g&&(r.url(g),r.replace()))},push:function(e,t,i){var o=e.format(t||{});null!==o&&t&&t["#"]&&(o+="#"+t["#"]),r.url(o),h=i&&i.$$avoidResync?r.url():n,i&&i.replace&&r.replace()},href:function(n,i,o){if(!n.validates(i))return null;var a=e.html5Mode();t.isObject(a)&&(a=a.enabled);var l=n.format(i);if(o=o||{},a||null===l||(l="#"+e.hashPrefix()+l),null!==l&&i&&i["#"]&&(l+="#"+i["#"]),l=s(l,a,o.absolute),!o.absolute||!l)return l;var u=!a&&l?"/":"",c=r.port();return c=80===c||443===c?"":":"+c,[r.protocol(),"://",r.host(),c,u,l].join("")}}}var l,u=[],c=null,f=!1;this.rule=function(e){if(!R(e))throw new Error("'rule' must be a function");return u.push(e),this},this.otherwise=function(e){if(I(e)){var t=e;e=function(){return t}}else if(!R(e))throw new Error("'rule' must be a function");return c=e,this},this.when=function(e,t){var n,s=I(t);if(I(e)&&(e=r.compile(e)),!s&&!R(t)&&!F(t))throw new Error("invalid 'handler' in when()");var l={matcher:function(e,t){return s&&(n=r.compile(t),t=["$match",function(e){return n.format(e)}]),L(function(n,r){return a(n,t,e.exec(r.path(),r.search()))},{prefix:I(e.prefix)?e.prefix:""})},regex:function(e,t){if(e.global||e.sticky)throw new Error("when() RegExp must not be global or sticky");return s&&(n=t,t=["$match",function(e){return o(n,e)}]),L(function(n,r){return a(n,t,e.exec(r.path()))},{prefix:i(e)})}},u={matcher:r.isMatcher(e),regex:e instanceof RegExp};for(var c in u)if(u[c])return this.rule(l[c](e,t));throw new Error("invalid 'what' in when()")},this.deferIntercept=function(e){e===n&&(e=!0),f=e},this.$get=s,s.$inject=["$location","$rootScope","$injector","$browser"]}function w(e,i){function o(e){return 0===e.indexOf(".")||0===e.indexOf("^")}function d(e,t){if(!e)return n;var r=I(e),i=r?e:e.name;if(o(i)){if(!t)throw new Error("No reference point given for path '"+i+"'");t=d(t);for(var a=i.split("."),s=0,l=a.length,u=t;l>s;s++)if(""!==a[s]||0!==s){if("^"!==a[s])break;if(!u.parent)throw new Error("Path '"+i+"' not valid for state '"+t.name+"'");u=u.parent}else u=t;a=a.slice(s).join("."),i=u.name+(u.name&&a?".":"")+a}var c=E[i];return!c||!r&&(r||c!==e&&c.self!==e)?n:c}function p(e,t){S[e]||(S[e]=[]),S[e].push(t)}function m(e){for(var t=S[e]||[];t.length;)g(t.shift())}function g(t){t=r(t,{self:t,resolve:t.resolve||{},toString:function(){return this.name}});var n=t.name;if(!I(n)||n.indexOf("@")>=0)throw new Error("State must have a valid name");if(E.hasOwnProperty(n))throw new Error("State '"+n+"'' is already defined");var i=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):I(t.parent)?t.parent:P(t.parent)&&I(t.parent.name)?t.parent.name:"";if(i&&!E[i])return p(i,t.self);for(var o in M)R(M[o])&&(t[o]=M[o](t,M.$delegates[o]));return E[n]=t,!t[_]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){k.$current.navigable==t&&u(e,n)||k.transitionTo(t,e,{inherit:!0,location:!1})}]),m(n),t}function v(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=k.$current.name.split("."),r=0,i=t.length;i>r;r++)"*"===t[r]&&(n[r]="*");return"**"===t[0]&&(n=n.slice(s(n,t[1])),n.unshift("**")),"**"===t[t.length-1]&&(n.splice(s(n,t[t.length-2])+1,Number.MAX_VALUE),n.push("**")),t.length==n.length&&n.join("")===t.join("")}function b(e,t){return I(e)&&!N(t)?M[e]:R(t)&&I(e)?(M[e]&&!M.$delegates[e]&&(M.$delegates[e]=M[e]),M[e]=t,this):this}function $(e,t){return P(e)?t=e:t.name=e,g(t),this}function w(e,i,o,s,f,p,m,g,b){function $(t,n,r,o){var a=e.$broadcast("$stateNotFound",t,n,r);if(a.defaultPrevented)return m.update(),T;if(!a.retry)return null;if(o.$retry)return m.update(),D;var s=k.transition=i.when(a.retry);return s.then(function(){return s!==k.transition?S:(t.options.$retry=!0,k.transitionTo(t.to,t.toParams,t.options))},function(){return T}),m.update(),s}function w(e,n,r,a,l,u){function d(){var n=[];return j(e.views,function(r,i){var a=r.resolve&&r.resolve!==e.resolve?r.resolve:{};a.$template=[function(){return o.load(i,{view:r,locals:l.globals,params:p,notify:u.notify})||""}],n.push(f.resolve(a,l.globals,l.resolve,e).then(function(n){if(R(r.controllerProvider)||F(r.controllerProvider)){var o=t.extend({},a,l.globals);n.$$controller=s.invoke(r.controllerProvider,null,o)}else n.$$controller=r.controller;n.$$state=e,n.$$controllerAs=r.controllerAs,l[i]=n}))}),i.all(n).then(function(){return l.globals})}var p=r?n:c(e.params.$$keys(),n),h={$stateParams:p};l.resolve=f.resolve(e.resolve,h,l.resolve,e);var m=[l.resolve.then(function(e){l.globals=e})];return a&&m.push(a),i.all(m).then(d).then(function(e){return l})}var S=i.reject(new Error("transition superseded")),M=i.reject(new Error("transition prevented")),T=i.reject(new Error("transition aborted")),D=i.reject(new Error("transition failed"));return C.locals={resolve:null,globals:{$stateParams:{}}},k={params:{},current:C.self,$current:C,transition:null},k.reload=function(e){return k.transitionTo(k.current,p,{reload:e||!0,inherit:!1,notify:!0})},k.go=function(e,t,n){return k.transitionTo(e,t,L({inherit:!0,relative:k.$current},n))},k.transitionTo=function(t,n,o){n=n||{},o=L({location:!0,inherit:!1,relative:null,notify:!0,reload:!1,$retry:!1},o||{});var a,u=k.$current,f=k.params,h=u.path,g=d(t,o.relative),v=n["#"];if(!N(g)){var y={to:t,toParams:n,options:o},b=$(y,u.self,f,o);if(b)return b;if(t=y.to,n=y.toParams,o=y.options,g=d(t,o.relative),!N(g)){if(!o.relative)throw new Error("No such state '"+t+"'");throw new Error("Could not resolve '"+t+"' from state '"+o.relative+"'")}}if(g[_])throw new Error("Cannot transition to abstract state '"+t+"'");if(o.inherit&&(n=l(p,n||{},k.$current,g)),!g.params.$$validates(n))return D;n=g.params.$$values(n),t=g;var E=t.path,T=0,A=E[T],O=C.locals,R=[];if(o.reload){if(I(o.reload)||P(o.reload)){if(P(o.reload)&&!o.reload.name)throw new Error("Invalid reload state object");var F=!0===o.reload?h[0]:d(o.reload);if(o.reload&&!F)throw new Error("No such reload state '"+(I(o.reload)?o.reload:o.reload.name)+"'");for(;A&&A===h[T]&&A!==F;)O=R[T]=A.locals,T++,A=E[T]}}else for(;A&&A===h[T]&&A.ownParams.$$equals(n,f);)O=R[T]=A.locals,T++,A=E[T];if(x(t,n,u,f,O,o))return v&&(n["#"]=v),k.params=n,U(k.params,p),o.location&&t.navigable&&t.navigable.url&&(m.push(t.navigable.url,n,{$$avoidResync:!0,replace:"replace"===o.location}),m.update(!0)),k.transition=null,i.when(k.current);if(n=c(t.params.$$keys(),n||{}),o.notify&&e.$broadcast("$stateChangeStart",t.self,n,u.self,f).defaultPrevented)return e.$broadcast("$stateChangeCancel",t.self,n,u.self,f),m.update(),M;for(var j=i.when(O),H=T;H=T;r--)a=h[r],a.self.onExit&&s.invoke(a.self.onExit,a.self,a.locals.globals),a.locals=null;for(r=T;r=0?i:i+"@"+(o?o.state.name:"")}function _(e,t){var n,r=e.match(/^\s*({[^}]*})\s*$/);if(r&&(e=t+"("+r[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function M(e){var t=e.parent().inheritedData("$uiView");return t&&t.state&&t.state.name?t.state:void 0}function T(e,n){var r=["location","inherit","reload","absolute"];return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(i,o,a,s){var l=_(a.uiSref,e.current.name),u=null,c=M(o)||e.$current,f="[object SVGAnimatedString]"===Object.prototype.toString.call(o.prop("href"))?"xlink:href":"href",d=null,p="A"===o.prop("tagName").toUpperCase(),h="FORM"===o[0].nodeName,m=h?"action":f,g=!0,v={relative:c,inherit:!0},y=i.$eval(a.uiSrefOpts)||{};t.forEach(r,function(e){e in y&&(v[e]=y[e])});var b=function(n){if(n&&(u=t.copy(n)),g){d=e.href(l.state,u,v);var r=s[1]||s[0];return r&&r.$$addStateInfo(l.state,u),null===d?(g=!1,!1):void a.$set(m,d)}};l.paramExpr&&(i.$watch(l.paramExpr,function(e,t){e!==u&&b(e)},!0),u=t.copy(i.$eval(l.paramExpr))),b(),h||o.bind("click",function(t){if(!((t.which||t.button)>1||t.ctrlKey||t.metaKey||t.shiftKey||o.attr("target"))){var r=n(function(){e.go(l.state,u,v)});t.preventDefault();var i=p&&!d?1:0;t.preventDefault=function(){i--<=0&&n.cancel(r)}}})}}}function D(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs",function(t,r,i){function o(){a()?r.addClass(l):r.removeClass(l)}function a(){for(var e=0;er;r++){o=a[r];var c=this.params[o],f=n[r+1];for(i=0;ir;r++)o=a[r],u[o]=this.params[o].value(t[o]);return u},v.prototype.parameters=function(e){return N(e)?this.params[e]||null:this.$$paramNames},v.prototype.validates=function(e){return this.params.$$validates(e)},v.prototype.format=function(e){function t(e){return encodeURIComponent(e).replace(/-/g,function(e){return"%5C%"+e.charCodeAt(0).toString(16).toUpperCase()})}e=e||{};var n=this.segments,r=this.parameters(),i=this.params;if(!this.validates(e))return null;var o,a=!1,s=n.length-1,l=r.length,u=n[0];for(o=0;l>o;o++){var c=s>o,f=r[o],d=i[f],p=d.value(e[f]),m=d.isOptional&&d.type.equals(d.value(),p),g=!!m&&d.squash,v=d.type.encode(p);if(c){var y=n[o+1];if(!1===g)null!=v&&(u+=F(v)?h(v,t).join("-"):encodeURIComponent(v)),u+=y;else if(!0===g){var b=u.match(/\/$/)?/\/?(.*)/:/(.*)/;u+=y.match(b)[1]}else I(g)&&(u+=g+y)}else{if(null==v||m&&!1!==g)continue;F(v)||(v=[v]),v=h(v,encodeURIComponent).join("&"+f+"="),u+=(a?"&":"?")+f+"="+v,a=!0}}return u},y.prototype.is=function(e,t){return!0},y.prototype.encode=function(e,t){return e},y.prototype.decode=function(e,t){return e},y.prototype.equals=function(e,t){return e==t},y.prototype.$subPattern=function(){var e=this.pattern.toString();return e.substr(1,e.length-2)},y.prototype.pattern=/.*/,y.prototype.toString=function(){return"{Type:"+this.name+"}"},y.prototype.$normalize=function(e){return this.is(e)?e:this.decode(e)},y.prototype.$asArray=function(e,t){function r(e,t){function r(e,t){return function(){return e[t].apply(e,arguments)}}function i(e){return F(e)?e:N(e)?[e]:[]}function o(e){switch(e.length){case 0:return n;case 1:return"auto"===t?e[0]:e;default:return e}}function a(e){return!e}function s(e,t){return function(n){n=i(n);var r=h(n,e);return!0===t?0===p(r,a).length:o(r)}}this.encode=s(r(e,"encode")),this.decode=s(r(e,"decode")),this.is=s(r(e,"is"),!0),this.equals=function(e){return function(t,n){var r=i(t),o=i(n);if(r.length!==o.length)return!1 +;for(var a=0;a=":n(e.from)}:{"<=":n(e.to)}}function o(e){return e.in?{IN:e.in}:{"NOT IN":e.nin}}return{extend:function(t){return e.assign(Object.create(this),t)},compactFilters:function(t){return t?e.pick(t,function(e){return 0===e||!1===e||!!e}):null},processFilters:function(t){return t?(t=this.compactFilters(t),e.transform(t,function(e,t,n){t.from||t.to?e[n]=i(t):t.in||t.nin?e[n]=o(t):e[n]=t},{})):null}}})}),define("common/models/contact-job-role.model",["common/modules/models","common/models/model","common/instances/contact-job-role-instance.instance","common/services/api/contact-job-role-api.api"],function(e){"use strict";e.factory("ContactJobRole",["$log","Model","ContactJobRoleAPI","ContactJobRoleInstance",function(e,t,n,r){return e.debug("ContactJobRole"),t.extend({all:function(e){return n.all(e).then(function(e){return e.list.map(function(e){return r.init(e,!0)})})}})}])}),define("common/models/instances/group-instance",["common/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("GroupInstance",["ModelInstance",function(e){var t=["id","name","title","description"];return e.extend({fromAPIFilter:function(e,n,r){_.includes(t,r)&&(e[r]=this[r])}})}])}),define("common/mocks/module",["common/angular"],function(e){"use strict";return e.module("common.mocks",[])}),define("common/mocks/services/api/group-mock",["common/lodash","common/mocks/module"],function(e,t){"use strict";t.factory("api.group.mock",["$q",function(t){function n(e){var n=t.defer();return n.resolve(e),n.promise}return{all:function(e,t,r){var i,o,a;return i=r||this.mockedGroups().list,e&&(i=i.filter(function(t){return Object.keys(e).every(function(n){return t[n]===e[n]})})),t&&(o=(t.page-1)*t.size,a=o+t.size,i=i.slice(o,a)),n({list:i,total:i.length,allIds:i.map(function(e){return e.id}).join(",")})},find:function(e,t){return n(t||this.mockedGroups().list.filter(function(t){return t.id===e})[0])},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedGroups:function(){return{total:5,list:[{id:"1",name:"Administrators",title:"Administrators",description:"Contacts in this group are assigned Administrator role permissions.",is_active:"1",visibility:"User and User Admin Only",group_type:["1"],is_hidden:"0",is_reserved:"0"},{id:"2",name:"Newsletter Subscribers",title:"Newsletter Subscribers",is_active:'"1',visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"3",name:"Summer Program Volunteers",title:"Summer Program Volunteers",is_active:"1",visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"4",name:"Advisory Board",title:"Advisory Board",is_active:"1",visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"5",name:"Case_Resources",title:"Case Resources",description:"Contacts in this group are listed with their phone number and email when viewing case. You also can send copies of case activities to these contacts.",is_active:"1",visibility:"User and User Admin Only",where_clause:"...",select_tables:"...",where_tables:"...",group_type:"2",is_hidden:"0",is_reserved:"0"}]}}}}])}),define("common/mocks/data/contact.data",[],function(){return{all:{is_error:0,version:3,count:26,values:[{id:"1",contact_id:"1",display_name:"Dr. Kiara Jensen-Parker",email:"kh.jensen-parker@testing.info",contact_type:"Individual"},{id:"2",contact_id:"2",display_name:"jacobc82@lol.co.pl",email:"cruz.v.jacob@spamalot.com",contact_type:"Individual"},{id:"3",contact_id:"3",display_name:"Mei Müller-Nielsen",email:"mz.mller-nielsen75@infomail.co.pl",contact_type:"Individual"},{id:"4",contact_id:"4",display_name:"Ms. Brigette Deforest",email:"deforest.p.brigette9@fakemail.info",contact_type:"Individual"},{id:"5",contact_id:"5",display_name:"robertsc@testing.net",email:"clintr56@mymail.org",contact_type:"Individual"},{id:"6",contact_id:"6",display_name:"Dr. Allen Samuels Sr.",email:"samuelsa@mymail.org",contact_type:"Individual"},{id:"7",contact_id:"7",display_name:"Mei Wilson",email:"wilson.u.mei59@sample.org",contact_type:"Individual"},{id:"8",contact_id:"8",display_name:"Dr. Betty Díaz",email:"dazb@sample.co.nz",contact_type:"Individual"},{id:"9",contact_id:"9",display_name:"Bob Jones-Dimitrov",email:"bobj@testmail.biz",contact_type:"Individual"},{id:"10",contact_id:"10",display_name:"Truman Samuels III",email:"trumans@spamalot.org",contact_type:"Individual"},{id:"11",contact_id:"11",display_name:"Iris Wagner",email:"iwagner75@notmail.info",contact_type:"Individual"},{id:"12",contact_id:"12",display_name:"Mr. Rosario McReynolds",email:"rosariomcreynolds@testmail.org",contact_type:"Individual"},{id:"13",contact_id:"13",display_name:"Shad Jones-Dimitrov III",email:"shadj@lol.net",contact_type:"Individual"},{id:"14",contact_id:"14",display_name:"Toby Cruz Sr.",email:"",contact_type:"Individual"},{id:"15",contact_id:"15",display_name:"lareedaz61@testing.com",email:"lareedaz61@testing.com",contact_type:"Individual"},{id:"16",contact_id:"16",display_name:"Dr. Jay Deforest",email:"jayd@fishmail.org",contact_type:"Individual"},{id:"17",contact_id:"17",display_name:"Mr. Norris Cruz",email:"norriscruz@spamalot.info",contact_type:"Individual"},{id:"18",contact_id:"18",display_name:"herminiac@fishmail.com",email:"herminiac@fishmail.com",contact_type:"Individual"},{id:"19",contact_id:"19",display_name:"Ashley Terrell",email:"terrell.ashley@testmail.info",contact_type:"Individual"},{id:"20",contact_id:"20",display_name:"Kandace Parker-Díaz",email:"parker-daz.kandace67@fishmail.co.uk",contact_type:"Individual"},{id:"21",contact_id:"21",display_name:"Nicole Samuels",email:"ng.samuels@testmail.net",contact_type:"Individual"},{id:"22",contact_id:"22",display_name:"Dr. Kandace Wattson",email:"kandacewattson@testing.info",contact_type:"Individual"},{id:"23",contact_id:"23",display_name:"Brittney Cruz",email:"cruz.brittney@spamalot.co.nz",contact_type:"Individual"},{id:"24",contact_id:"24",display_name:"Shauna Olsen",email:"",contact_type:"Individual"},{id:"202",contact_id:"202",display_name:"civihr_staff@compucorp.co.uk",email:"civihr_staff@compucorp.co.uk",contact_type:"Individual"},{id:"203",contact_id:"203",display_name:"civihr_manager@compucorp.co.uk",email:"civihr_manager@compucorp.co.uk",contact_type:"Individual"}]}}}),define("common/mocks/services/api/contact-mock",["common/lodash","common/mocks/module","common/mocks/data/contact.data"],function(e,t,n){"use strict";t.factory("api.contact.mock",["$q",function(t){function r(e){var n=t.defer();return n.resolve(e),n.promise}return{all:function(t,i,o,a,s){var l,u,c;return l=s||n.all.values,t&&(l=l.filter(function(n){return Object.keys(t).every(function(r){return null===t[r]||("display_name"===r?new RegExp(t[r],"i").test(n[r]):t[r].IN?e.includes(t[r].IN,n[r]):n[r]===t[r])})})),i&&(u=(i.page-1)*i.size,c=u+i.size,l=l.slice(u,c)),r({list:l,total:l.length,allIds:l.map(function(e){return e.id}).join(",")})},find:function(e,t){return r(t||n.all.values.filter(function(t){return t.id===e})[0])},leaveManagees:function(){return r(this.mockedContacts().list)},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedContacts:function(){var e=n.all.values;return{total:e.length,list:e.map(function(e){return e})}}}}])}),define("common/mocks/services/api/group-contact-mock",["common/lodash","common/mocks/module","common/mocks/services/api/contact-mock","common/mocks/services/api/group-mock"],function(e,t){"use strict";t.factory("api.group-contact.mock",["$q","api.contact.mock","api.group.mock",function(t,n,r){function i(t){return e.sample(t)}function o(e){var n=t.defer();return n.resolve(e),n.promise}var a=n.mockedContacts().list,s=r.mockedGroups().list;return{all:function(e,t,n){var r,i,a;return r=n||this.mockedGroupsContacts.list,e&&(r=r.filter(function(t){return Object.keys(e).every(function(n){return t[n]===e[n]})})),t&&(i=(t.page-1)*t.size,a=i+t.size,r=r.slice(i,a)),o({list:r,total:r.length,allIds:r.map(function(e){return e.id}).join(",")})},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedGroupsContacts:{total:a.length,list:function(){var e=1;return a.map(function(t){return{id:""+e++,group_id:i(s).id,contact_id:t.id,status:"Added"}})}()}}}])}),define("common/models/group",["common/modules/models","common/models/model","common/models/instances/group-instance","common/mocks/services/api/group-mock","common/mocks/services/api/group-contact-mock"],function(e){"use strict";e.factory("Group",["Model","api.group.mock","api.group-contact.mock","GroupInstance",function(e,t,n,r){return e.extend({all:function(e,n){return t.all(this.processFilters(e),n).then(function(e){return e.list=e.list.map(function(e){return r.init(e,!0)}),e})},find:function(e){return t.find(e).then(function(e){return r.init(e,!0)})},contactIdsOf:function(e){return n.all({group_id:e}).then(function(e){return e.list.map(function(e){return e.contact_id})})}})}])}),define("common/models/instances/job-role-instance",["common/lodash","common/moment","common/modules/models-instances","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("JobRoleInstance",["ModelInstance","HR_settings",function(n,r){return n.extend({fromAPIFilter:function(n,i,o){var a=r.DATE_FORMAT.toUpperCase();e.endsWith(o,"_date")?n[o]=t(this[o],"YYYY-MM-DD HH:mm:ss").format(a):"api.HRJobContract.getsingle"===o?(n.contact_id=this[o].contact_id,n.job_contract_id=this[o].id):n[o]=this[o]},toAPIFilter:function(n,i,o){var a=["contact_id","job_contract_id"],s=r.DATE_FORMAT.toUpperCase();if(e.endsWith(o,"_date"))n[o]=t(this[o],s).format("YYYY-MM-DD HH:mm:ss");else{if(e.includes(a,o))return;n[o]=this[o]}}})}])}),define("common/services/api/job-role",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.job-role",["$log","api",function(e,t){return e.debug("api.jobRole"),t.extend({all:function(t,n,r,i){return e.debug("api.jobRole.api"),this.getAll("HrJobRoles",t,n,r,i)},find:function(t){return e.debug("api.jobRole.find"),this.sendGET("HRJobRole","get",{id:""+t},!1).then(function(e){return e.values[0]})}})}])}),define("common/models/job-role",["common/modules/models","common/models/model","common/models/instances/job-role-instance","common/services/api/job-role"],function(e){"use strict";e.factory("JobRole",["Model","api.job-role","JobRoleInstance",function(e,t,n){return e.extend({all:function(e,r){return t.all(this.processFilters(e),r).then(function(e){return e.list=e.list.map(function(e){return n.init(e,!0)}),e})},find:function(e){return t.find(e).then(function(e){return n.init(e,!0)})}})}])}),define("common/services/api/contact",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.contact",["$log","api",function(e,t){return e.debug("api.contact"),t.extend({all:function(t,n,r,i){return e.debug("api.contact.api"),this.getAll("Contact",t,n,r,i)},find:function(t){return e.debug("api.contact.find"),this.sendGET("Contact","get",{id:""+t},!1).then(function(e){return e.values[0]})},leaveManagees:function(t,n){return e.debug("api.contact.leaveManagees"),n=_.assign({},n,{managed_by:t}),this.sendGET("Contact","getleavemanagees",n).then(function(e){return e.values})}})}])}),define("common/models/instances/contact-instance",["common/modules/models-instances","common/models/instances/instance","common/services/api/contact"],function(e){"use strict";e.factory("ContactInstance",["ModelInstance","api.contact",function(e,t){return e.extend({leaveManagees:function(e){return t.leaveManagees(this.id,e)}})}])}),define("common/models/contact",["common/lodash","common/modules/models","common/models/model","common/models/contact-job-role.model","common/models/group","common/models/job-role","common/models/instances/contact-instance","common/services/api/contact"],function(e,t){"use strict";t.factory("Contact",["$q","Model","api.contact","Group","JobRole","ContactJobRole","ContactInstance",function(t,n,r,i,o,a,s){function l(t,n){return!e.isEmpty(e.intersection(e.keys(t),n))}function u(e){return a.all(e).then(function(e){return e.map(function(e){return e.contact_id})})}function c(t,n){return e(t).omit(d).omit(p).assign({id:{in:e.intersection.apply(null,n)}}).value()}function f(n){var r=t.defer(),o=[];return n=this.compactFilters(n),l(n,p)&&o.push(u(e.pick(n,p))),l(n,d)&&o.push(i.contactIdsOf(n.group_id)),e.isEmpty(o)?r.resolve(this.processFilters(n)):t.all(o).then(function(e){n=c(n,e),r.resolve(this.processFilters(n))}.bind(this)),r.promise}var d=["group_id"],p=["region","department","level_type","location"];return n.extend({all:function(e,t,n,i){return f.call(this,e).then(function(e){return e&&e.id&&!e.id.IN.length?{list:[]}:r.all(e,t,n,i)}).then(function(e){return e.list=e.list.map(function(e){return s.init(e,!0)}),e})},find:function(e){return r.find(e).then(function(e){return s.init(e,!0)})},leaveManagees:function(e,t){return f.call(this,t).then(function(t){return t&&t.id&&!t.id.IN.length?[]:r.leaveManagees(e,t)})}})}])}),define("common/models/instances/contract-instance",["common/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("ContractInstance",["ModelInstance",function(e){return e.extend({})}])}),define("common/services/api/contract",["common/lodash","common/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("api.contract",["$log","api",function(t,n){function r(t){var n=e.clone(t);return n.info=n["api.HRJobContract.getfulldetails"],delete n["api.HRJobContract.getfulldetails"],n}return t.debug("api.contract"),n.extend({all:function(e){return t.debug("ContractAPI.all"),e=e||{},e["api.HRJobContract.getfulldetails"]={jobcontract_id:"$value.id"},e.deleted=0,this.sendGET("HRJobContract","get",e,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r)})}})}])}),define("common/models/contract",["common/modules/models","common/models/model","common/models/instances/contract-instance","common/services/api/contract"],function(e){"use strict";e.factory("Contract",["$log","Model","api.contract","ContractInstance",function(e,t,n,r){return e.debug("Contract"),t.extend({all:function(e){return n.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})}})}])}),define("common/models/option-group",["common/modules/models","common/models/model","common/services/api/option-group"],function(e){"use strict";e.factory("OptionGroup",["Model","api.optionGroup",function(e,t){return e.extend({valuesOf:function(e,n){return t.valuesOf(e,n)}})}])}),function(e,t){define("common/models/session.model",["common/modules/models","common/models/model"],function(n){"use strict";n.factory("Session",["$log","$q","Model",function(n,r,i){return n.debug("Session"),i.extend({get:function(){var n={contactId:e.vars.session?e.vars.session.contact_id:t.settings.currentCiviCRMUserId};if(!n.contactId)throw new Error("Session Error: *Logged In Contact Id* is not defined");return r.resolve(n)}})}])})}(CRM,window.Drupal),define("common/bundles/models",["common/instances/contact-job-role-instance.instance","common/models/model","common/models/contact","common/models/contact-job-role.model","common/models/contract","common/models/group","common/models/job-role","common/models/option-group","common/models/session.model","common/models/instances/instance","common/models/instances/contact-instance","common/models/instances/contract-instance","common/models/instances/group-instance","common/models/instances/job-role-instance"],function(){}),define("common/services/dialog/dialog",["common/lodash","common/modules/services"],function(e,t){"use strict";function n(t,n,r){function i(i){var o;if(!e.isObject(i))throw new Error("Dialog Service: Options passed should be an object");return o=n.children(),t.open({appendTo:o.length?o.eq(0):n,size:"sm",controller:"DialogController",template:r.get("dialog.html"),resolve:{options:function(){return i}}}).result}return{open:i}}t.factory("dialog",n),n.$inject=["$uibModal","$rootElement","$templateCache"]}),define("common/controllers/dialog/dialog-ctrl",["common/lodash","common/modules/controllers"],function(e,t){"use strict";function n(t,n,r,i){function o(t){e.assign(n,e.defaultsDeep(t,{title:"CiviHR",msg:"",copyConfirm:"",copyCancel:"",classConfirm:"btn-primary",loading:!1}))}function a(){r.close(!1)}function s(){n.loading=!0,r.closed.then(n.onCloseAfterConfirm),t.resolve().then(n.onConfirm).then(function(){r.close(!0)})}n.cancel=a,n.confirm=s,function(){o(i),i.optionsPromise&&i.optionsPromise().then(function(e){o(e)})}()}t.controller("DialogController",n),n.$inject=["$q","$scope","$uibModalInstance","options"]}),define("common/modules/dialog",["common/angular","common/services/dialog/dialog","common/controllers/dialog/dialog-ctrl","common/angularBootstrap","common/directives/loading","common/modules/templates"],function(e){"use strict";return e.module("common.dialog",["ui.bootstrap","common.directives","common.templates"])}),define("common/decorators/xeditable-civi/editable-directive-factory",[],function(){"use strict";return["$delegate",function(e){return function(t){var n=e(t);return n.compile=function(e){var t,r=e[0].attributes.getNamedItem("ng-href");return e.append(''),r&&(t=angular.element(""),t.text("Follow link"),t.attr(r.nodeName,r.value),t.attr("ng-click","$event.stopPropagation();"),t.addClass("editable-link"),e.append(t),e.addClass("editable-with-link")),{post:n.link}},n}}]}),define("common/directives/xeditable-civi/editable-ta",[],function(){"use strict";return["editableDirectiveFactory","$timeout",function(e,t){var n,r;return r=e({directiveName:"editableTa",inputTpl:"",render:function(){this.parent.render.call(this),this.inputEl.parent().parent().removeClass("form-inline"),this.inputEl.addClass("editable-ta"),this.inputEl.attr("ng-model","ta.$data"),this.inputEl.attr("ta-toolbar",this.attrs.eTaToolbar||'[["bold","italics","underline","strikeThrough","ul","ol","undo","redo","clear"]]'),t(function(){this.inputEl.find("textarea").hide()}.bind(this),0)},save:function(){this.scope.$data=this.scope.ta.$data,this.parent.save.call(this)},setLocalValue:function(){this.parent.setLocalValue.call(this),this.scope.ta.$data=this.scope.$data}}),n=r.link,r.link=function(e,t,r,i){return e.ta={},n(e,t,r,i)},r}]}),define("common/modules/xeditable-civi",["common/angular","common/decorators/xeditable-civi/editable-directive-factory","common/directives/xeditable-civi/editable-ta","common/angularXeditable","common/text-angular"],function(e,t,n){"use strict";return e.module("xeditable-civi",["xeditable","textAngular"]).directive("editableTa",n)}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/org.civicrm.reqangular/dist/reqangular.min.js.map \ No newline at end of file diff --git a/org.civicrm.reqangular/src/common/models/option-group.js b/org.civicrm.reqangular/src/common/models/option-group.js index a05bb58aece..ed8cff49783 100644 --- a/org.civicrm.reqangular/src/common/models/option-group.js +++ b/org.civicrm.reqangular/src/common/models/option-group.js @@ -18,12 +18,11 @@ define([ * @param {String|Array} names * Bases on the type of the parameter, the method will return * either an array of values (string) or an object (array) - * @param {Object} params optional parameters for the query - * @param {Boolean} cache optional parameter to cache the query or not + * @param {Boolean} [cache] parameter to cache the query or not * @return {Promise} */ - valuesOf: function (names, params, cache) { - return optionGroupAPI.valuesOf(names, params, cache); + valuesOf: function (names, cache) { + return optionGroupAPI.valuesOf(names, cache); } }); } diff --git a/org.civicrm.reqangular/src/common/services/api.js b/org.civicrm.reqangular/src/common/services/api.js index 3395151138f..e44d6abc39e 100644 --- a/org.civicrm.reqangular/src/common/services/api.js +++ b/org.civicrm.reqangular/src/common/services/api.js @@ -42,20 +42,6 @@ define([ return JSON.stringify(_.merge(defaults, params || {})); } - /** - * Constructs a GET query string exactly the same way as $http service does - * - * @param {Object} json that is passed as "params" to $http - * @return {String} query string - */ - function jsonToQueryString (json) { - return '?' + Object.keys(json).sort().map(function (key) { - return (encodeURIComponent(key) + '=' + encodeURIComponent(json[key])) - .replace(/%3A/g, ':') - .replace(/%2C/g, ','); - }).join('&'); - } - return { /** @@ -158,8 +144,8 @@ define([ * @param {String} action - The action to perform * @param {Object} params - Any additional parameters to pass in the request * @param {Boolean} returnCachedData - * - if passed as TRUE or not passed, returns data from cache (if not the first call) - * - if passed as FALSE, returns updated data from API and caches for future requests + * - if passed as `true` or not passed, returns data from cache (if not the first call) + * - if passed as `false`, returns updated data from API and caches for future requests * @return {Promise} */ sendGET: function (entity, action, params, returnCachedData) { @@ -172,7 +158,7 @@ define([ if (returnCachedData === false) { $cacheFactory.get('$http').remove( - API_ENDPOINT + jsonToQueryString(queryJSON)); + API_ENDPOINT + '?' + $httpParamSerializer(queryJSON)); } return $http({ diff --git a/org.civicrm.reqangular/src/common/services/api/option-group.js b/org.civicrm.reqangular/src/common/services/api/option-group.js index d24a372d476..b6d6b9b2a88 100644 --- a/org.civicrm.reqangular/src/common/services/api/option-group.js +++ b/org.civicrm.reqangular/src/common/services/api/option-group.js @@ -55,24 +55,23 @@ define([ * @param {String|Array} groupNames * If the value is an array of names, the method will group * the values by option group names - * @param {Object} params optional parameters for the query * @param {Boolean} cache optional parameter to cache the query or not * @return {Promise} * Resolves to an array with the values (if `groupNames` is a string) * or an object with keys as the group names and values as the * array of their option values (if `groupNames` is an array) */ - valuesOf: function (groupNames, params, cache) { + valuesOf: function (groupNames, cache) { var multiple = _.isArray(groupNames); - return this.sendGET('OptionValue', 'get', _.assign({ + return this.sendGET('OptionValue', 'get', { 'option_group_id.name': { 'IN': multiple ? groupNames : [groupNames] }, 'is_active': '1', 'return': [ 'option_group_id.name', 'option_group_id', 'id', 'name', 'label', 'value', 'weight', 'is_active', 'is_reserved' ] - }, params), cache) + }, cache) .then(normalizeResponse) .then(function (optionValues) { return multiple ? valuesByGroup(optionValues) : optionValues; diff --git a/org.civicrm.reqangular/src/common/services/crm-ang.service.js b/org.civicrm.reqangular/src/common/services/crm-ang.service.js index ffe60898342..1d16f360ea4 100644 --- a/org.civicrm.reqangular/src/common/services/crm-ang.service.js +++ b/org.civicrm.reqangular/src/common/services/crm-ang.service.js @@ -16,11 +16,11 @@ /** * Opens a CRM form with a provided url and options * This is simply a wrapper to CRM.loadForm - * Reference: https://docs.civicrm.org/dev/en/latest/framework/ajax + * @see https://docs.civicrm.org/dev/en/latest/framework/ajax * * @param {String} url * @param {Object} options - * @return {jQuery} + * @return {Object} extended jQuery object */ function loadForm (url, options) { return CRM.loadForm(url, options); diff --git a/org.civicrm.reqangular/test/models/option-group.spec.js b/org.civicrm.reqangular/test/models/option-group.spec.js index 73bc12d7692..d96201ab043 100644 --- a/org.civicrm.reqangular/test/models/option-group.spec.js +++ b/org.civicrm.reqangular/test/models/option-group.spec.js @@ -47,7 +47,7 @@ define([ }); it('caches requests by default', function () { - expect(optionGroupAPI.valuesOf.calls.mostRecent().args[2]).toBe(undefined); + expect(optionGroupAPI.valuesOf.calls.mostRecent().args[1]).toBe(undefined); }); }); @@ -63,27 +63,15 @@ define([ }); }); - describe('when extra params are passed', function () { - var params = { paramKey: 'paramValue' }; - - beforeEach(function () { - OptionGroup.valuesOf(optionGroupName, params); - }); - - it('passed params to API', function () { - expect(optionGroupAPI.valuesOf.calls.mostRecent().args[1]).toBe(params); - }); - }); - describe('when caching is disabled', function () { var cache = false; beforeEach(function () { - OptionGroup.valuesOf(optionGroupName, {}, cache); + OptionGroup.valuesOf(optionGroupName, cache); }); it('does not cache requests', function () { - expect(optionGroupAPI.valuesOf.calls.mostRecent().args[2]).toBe(cache); + expect(optionGroupAPI.valuesOf.calls.mostRecent().args[1]).toBe(cache); }); }); }); diff --git a/org.civicrm.reqangular/test/services/api.spec.js b/org.civicrm.reqangular/test/services/api.spec.js index fb2dce3c798..0ab7210c85f 100644 --- a/org.civicrm.reqangular/test/services/api.spec.js +++ b/org.civicrm.reqangular/test/services/api.spec.js @@ -14,8 +14,7 @@ define([ beforeEach(module('common.apis')); - beforeEach(inject(function (_api_, _$cacheFactory_, _$httpBackend_, - _$httpParamSerializer_, _$rootScope_) { + beforeEach(inject(function (_api_, _$cacheFactory_, _$httpBackend_, _$httpParamSerializer_, _$rootScope_) { api = _api_; $cacheFactory = _$cacheFactory_; $httpBackend = _$httpBackend_; @@ -24,11 +23,7 @@ define([ })); describe('sendGET()', function () { - var promise; - - afterEach(function () { - $httpBackend.flush(); - }); + var expectedResponse; describe('when the API does not return an error', function () { var returnValue = { @@ -37,13 +32,15 @@ define([ }; beforeEach(function () { - promise = expectAndSendGET(returnValue); + expectAndSendGET(returnValue) + .then(function (response) { + expectedResponse = response; + }); + $httpBackend.flush(); }); it('returns values sent from API', function () { - promise.then(function (response) { - expect(response).toEqual(returnValue); - }); + expect(expectedResponse).toEqual(returnValue); }); }); @@ -54,13 +51,15 @@ define([ }; beforeEach(function () { - promise = expectAndSendGET(returnValue); + expectAndSendGET(returnValue) + .catch(function (response) { + expectedResponse = response; + }); + $httpBackend.flush(); }); it('rejects the promise with the error message provided by the API', function () { - promise.catch(function (response) { - expect(response).toBe(returnValue.error_message); - }); + expect(expectedResponse).toBe(returnValue.error_message); }); }); @@ -70,20 +69,20 @@ define([ somekey: 'someval' }; + beforeEach(function () { + spyOn(api, 'sendGET').and.callThrough(); + }); + describe('when limit is sent as a parameter', function () { var limit = 5; beforeEach(function () { - expectAndSendGET(returnValue, {options: {limit: limit}}); + expectAndSendGET(returnValue, { options: { limit: limit } }); + $httpBackend.flush(); }); - it('send a GET request with original limit value', function () { - $httpBackend.expectGET('/civicrm/ajax/rest?' + $httpParamSerializer({ - json: {options: {limit: limit}}, - sequential: 1, - action: action, - entity: entity - })); + it('sends a GET request with original limit value', function () { + expect(api.sendGET.calls.mostRecent().args[2]).toEqual({ options: { limit: limit } }); }); }); @@ -92,18 +91,14 @@ define([ expectAndSendGET(returnValue); }); - it('send a GET request with 0 set as limit', function () { - $httpBackend.expectGET('/civicrm/ajax/rest?' + $httpParamSerializer({ - json: {options: {limit: 0}}, - sequential: 1, - action: action, - entity: entity - })); + it('sends a GET request with 0 set as limit', function () { + expect(api.sendGET.calls.mostRecent().args[2]).not.toBeDefined(); }); }); }); describe('caching', function () { + var cacheSize; var sampleResult = 'sample result'; var sampleParams = {}; @@ -115,6 +110,8 @@ define([ beforeEach(function () { expectAndSendGET(sampleResult, sampleParams); $rootScope.$digest(); + + cacheSize = $cacheFactory.get('$http').info().size; }); it('does not flush cache before HTTP call', function () { @@ -122,14 +119,16 @@ define([ }); it('caches data by default', function () { - expect($cacheFactory.get('$http').info().size).toBe(1); + expect(cacheSize).toBe(1); }); }); - describe('when "returnCachedData" parameter passed as TRUE', function () { + describe('when "returnCachedData" parameter passed as `true`', function () { beforeEach(function () { expectAndSendGET(sampleResult, sampleParams, true); $rootScope.$digest(); + + cacheSize = $cacheFactory.get('$http').info().size; }); it('does not flush cache before HTTP call', function () { @@ -137,23 +136,35 @@ define([ }); it('caches data', function () { - expect($cacheFactory.get('$http').info().size).toBe(1); + expect(cacheSize).toBe(1); }); }); - describe('when "returnCachedData" parameter passed as FALSE', function () { + describe('when "returnCachedData" parameter passed as `false`', function () { + var cacheResultKey; + beforeEach(function () { + // An URL that is constructed during calling $http method + // is used by $cacheFactory to keep the cached results + cacheResultKey = '/civicrm/ajax/rest?' + $httpParamSerializer({ + action: action, + entity: entity, + json: { options: { limit: 0 } }, + sequential: 1 + }); + expectAndSendGET(sampleResult, sampleParams, false); $rootScope.$digest(); + + cacheSize = $cacheFactory.get('$http').info().size; }); it('flushes cache before HTTP call', function () { - expect($cacheFactory.get('$http').remove).toHaveBeenCalledWith( - '/civicrm/ajax/rest?action=action&entity=entity&json=%7B%22options%22:%7B%22limit%22:0%7D%7D&sequential=1'); + expect($cacheFactory.get('$http').remove).toHaveBeenCalledWith(cacheResultKey); }); it('caches updated data for future requests', function () { - expect($cacheFactory.get('$http').info().size).toBe(1); + expect(cacheSize).toBe(1); }); }); }); @@ -176,11 +187,7 @@ define([ }); describe('sendPOST()', function () { - var promise; - - afterEach(function () { - $httpBackend.flush(); - }); + var expectedResponse; describe('when the API doesnt return an error', function () { var returnValue = { @@ -189,13 +196,15 @@ define([ }; beforeEach(function () { - promise = expectAndSendPOST(returnValue); + expectAndSendPOST(returnValue) + .then(function (response) { + expectedResponse = response; + }); + $httpBackend.flush(); }); it('returns values sent from API', function () { - promise.then(function (response) { - expect(response).toEqual(returnValue); - }); + expect(expectedResponse).toEqual(returnValue); }); }); @@ -206,13 +215,15 @@ define([ }; beforeEach(function () { - promise = expectAndSendPOST(returnValue); + expectAndSendPOST(returnValue) + .catch(function (response) { + expectedResponse = response; + }); + $httpBackend.flush(); }); it('rejects the promise with the error message provided by the API', function () { - promise.catch(function (response) { - expect(response).toBe(returnValue.error_message); - }); + expect(expectedResponse).toBe(returnValue.error_message); }); }); @@ -222,20 +233,19 @@ define([ somekey: 'someval' }; + beforeEach(function () { + spyOn(api, 'sendPOST').and.callThrough(); + }); + describe('when limit is sent as a parameter', function () { var limit = 5; beforeEach(function () { - expectAndSendPOST(returnValue, {options: {limit: limit}}); + expectAndSendPOST(returnValue, { options: { limit: limit } }); }); it('send a POST request with original limit value', function () { - $httpBackend.expectPOST('/civicrm/ajax/rest', $httpParamSerializer({ - json: { options: { limit: limit } }, - sequential: 1, - action: action, - entity: entity - })); + expect(api.sendPOST.calls.mostRecent().args[2]).toEqual({ options: { limit: limit } }); }); }); @@ -245,12 +255,7 @@ define([ }); it('send a POST request with 0 set as limit', function () { - $httpBackend.expectPOST('/civicrm/ajax/rest', $httpParamSerializer({ - json: { options: { limit: 0 } }, - sequential: 1, - action: action, - entity: entity - })); + expect(api.sendPOST.calls.mostRecent().args[2]).not.toBeDefined(); }); }); }); diff --git a/org.civicrm.reqangular/test/services/api/option-group.spec.js b/org.civicrm.reqangular/test/services/api/option-group.spec.js index 803dc5f20b8..d1a96a97660 100644 --- a/org.civicrm.reqangular/test/services/api/option-group.spec.js +++ b/org.civicrm.reqangular/test/services/api/option-group.spec.js @@ -10,9 +10,7 @@ define([ describe('api.option-group', function () { var $q, OptionGroupAPI; - beforeEach(function () { - module('common.models', 'common.mocks'); - }); + beforeEach(module('common.models', 'common.mocks')); beforeEach(inject([ 'api.optionGroup', @@ -36,7 +34,7 @@ define([ spyOn(OptionGroupAPI, 'sendGET').and.returnValue($q.resolve()); }); - describe('when a single option name is passed without any additional parameters', function () { + describe('when a single option name is passed', function () { var sendGETCallArgs; beforeEach(function () { @@ -78,25 +76,11 @@ define([ }); }); - describe('when extra params are passed', function () { - var params = { paramKey: 'paramValue' }; - - beforeEach(function () { - OptionGroupAPI.valuesOf(optionGroupName, params); - }); - - it('passes extra parameters to sendGET', function () { - expect(OptionGroupAPI.sendGET.calls.mostRecent().args[2]).toEqual( - jasmine.objectContaining(params) - ); - }); - }); - describe('when no caching is needed', function () { var cache = false; beforeEach(function () { - OptionGroupAPI.valuesOf(optionGroupName, {}, cache); + OptionGroupAPI.valuesOf(optionGroupName, cache); }); it('tells sendGET to not cache the API call', function () { diff --git a/org.civicrm.reqangular/test/services/crm-ang.service.spec.js b/org.civicrm.reqangular/test/services/crm-ang.service.spec.js index be5021c2024..d8c893a7e69 100644 --- a/org.civicrm.reqangular/test/services/crm-ang.service.spec.js +++ b/org.civicrm.reqangular/test/services/crm-ang.service.spec.js @@ -23,10 +23,7 @@ var originalResult = 'jQuery object'; beforeEach(function () { - CRM.loadForm = function () {}; - - spyOn(CRM, 'loadForm').and.returnValue(originalResult); - + CRM.loadForm = jasmine.createSpy().and.returnValue(originalResult); result = crmAngService.loadForm(url, options); }); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js index e15f2509c91..32bf4fcad04 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js @@ -1,5 +1,5 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,o){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:t(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,o,s,i){return t.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return s.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,o,s){return t.debug("WorkPatternAPI.getCalendar",n,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,o){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,o,s,i){function r(t,n){return u().then(function(a){var o=this.days[c(t).valueOf()];return!!o&&e.find(a,function(e){return e.name===n}).value===o.type}.bind(this))}function c(e){return t(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[c(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,o){return t.debug("Calendar"),n.extend({get:function(n,s,i,r){return t.debug("Calendar.get"),a.getCalendar(n,s,i,r).then(function(t){var a=t.values.map(function(e){return o.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function o(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,o,s){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return o.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",t,n,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t,n,o,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var i=a.defer();t&&n||i.reject("contact_id and period_id are mandatory");var r={contact_id:t,period_id:n,statuses:o?{IN:o}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",r,!1).then(function(e){i.resolve(e.values)}),i.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?o.reject(t(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(t){return s.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,o&&(i.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return r.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),n.all(t)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(s.permissions.admin.administer).then(function(t){return t?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,o,s,i){return n.all(this.processFilters(e),t,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,o){return n.balanceChangeByAbsenceType(e,t,a,o)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/instances/work-pattern.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("WorkPatternInstance",["$log","ModelInstance",function(e,t){return e.debug("WorkPatternInstance"),t.extend({})}])}),define("leave-absences/shared/models/work-pattern.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/work-pattern.instance"],function(e,t){"use strict";t.factory("WorkPattern",["$log","Model","WorkPatternAPI","WorkPatternInstance",function(t,n,a,o){return t.debug("WorkPattern"),n.extend({assignWorkPattern:function(e,t,n,o,s,i){return a.assignWorkPattern(e,t,n,o,s,i)},default:function(){return a.get({is_default:!0}).then(function(t){return o.init(e.first(t),!0)})},unassignWorkPattern:function(e){return a.unassignWorkPattern(e)},workPatternsOf:function(e,t,n){return a.workPatternsOf(e,t,n).then(function(e){return e.map(function(e){return o.init(e,!0)})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function u(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?c():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return o.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):i.all()}function m(e){return"me"===e?o.leaveManagees(v.contactId):"unassigned"===e?o.leaveManagees(void 0,{unassigned:!0}):o.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){r.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,u()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:i.contactId}).leaveManagees().then(function(e){i.lookupContacts=e}).then(o)}}}function o(){return t.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:i.filters.userSettings.department?i.filters.userSettings.department.value:null,level_type:i.filters.userSettings.level_type?i.filters.userSettings.level_type.value:null,location:i.filters.userSettings.location?i.filters.userSettings.location.value:null,region:i.filters.userSettings.region?i.filters.userSettings.region.value:null,id:{IN:i.filters.userSettings.contact?[i.filters.userSettings.contact.id]:i.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var i;return{init:function(e){return i=e,i.showContactName=!0,i.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function o(a,o,s,i,r,c,u,l,d,m){function f(){for(var e=[],t=n(M.selectedPeriod.start_date).clone().startOf("month"),a=n(M.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(R(t)),t.add(1,"month");M.months=e}function p(){i.$new().$watch(function(){return M.selectedMonths},function(t,n){null===n||e.equals(t,n)||I()})}function h(e){M.injectMonths=!0,S("injected").then(function(){I(e)}).then(function(){M.loading.calendar=!1})}function v(){L=a("LeaveCalendar"+t.capitalize(k)+"Controller").init(M)}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function g(){return c.all().then(function(e){M.absencePeriods=t.sortBy(e,"start_date"),M.selectedPeriod=t.find(M.absencePeriods,function(e){return!!e.current})}).then(f).then(w)}function _(){return u.all().then(u.loadCalculationUnits)}function y(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return L.loadContacts().then(function(e){M.contacts=e})}function C(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){M.filters.optionValues.regions=e.hrjc_region,M.filters.optionValues.locations=e.hrjc_location,M.filters.optionValues.levelTypes=e.hrjc_level_type,M.filters.optionValues.departments=e.hrjc_department})}function D(){return l.all()}function T(){return o.all([_(),D(),y()]).then(function(e){M.supportData.absenceTypes=e[0],M.supportData.publicHolidays=e[1],M.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,M.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,M.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,M.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function P(){var e=o.resolve();return M.injectMonths&&(e=S("destroyed"),M.injectMonths=!1),e}function R(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function A(e){e=t.includes(["contacts","period"],e)?e:"period",o.resolve().then(function(){M.loading.calendar=!0}).then(P).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function I(e){var n=M.selectedMonths.length?M.months.filter(function(e){return t.includes(M.selectedMonths,e.index)}):M.months;i.$emit("LeaveCalendar::showMonths",n,!!e)}function w(){M.selectedMonths=[n().month()]}function O(){return M.roleOverride?o.resolve().then(function(){k=M.roleOverride}):o.all([m(r.permissions.admin.administer),m(r.permissions.ssp.manage)]).then(function(e){k=e[0]?"admin":e[1]?"manager":"staff"})}function S(e){return o(function(n){var a=0,o=i.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===M.months.length&&(o(),n())})})}s.debug("Component: leave-calendar");var L,k,M=this;M.absencePeriods=[],M.contacts=[],M.contactIdsToReduceTo=null,M.injectMonths=!1,M.months=[],M.selectedMonths=null,M.selectedPeriod=null,M.showContactName=!1,M.showFilters=!1,M.supportData={},M.loading={calendar:!0,page:!0},M.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},M.labelPeriod=b,M.refresh=A,function(){O().then(p).then(v).then(P).then(g).then(function(){return o.all([q(),T()])}).then(function(){return M.showFilters?C():t.noop}).then(function(){h()}).then(function(){M.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",o]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,o){"use strict";function s(){y.calculationUnit=i(y.supportData.calculationUnits,"value",b.calculation_unit)}function i(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function r(){var e,n;return n=t(y.contactData.leaveRequest.from_date).isSame(y.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+y.calculationUnit.name+"-on-"+e+"-tooltip"}function c(){b=i(y.supportData.absenceTypes,"id",y.contactData.leaveRequest.type_id),y.contactData.leaveRequest["type_id.title"]=b.title}function u(){"days"===y.calculationUnit.name&&(g=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.from_date_type),_=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.to_date_type),y.contactData.leaveRequest["from_date_type.label"]=g.label,y.contactData.leaveRequest["to_date_type.label"]=_.label)}function l(e,t,n,a,s){e.stopPropagation(),o.openModal(t,n,a,s)}function d(){y.dates.from=new Date(y.contactData.leaveRequest.from_date),y.dates.to=new Date(y.contactData.leaveRequest.to_date)}function m(){y.contactData.isAccruedTOIL?y.label="AT":"days"===y.calculationUnit.name?f():p()}function f(){y.label=y.contactData.isAM?"AM":y.contactData.isPM?"PM":""}function p(){var e=t(y.contactData.leaveRequest.from_date).isSame(y.date,"day"),n=t(y.contactData.leaveRequest.to_date).isSame(y.date,"day");y.label=e?t(y.contactData.leaveRequest.from_date).format("HH:mm"):n?t(y.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){y.tooltipTemplate=y.contactData.isAccruedTOIL?"accrued-toil-tooltip":r()}function v(){a.$watch("day.contactData.leaveRequest",function(){y.contactData&&y.contactData.leaveRequest&&(c(),s(),u(),m(),d(),h()) })}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(e){_([e]),U(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return j[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){L(e),U(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=P(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){N.push(o.$on("LeaveCalendar::showMonths",$)),N.push(r.subscribe("LeaveRequest::new",u)),N.push(r.subscribe("LeaveRequest::edit",B)),N.push(r.subscribe("LeaveRequest::updatedByManager",B)),N.push(r.subscribe("LeaveRequest::delete",h)),N.push(r.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function D(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function T(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function P(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function R(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function A(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function I(){return[A(c.statusNames.approved),A(c.statusNames.adminApproved),A(c.statusNames.awaitingApproval),A(c.statusNames.moreInformationRequired)]}function w(){return H.month.loading=!0,a.all([S(),O()]).then(b).then(x).then(function(){F=!0}).then(function(){H.month.loading=!1})}function O(){return i.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:I()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function S(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){j=e.indexBy(t,"contact_id")})}function L(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function k(){o.$emit("LeaveCalendar::monthDestroyed"),N.map(function(e){e.remove?e.remove():e()})}function M(t,n,o){var s,i;return t.contactsData[n]=t.contactsData[n]||{},i=m(n),s=!0===o?a.resolve():a.all([i.isWeekend(p(t.date)),i.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:D(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?T(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function x(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return M(e,t.id)}))}))}function $(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!F)&&w())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=R(e);t&&(h(t),-1!==I().indexOf(e.status_id)&&u(e))}function U(e){return a.all(P(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var F=!1,N=[],j={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=k,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,i,r,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(i.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=D[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&r.publish("ManagerBadge:: Update Count"),r.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(D,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:D[e].label,isDirectAction:D[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,D={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return r.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,c.serverDateFormat).toDate()}function h(e){return t(e).format(c.serverDateFormat)}function v(e){var t;return i.resolve().then(function(){N(e),"from"===e&&F(),S("hours")&&(_(e),"from"!==e||te.uiOptions.multipleDays||_("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return i.reject("Please change date as it is not in any absence period")}).then(W).then(function(){if(t)return x()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(V(),!t)return E();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(P).finally(y)}function b(){return V(),E()}function g(){return te.uiOptions.toDate=null,N("to"),i.resolve().then(V).then(te.setDaysSelectionModeExtended).then(y).then(!te.uiOptions.multipleDays&&E)}function _(e){te.uiOptions.times[e].loading=!0}function y(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,S("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function C(){return te.request?te.request.request_type:te.leaveType||null}function D(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(j).catch(P)}function P(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function R(){return te.isMode("create")||te.forceRecalculateBalanceChange?E():T()}function A(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():i.resolve()}function I(){ee.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){Q()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){J(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",E))}function w(){te.isMode("edit")&&(te.isLeaveStatus(c.statusNames.approved)||te.isLeaveStatus(c.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function O(){o.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(K(e),V()))})}function S(e){return te.selectedAbsenceType.calculation_unit_name===e}function L(e){return te.request.request_type===e}function k(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function M(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function x(){return u.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function $(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function E(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(j).catch(P).finally(function(){te.loading.balanceChange=!1})):i.resolve()}function B(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function U(){return h(te.request.from_date)===h(te.request.to_date)}function F(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,N("to"))}function N(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),V(),z()}function j(e){te.balance.change=e,te.request.balance_change=e.amount,f(),B(),te.loading.balanceChange=!1}function W(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function H(){return!te.isMode("create")&&U()||te.isMode("create")&&(L("sickness")||S("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,i.resolve().then(te.setDaysSelectionModeExtended)}function G(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function Y(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function V(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(S("hours")||L("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function X(){e.forEach(ee,function(e){e()})}function Q(){var e,t=te.selectedAbsenceType.calculation_unit_name;return Y(),e=t!==te.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&H).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&V).then(y).then(E)}function J(e){return te.absenceTypes=e,Y(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,N("to")),G(),E()}function K(e){var t=D(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(D(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(D(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=c.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:$},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:r.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=b,te.daysSelectionModeChangeHandler=g,te.disableAndShowLoadingTimeInput=_,te.getMomentDateWithGivenTime=D,te.handleError=P,te.isCalculationUnit=S,te.isLeaveType=L,te.isNotWorkingDay=k,te.performBalanceChangeCalculation=E,te.setRequestDateTimesAndDateTypes=V,te.updateEndTimeInputMinTime=K,te.$onDestroy=X,function(){n("RequestModalDetails"+e.capitalize(C(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",te),I(),te.initChildController().then(function(){return i.all([x(),M()])}).then(!te.isMode("create")&&A).then(H).then(function(){if(!te.isMode("create"))return i.resolve().then(te.initTimesExtended).then(V)}).then(!te.isMode("create")&&W).then(w).then(G).then(R).then(O).then(!te.isMode("view")&&te.initWatchersExtended).catch(P).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l){function d(){return O.fileUploader&&O.fileUploader.queue.length>0}function m(){return O.getFilesAmount()0?A.map(function(e){return e.label}).join(", "):""}function q(){return O.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(A.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){w[e.label]=t})})).catch(function(){w=null})}function D(){return c.valuesOf("safe_file_extension").then(function(e){A=e})}function T(e){return!e.attachment_id||O.canManage}function P(){e.forEach(I,function(e){e()})}function R(e,t){O.fileUploader.queue&&O.fileUploader.queue.length>0?O.fileUploader.uploadAll({entityID:O.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var A=[],I=[],w={},O=Object.create(this);return O.filesLoaded=!1,O.fileUploader=null,O.today=Date.now(),O.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",O.userDateFormat=i.DATE_FORMAT,O.$onDestroy=P,O.canRemoveAttachment=T,O.canSubmit=d,O.canUploadMore=m,O.formatDateTime=f,O.getAuthorName=p,O.getFilesAmount=h,O.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",O),g(),a.all([D(),q()]).then(_).finally(function(){O.filesLoaded=!0})}(),O}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,o){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],s.openLeavePopup=a,function(){o=n.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,o,s,i,r,c,u,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var t=j[e.status];t?t(e.leaveRequest):W.refresh()}function b(t){t.dataIndex=e.indexBy(t.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return i.all().then(i.loadCalculationUnits).then(function(t){W.absenceTypes=t,W.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return A("approved",{status_id:N(m.statusNames.approved)})}function C(){return n.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[N(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[N(m.statusNames.awaitingApproval),N(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function D(){return r.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(t){var n=e.find(W.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function T(){return r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return M(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function P(){return n.all([r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),R({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:M(e[0]),expiredTOILS:x(e[1].list)})}).then(function(t){W.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function R(t){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function A(e,t){return R(t).then(function(t){W.sections[e].data=t.list})}function I(){return n.all(Object.values(W.sections).filter(function(e){return e.open}).map(L))}function w(){return A("other",{status_id:{in:[N(m.statusNames.rejected),N(m.statusNames.cancelled)]}})}function O(){return A("pending",{status_id:{in:[N(m.statusNames.awaitingApproval),N(m.statusNames.moreInformationRequired)]}})}function S(){return A("holidays",{public_holiday:!0})}function L(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function k(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){W.leaveRequestStatuses=e.indexBy(t,"value")})}function M(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(W.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function x(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function $(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(W.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],B(t,a))})}function B(e,t){var n=W.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function U(){W.loading.content=!0,n.all([D(),C()]).then(function(){W.loading.content=!1}).then(function(){return n.all([I(),h()])})}function F(e){var t=W.sections[e];t.open=!t.open,t.open&&!t.data.length&&L(t)}function N(t){return e.find(W.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var j={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:T},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:P},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w}},W.labelPeriod=g,W.refresh=U,W.toggleSection=F,function(){n.all([k(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return n.all([D(),C()])}).then(function(){W.loading.content=!1}),$()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report", -controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function u(){var e=i.request,t=!!e.from_date&&!!e.to_date,n=i.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return i.canCalculateChange()}function d(t,n){var a=i.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);i.uiOptions.multipleDays||("from"===t&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=i.convertDateToServerFormat(t),r.isPublicHoliday(t).then(function(n){return n?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,i.requestDayTypes).then(function(t){return t.length?t:i.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return R(n,e),e})):o.reject([])}function f(e,n){return e=t(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return o.resolve()}function v(){return C(i.uiOptions.fromDate,"from").then(function(){return C(i.uiOptions.toDate,"to")})}function b(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,t){i.isCalculationUnit("days")||+e==+t||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function g(e){var n=t(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),i.uiOptions.times[e].time=n}function _(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],t=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(T)).then(function(){["from","to"].forEach(function(e){g(e),I(e),t[e].amount=Math.min(i.request[e+"_date_amount"],t[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function y(){["from","to"].forEach(function(e){b(e),q(e)})}function q(e){s.$watch(function(){return i.uiOptions.times[e].time},function(t,n){i.isCalculationUnit("days")||t===n||(i.setRequestDateTimesAndDateTypes(),t&&I(e,!0))})}function C(e,t){return m(e,t).then(function(){i.loading[t+"DayTypes"]=!1})}function D(e){return C(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return T(e).then(function(){I(e,!0)})})}function T(e){var t=i.uiOptions[e+"Date"],n=!i.uiOptions.multipleDays;return t?i.request.getWorkDayForDate(i.convertDateToServerFormat(t)).then(function(t){S[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return S[e]={},i.handleError(t)}).finally(function(){n&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(t){var n=i.uiOptions.times[t];i["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function R(t,n){var a="request"+e.startCase(t)+"DayTypes";i[a]=n,i.isMode("create")&&(i.request[t+"_date_type"]=i[a][0].value)}function A(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),T("from").then(function(){I("from",!0)})):o.resolve()}function I(e,t){var n=i.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,c=S[a].number_of_hours?p(s,r).toString():"0";o.maxAmount=c,t&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function O(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?T("from").then(function(){I("from",!0)}):o.resolve()}var S={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=c,i.canCalculateChange=u,i.canSubmit=l,i.initChildController=h,i.initDayTypesExtended=v,i.initTimesExtended=_,i.initWatchersExtended=y,i.onAbsenceTypeUpdateExtended=O,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=A}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function i(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function r(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=i,s.initChildController=r,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=t.duration(t(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,t=!c.uiOptions.multipleDays&&!!c.request.from_date,n=t||e,a=E.from_date!==c.request.from_date||E.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&n&&U.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,t=c.request;return b({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function b(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&U.hasExpirationFromAdminSettings,t=U.hasPreviousExpirationDate,n=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=n&&(a||e||t)}function _(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function y(){return U.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){U.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",y().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function D(){o.$watch(function(){return c.request.toil_to_accrue},function(e,t){+e!=+t&&c.performBalanceChangeCalculation()})}function T(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,t){c.isCalculationUnit("hours")&&e!==t&&(c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function P(){var e=c.uiOptions.times;e.from.time=t(c.request.from_date).format("HH:mm"),e.to.time=t(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,t){e!==t&&(c.setRequestDateTimesAndDateTypes(),x(),l(),S())})})}function A(){c.isMode("view")||(D(),T(),R())}function I(t){return i.valuesOf("hrleaveandabsences_toil_amounts",{},t).then(function(t){c.toilAmounts=e.sortBy(t,"value")})}function w(){return l(),S(),x()}function O(){return k(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),B?B=!1:S(),x()}function S(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function L(){E=e.cloneDeep(c.request.attributes())}function k(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function M(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){I(!1)})}function x(){return f()?d().catch(a.resolve):a.resolve()}function $(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var E,B=!c.isMode("create"),U={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=P,c.initWatchersExtended=A,c.onDateChangeExtended=w,c.openToilInDaysAccrualOptionsEditor=M,c.setDaysSelectionModeExtended=O,c.updateExpiryDate=$,function(){L(),k(),!c.isMode("create")&&_()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,D){function T(e){"days"===xe.selectedAbsenceType.calculation_unit_name?delete xe.request[e+"_date_amount"]:delete xe.request[e+"_date_type"]}function P(){["from","to"].forEach(T)}function R(){var e=xe.requestStatuses[y.statusNames.awaitingApproval].value;we.status_id===e&&e!==xe.request.status_id&&d.publish("ManagerBadge:: Update Count")}function A(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!xe.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function O(){var e=A();return xe.isMode("edit")&&(e=e&&(G()||I())),xe.canManage&&xe.requestStatuses&&(e=e&&!!xe.getStatusFromValue(xe.newStatusOnSave)),(e=e&&!!xe.period.id)&&!xe.isMode("view")}function S(){xe.isSelfRecord?xe.request.status_id=xe.requestStatuses[y.statusNames.awaitingApproval].value:xe.canManage&&(xe.request.status_id=xe.newStatusOnSave||xe.request.status_id)}function L(){if(xe.isMode("edit")&&!xe.isRole("staff")&&"toil"!==N())return xe.request.calculateBalanceChange(xe.selectedAbsenceType.calculation_unit_name).then(function(e){if(+xe.balance.change.amount!=+e.amount)return D.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function k(){xe.errors=[]}function M(){return xe.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function x(){ee()&&!xe.isRole("staff")&&(xe.request.change_balance=!0)}function $(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return xe.request.delete().then(function(){xe.dismissModal(),d.publish("LeaveRequest::delete",xe.request)})}})}function E(){r.dismiss({$value:"cancel"})}function B(){var e=N();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return F(xe.getStatusFromValue(xe.request.status_id).name)}function F(e){return n.map(Ae[e],function(e){return xe.requestStatuses[e]})}function N(){return xe.request?xe.request.request_type:xe.leaveType||null}function j(){return!xe.request||e.equals({},xe.requestStatuses)?[]:xe.request.status_id?U():F("none")}function W(e){return n.find(xe.requestStatuses,function(t){return t.value===e})}function H(e){xe.errors=n.isArray(e)?e:[e],xe.loading.absenceTypes=!1,xe.submitting=!1}function G(){return!e.equals(we,xe.request.attributes())||xe.canManage&&xe.newStatusOnSave}function Y(){return xe.postContactSelection=!0,xe.staffMemberSelectionComplete=!1,xe.request.contact_id?o.resolve().then(re).then(ce).then(he).then(be).then(Z).then(z).then(xe.isMode("edit")?ge:n.noop).then(function(){xe.postContactSelection=!1,xe.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Le)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Ae.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Ae.awaiting_approval=e,Ae.more_information_required=e,Ae.rejected=e,Ae.approved=e,Ae.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return xe.canManage?f.find(xe.request.contact_id).then(function(e){xe.contactName=e.display_name}):o.resolve()}function X(){Oe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",xe.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Ie++})),i.$on("$destroy",De),i.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function Q(){var e,t;xe.request=xe.leaveRequest||null,e=N(),t=xe.initRequestAttributes(),"leave"===e?xe.request=_.init(t):"sickness"===e?xe.request=q.init(t):"toil"===e&&(xe.request=C.init(t))}function J(){var e={};return xe.request?e=xe.request.attributes():xe.canManage||(e={contact_id:Se}),e}function K(){if(ke="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(ke="admin")}).then(function(){return"staff"===ke&&c(y.permissions.ssp.manage).then(function(e){e&&(ke="manager")})}).finally(function(){xe.canManage=xe.isRole("manager")||xe.isRole("admin")})}function Z(){(xe.isRole("admin")||xe.isMode("create")&&xe.isRole("manager"))&&(xe.newStatusOnSave=xe.requestStatuses[y.statusNames.approved].value)}function ee(){return!xe.request.status_id||!n.includes(["cancelled","rejected"],W(xe.request.status_id).name)}function te(e){var t=xe.getStatusFromValue(xe.request.status_id);return!!t&&t.name===e}function ne(e){return xe.request&&xe.request.request_type===e}function ae(e){return xe.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return ke===e}function ie(){return h.all().then(function(e){xe.absencePeriods=e})}function re(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Re={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return xe.loading.entitlements=!0,b.all({contact_id:xe.request.contact_id,period_id:xe.period.id,type_id:{IN:Re.ids}},!0).finally(function(){xe.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Se=e.contactId})}function le(){return xe.selectedContactId?f.find(xe.selectedContactId).then(function(e){xe.managedContacts=[e]}):xe.isRole("admin")?f.all().then(function(e){xe.managedContacts=n.remove(e.list,function(e){return e.id!==Se})}):f.find(Se).then(function(e){return e.leaveManagees()}).then(function(e){xe.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){xe.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){R(),d.publish(e,xe.request),xe.errors=[],xe.dismissModal()}function pe(){["from","to"].forEach(function(e){xe.request[e+"_date"]=we[e+"_date"]})}function he(e){if(xe.absenceTypes=me(Re.types,e),!xe.absenceTypes.length)return o.reject(Le)}function ve(){xe.period=n.find(xe.absencePeriods,function(e){return xe.isMode("create")?e.current:oe(xe.request,e)})}function be(){xe.isMode("create")?(xe.selectedAbsenceType=xe.absenceTypes[0],xe.request.type_id=xe.selectedAbsenceType.id):xe.selectedAbsenceType=n.find(xe.absenceTypes,function(e){return e.id===xe.request.type_id})}function ge(){we=e.copy(xe.request.attributes())}function _e(){var e;xe.request.id?(e=[xe.requestStatuses[y.statusNames.approved].value,xe.requestStatuses[y.statusNames.adminApproved].value,xe.requestStatuses[y.statusNames.rejected].value,xe.requestStatuses[y.statusNames.cancelled].value],xe.mode="edit",xe.isRole("staff")&&e.indexOf(xe.request.status_id)>-1&&(xe.mode="view")):xe.mode="create"}function ye(){var e=xe.request.status_id;if(!xe.isMode("view")&&!xe.submitting)return xe.submitting=!0,S(),P(),xe.request.isValid().then(ee()&&L).then(x).then(!xe.request.change_balance&&pe).then(qe).then(function(){return xe.isMode("edit")?Pe():M()}).catch(function(t){xe.request.status_id=e,t&&H(t)}).finally(function(){xe.submitting=!1})}function qe(){return o.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===Ie&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return Ie>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function De(){Oe.forEach(function(e){e()})}function Te(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Pe(){return xe.request.update().then(Ce).then(function(){xe.isRole("manager")?fe("LeaveRequest::updatedByManager"):(xe.isRole("staff")||xe.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Re,Ae={},Ie=0,we={},Oe=[],Se="",Le="No entitlement",ke="",Me=[],xe=n.assign(this,m);xe.absencePeriods=[],xe.absenceTypes=[],xe.canManage=!1,xe.contactName=null,xe.errors=[],xe.loading={absenceTypes:!0,entitlements:!0},xe.managedContacts=[],xe.mode="",xe.newStatusOnSave=null,xe.period={},xe.postContactSelection=!1,xe.requestStatuses={},xe.selectedAbsenceType={},xe.staffMemberSelectionComplete=!1,xe.submitting=!1,xe.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},xe.canChangeAbsenceType=w,xe.canSubmit=O,xe.closeAlert=k,xe.deleteLeaveRequest=$,xe.dismissModal=E,xe.getStatuses=j,xe.getStatusFromValue=W,xe.initAfterContactSelection=Y,xe.initRequestAttributes=J,xe.isLeaveStatus=te,xe.isLeaveType=ne,xe.isMode=ae,xe.isRole=se,xe.submit=ye,xe.updateAbsenceType=Te,function(){xe.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),ie(),de()]).then(Q).then(_e).then(ve).then(function(){return xe.canManage&&!xe.isMode("edit")&&le()}).then(function(){if(xe.selectedContactId&&(xe.request.contact_id=xe.selectedContactId),xe.request.contact_id)return xe.initAfterContactSelection()}).catch(H).finally(function(){xe.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,i,r,c){function u(e){return r.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,i,r){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:i,forceRecalculateBalanceChange:r}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,i){function r(e){l.errorMessage=e}function c(){return i.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrjc_revision_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,i.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(r).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrjc_revision_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(), -g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){r.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){i.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i){function r(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,i){n=o.entitlements.slice(0,i),a=e.entitlements.slice(i+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,i;return s=e.indexBy(n,"entitlement_id.type_id"),i=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:i}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t];e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,i){o.comment&&(t=s.concat(o).concat(i),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(r).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,i,r,c,u,l,d){function m(){D.absencePeriods=t.chain(D.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){D.absenceTypes=t.filter(D.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:D.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:D.contactId,returnUrl:n})}function h(){return c.all().then(function(e){D.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:D.contactId}).then(function(e){q=e})}function g(e){i.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=D.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){D.absencePeriods=t.map(D.absencePeriods,function(e){var n=t.map(D.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

    Last updated:
    By: "+e.author_name+"
    Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
    ";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],D=this;D.absencePeriods=[],D.loading={absencePeriods:!0},D.getEditEntitlementsPageURL=p,D.openAnnualEntitlementChangeLog=g,D.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){D.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i,r){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return i.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){r.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); +controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function u(){var e=i.request,t=!!e.from_date&&!!e.to_date,n=i.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return i.canCalculateChange()}function d(t,n){var a=i.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);i.uiOptions.multipleDays||("from"===t&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=i.convertDateToServerFormat(t),r.isPublicHoliday(t).then(function(n){return n?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,i.requestDayTypes).then(function(t){return t.length?t:i.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return R(n,e),e})):o.reject([])}function f(e,n){return e=t(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return o.resolve()}function v(){return C(i.uiOptions.fromDate,"from").then(function(){return C(i.uiOptions.toDate,"to")})}function b(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,t){i.isCalculationUnit("days")||+e==+t||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function g(e){var n=t(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),i.uiOptions.times[e].time=n}function _(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],t=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(T)).then(function(){["from","to"].forEach(function(e){g(e),I(e),t[e].amount=Math.min(i.request[e+"_date_amount"],t[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function y(){["from","to"].forEach(function(e){b(e),q(e)})}function q(e){s.$watch(function(){return i.uiOptions.times[e].time},function(t,n){i.isCalculationUnit("days")||t===n||(i.setRequestDateTimesAndDateTypes(),t&&I(e,!0))})}function C(e,t){return m(e,t).then(function(){i.loading[t+"DayTypes"]=!1})}function D(e){return C(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return T(e).then(function(){I(e,!0)})})}function T(e){var t=i.uiOptions[e+"Date"],n=!i.uiOptions.multipleDays;return t?i.request.getWorkDayForDate(i.convertDateToServerFormat(t)).then(function(t){S[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return S[e]={},i.handleError(t)}).finally(function(){n&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(t){var n=i.uiOptions.times[t];i["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function R(t,n){var a="request"+e.startCase(t)+"DayTypes";i[a]=n,i.isMode("create")&&(i.request[t+"_date_type"]=i[a][0].value)}function A(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),T("from").then(function(){I("from",!0)})):o.resolve()}function I(e,t){var n=i.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,c=S[a].number_of_hours?p(s,r).toString():"0";o.maxAmount=c,t&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function O(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?T("from").then(function(){I("from",!0)}):o.resolve()}var S={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=c,i.canCalculateChange=u,i.canSubmit=l,i.initChildController=h,i.initDayTypesExtended=v,i.initTimesExtended=_,i.initWatchersExtended=y,i.onAbsenceTypeUpdateExtended=O,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=A}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function i(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function r(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=i,s.initChildController=r,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=t.duration(t(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,t=!c.uiOptions.multipleDays&&!!c.request.from_date,n=t||e,a=B.from_date!==c.request.from_date||B.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&n&&F.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,t=c.request;return b({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function b(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&F.hasExpirationFromAdminSettings,t=F.hasPreviousExpirationDate,n=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=n&&(a||e||t)}function _(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function y(){return F.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){F.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",y().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function D(){o.$watch(function(){return c.request.toil_to_accrue},function(e,t){+e!=+t&&c.performBalanceChangeCalculation()})}function T(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,t){c.isCalculationUnit("hours")&&e!==t&&(c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function P(){var e=c.uiOptions.times;e.from.time=t(c.request.from_date).format("HH:mm"),e.to.time=t(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,t){e!==t&&(c.setRequestDateTimesAndDateTypes(),$(),l(),S())})})}function A(){c.isMode("view")||(D(),T(),R())}function I(t){return i.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){c.toilAmounts=e.sortBy(t,"value")})}function w(){return l(),S(),$()}function O(){return k(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),U?U=!1:S(),$()}function S(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function L(){B=e.cloneDeep(c.request.attributes())}function k(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function M(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){I(!1)})}function x(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function $(){return f()?d().catch(a.resolve):a.resolve()}function E(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var B,U=!c.isMode("create"),F={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=P,c.initWatchersExtended=A,c.onDateChangeExtended=w,c.openToilInDaysAccrualOptionsEditor=M,c.setDaysSelectionModeExtended=O,c.updateExpiryDate=E,function(){L(),k(),x(),!c.isMode("create")&&_()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,D){function T(e){"days"===xe.selectedAbsenceType.calculation_unit_name?delete xe.request[e+"_date_amount"]:delete xe.request[e+"_date_type"]}function P(){["from","to"].forEach(T)}function R(){var e=xe.requestStatuses[y.statusNames.awaitingApproval].value;we.status_id===e&&e!==xe.request.status_id&&d.publish("ManagerBadge:: Update Count")}function A(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!xe.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function O(){var e=A();return xe.isMode("edit")&&(e=e&&(G()||I())),xe.canManage&&xe.requestStatuses&&(e=e&&!!xe.getStatusFromValue(xe.newStatusOnSave)),(e=e&&!!xe.period.id)&&!xe.isMode("view")}function S(){xe.isSelfRecord?xe.request.status_id=xe.requestStatuses[y.statusNames.awaitingApproval].value:xe.canManage&&(xe.request.status_id=xe.newStatusOnSave||xe.request.status_id)}function L(){if(xe.isMode("edit")&&!xe.isRole("staff")&&"toil"!==N())return xe.request.calculateBalanceChange(xe.selectedAbsenceType.calculation_unit_name).then(function(e){if(+xe.balance.change.amount!=+e.amount)return D.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function k(){xe.errors=[]}function M(){return xe.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function x(){ee()&&!xe.isRole("staff")&&(xe.request.change_balance=!0)}function $(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return xe.request.delete().then(function(){xe.dismissModal(),d.publish("LeaveRequest::delete",xe.request)})}})}function E(){r.dismiss({$value:"cancel"})}function B(){var e=N();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return F(xe.getStatusFromValue(xe.request.status_id).name)}function F(e){return n.map(Ae[e],function(e){return xe.requestStatuses[e]})}function N(){return xe.request?xe.request.request_type:xe.leaveType||null}function j(){return!xe.request||e.equals({},xe.requestStatuses)?[]:xe.request.status_id?U():F("none")}function W(e){return n.find(xe.requestStatuses,function(t){return t.value===e})}function H(e){xe.errors=n.isArray(e)?e:[e],xe.loading.absenceTypes=!1,xe.submitting=!1}function G(){return!e.equals(we,xe.request.attributes())||xe.canManage&&xe.newStatusOnSave}function Y(){return xe.postContactSelection=!0,xe.staffMemberSelectionComplete=!1,xe.request.contact_id?o.resolve().then(re).then(ce).then(he).then(be).then(Z).then(z).then(xe.isMode("edit")?ge:n.noop).then(function(){xe.postContactSelection=!1,xe.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Le)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Ae.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Ae.awaiting_approval=e,Ae.more_information_required=e,Ae.rejected=e,Ae.approved=e,Ae.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return xe.canManage?f.find(xe.request.contact_id).then(function(e){xe.contactName=e.display_name}):o.resolve()}function X(){Oe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",xe.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Ie++})),i.$on("$destroy",De),i.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function Q(){var e,t;xe.request=xe.leaveRequest||null,e=N(),t=xe.initRequestAttributes(),"leave"===e?xe.request=_.init(t):"sickness"===e?xe.request=q.init(t):"toil"===e&&(xe.request=C.init(t))}function J(){var e={};return xe.request?e=xe.request.attributes():xe.canManage||(e={contact_id:Se}),e}function K(){if(ke="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(ke="admin")}).then(function(){return"staff"===ke&&c(y.permissions.ssp.manage).then(function(e){e&&(ke="manager")})}).finally(function(){xe.canManage=xe.isRole("manager")||xe.isRole("admin")})}function Z(){(xe.isRole("admin")||xe.isMode("create")&&xe.isRole("manager"))&&(xe.newStatusOnSave=xe.requestStatuses[y.statusNames.approved].value)}function ee(){return!xe.request.status_id||!n.includes(["cancelled","rejected"],W(xe.request.status_id).name)}function te(e){var t=xe.getStatusFromValue(xe.request.status_id);return!!t&&t.name===e}function ne(e){return xe.request&&xe.request.request_type===e}function ae(e){return xe.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return ke===e}function ie(){return h.all().then(function(e){xe.absencePeriods=e})}function re(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Re={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return xe.loading.entitlements=!0,b.all({contact_id:xe.request.contact_id,period_id:xe.period.id,type_id:{IN:Re.ids}},!0).finally(function(){xe.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Se=e.contactId})}function le(){return xe.selectedContactId?f.find(xe.selectedContactId).then(function(e){xe.managedContacts=[e]}):xe.isRole("admin")?f.all().then(function(e){xe.managedContacts=n.remove(e.list,function(e){return e.id!==Se})}):f.find(Se).then(function(e){return e.leaveManagees()}).then(function(e){xe.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){xe.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){R(),d.publish(e,xe.request),xe.errors=[],xe.dismissModal()}function pe(){["from","to"].forEach(function(e){xe.request[e+"_date"]=we[e+"_date"]})}function he(e){if(xe.absenceTypes=me(Re.types,e),!xe.absenceTypes.length)return o.reject(Le)}function ve(){xe.period=n.find(xe.absencePeriods,function(e){return xe.isMode("create")?e.current:oe(xe.request,e)})}function be(){xe.isMode("create")?(xe.selectedAbsenceType=xe.absenceTypes[0],xe.request.type_id=xe.selectedAbsenceType.id):xe.selectedAbsenceType=n.find(xe.absenceTypes,function(e){return e.id===xe.request.type_id})}function ge(){we=e.copy(xe.request.attributes())}function _e(){var e;xe.request.id?(e=[xe.requestStatuses[y.statusNames.approved].value,xe.requestStatuses[y.statusNames.adminApproved].value,xe.requestStatuses[y.statusNames.rejected].value,xe.requestStatuses[y.statusNames.cancelled].value],xe.mode="edit",xe.isRole("staff")&&e.indexOf(xe.request.status_id)>-1&&(xe.mode="view")):xe.mode="create"}function ye(){var e=xe.request.status_id;if(!xe.isMode("view")&&!xe.submitting)return xe.submitting=!0,S(),P(),xe.request.isValid().then(ee()&&L).then(x).then(!xe.request.change_balance&&pe).then(qe).then(function(){return xe.isMode("edit")?Pe():M()}).catch(function(t){xe.request.status_id=e,t&&H(t)}).finally(function(){xe.submitting=!1})}function qe(){return o.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===Ie&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return Ie>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function De(){Oe.forEach(function(e){e()})}function Te(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Pe(){return xe.request.update().then(Ce).then(function(){xe.isRole("manager")?fe("LeaveRequest::updatedByManager"):(xe.isRole("staff")||xe.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Re,Ae={},Ie=0,we={},Oe=[],Se="",Le="No entitlement",ke="",Me=[],xe=n.assign(this,m);xe.absencePeriods=[],xe.absenceTypes=[],xe.canManage=!1,xe.contactName=null,xe.errors=[],xe.loading={absenceTypes:!0,entitlements:!0},xe.managedContacts=[],xe.mode="",xe.newStatusOnSave=null,xe.period={},xe.postContactSelection=!1,xe.requestStatuses={},xe.selectedAbsenceType={},xe.staffMemberSelectionComplete=!1,xe.submitting=!1,xe.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},xe.canChangeAbsenceType=w,xe.canSubmit=O,xe.closeAlert=k,xe.deleteLeaveRequest=$,xe.dismissModal=E,xe.getStatuses=j,xe.getStatusFromValue=W,xe.initAfterContactSelection=Y,xe.initRequestAttributes=J,xe.isLeaveStatus=te,xe.isLeaveType=ne,xe.isMode=ae,xe.isRole=se,xe.submit=ye,xe.updateAbsenceType=Te,function(){xe.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),ie(),de()]).then(Q).then(_e).then(ve).then(function(){return xe.canManage&&!xe.isMode("edit")&&le()}).then(function(){if(xe.selectedContactId&&(xe.request.contact_id=xe.selectedContactId),xe.request.contact_id)return xe.initAfterContactSelection()}).catch(H).finally(function(){xe.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,i,r,c){function u(e){return r.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,i,r){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:i,forceRecalculateBalanceChange:r}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,i){function r(e){l.errorMessage=e}function c(){return i.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrjc_revision_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,i.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(r).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrjc_revision_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"}) +;return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(),g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){r.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){i.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i){function r(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,i){n=o.entitlements.slice(0,i),a=e.entitlements.slice(i+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,i;return s=e.indexBy(n,"entitlement_id.type_id"),i=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:i}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t];e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,i){o.comment&&(t=s.concat(o).concat(i),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(r).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,i,r,c,u,l,d){function m(){D.absencePeriods=t.chain(D.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){D.absenceTypes=t.filter(D.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:D.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:D.contactId,returnUrl:n})}function h(){return c.all().then(function(e){D.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:D.contactId}).then(function(e){q=e})}function g(e){i.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=D.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){D.absencePeriods=t.map(D.absencePeriods,function(e){var n=t.map(D.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

    Last updated:
    By: "+e.author_name+"
    Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
    ";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],D=this;D.absencePeriods=[],D.loading={absencePeriods:!0},D.getEditEntitlementsPageURL=p,D.openAnnualEntitlementChangeLog=g,D.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){D.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i,r){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return i.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){r.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js index 39c494d1095..2e7963f07f9 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js @@ -8,7 +8,7 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),w.current)}).then(null,function(a){return a===D?S:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:S(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function M(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function L(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;aWhen All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){E.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){E.selectedMonths=[n().month()]}function T(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=D,function(){T().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",L)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([O(),T()]).then(g).then(M).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function M(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function L(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}), -define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function S(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function T(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function L(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:L},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),E()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(S).then(V).then(P).then(T).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||T.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=w,T.canRemoveAttachment=A,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=h,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:E(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:L(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function E(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function M(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function L(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=M(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=h,U.getAbsenceTypeByID=v,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=x,U.refresh=k,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),O(),P(),S(),R(),I()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),S(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(S)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function S(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function T(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=T,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=k.from_date!==u.request.from_date||k.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&B.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&B.hasExpirationFromAdminSettings,t=B.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return B.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){B.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),M(),l(),O())})})} -function D(){u.isMode("view")||(C(),A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",{},t).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function S(){return l(),O(),M()}function T(){return x(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),j?j=!1:O(),M()}function O(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function I(){k=e.cloneDeep(u.request.attributes())}function x(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function E(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){R(!1)})}function M(){return m()?d().catch(a.resolve):a.resolve()}function L(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var k,j=!u.isMode("create"),B={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=S,u.openToilInDaysAccrualOptionsEditor=E,u.setDaysSelectionModeExtended=T,u.updateExpiryDate=L,function(){I(),x(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,r,o){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(o.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==F())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function E(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function L(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function F(){return Me.request?Me.request.request_type:Me.leaveType||null}function U(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Se,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=F(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Me.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Se[e+"_date"]})}function he(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function ve(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Se=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():E()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Ee=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=S,Me.canSubmit=T,Me.closeAlert=x,Me.deleteLeaveRequest=L,Me.dismissModal=k,Me.getStatuses=U,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(t){return t.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM), -define("leave-absences/admin-dashboard/modules/config",["common/angular","leave-absences/admin-dashboard/modules/settings"],function(e){return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(e,t,n,a,r,o){var s={format:["DateFormat",function(e){return e.getDateFormat()}]};r.debugEnabled(o.debug),t.defaults.stripTrailingSlashes=!1,a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:s}).state("calendar",{url:"/calendar",template:'',resolve:s}).state("leave-balances",{url:"/leave-balances",template:"",resolve:s})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function t(e,t){e.debug("Component: admin-dashboard-container"),t.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",t]})}),define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/admin-dashboard":n+"/admin-dashboard"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); +define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function S(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function T(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function L(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:L},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),E()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(S).then(V).then(P).then(T).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||T.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=w,T.canRemoveAttachment=A,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=h,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:E(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:L(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function E(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function M(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function L(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=M(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=h,U.getAbsenceTypeByID=v,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=x,U.refresh=k,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),O(),P(),S(),R(),I()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),S(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(S)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function S(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function T(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=T,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=j.from_date!==u.request.from_date||j.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&N.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&N.hasExpirationFromAdminSettings,t=N.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return N.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){N.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),L(),l(),O())})})}function D(){u.isMode("view")||(C(), +A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function S(){return l(),O(),L()}function T(){return x(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),B?B=!1:O(),L()}function O(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function I(){j=e.cloneDeep(u.request.attributes())}function x(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function E(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){R(!1)})}function M(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function L(){return m()?d().catch(a.resolve):a.resolve()}function k(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var j,B=!u.isMode("create"),N={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=S,u.openToilInDaysAccrualOptionsEditor=E,u.setDaysSelectionModeExtended=T,u.updateExpiryDate=k,function(){I(),x(),M(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,r,o){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(o.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==F())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function E(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function L(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function F(){return Me.request?Me.request.request_type:Me.leaveType||null}function U(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Se,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=F(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Me.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Se[e+"_date"]})}function he(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function ve(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Se=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():E()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Ee=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=S,Me.canSubmit=T,Me.closeAlert=x,Me.deleteLeaveRequest=L,Me.dismissModal=k,Me.getStatuses=U,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(t){return t.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug, +pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM),define("leave-absences/admin-dashboard/modules/config",["common/angular","leave-absences/admin-dashboard/modules/settings"],function(e){return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(e,t,n,a,r,o){var s={format:["DateFormat",function(e){return e.getDateFormat()}]};r.debugEnabled(o.debug),t.defaults.stripTrailingSlashes=!1,a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:s}).state("calendar",{url:"/calendar",template:'',resolve:s}).state("leave-balances",{url:"/leave-balances",template:"",resolve:s})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function t(e,t){e.debug("Component: admin-dashboard-container"),t.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",t]})}),define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/admin-dashboard":n+"/admin-dashboard"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js index ee65d4b8eb9..fcb5fb68730 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js @@ -9,6 +9,6 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))h.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),h.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var v=s(u||{}),h=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+h.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,v)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,v)),m.$$inheritedValues=f(o.$$values,v),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,v)),o.then(i,u));for(var q=0,$=h.length;q<$;q+=3)a.hasOwnProperty(h[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(h[q],h[q+1],h[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(h.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(v[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return v[t]=new Y.Param(t,n,a,r),v[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},v=this.params=r?r.params.$$new():new Y.ParamSet,h=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=h}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:v,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,v=!0,h=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(v=e),v},this.defaultSquashPolicy=function(e){if(!j(e))return h;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return h=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!v.type.is(e))throw new Error("Default value ("+e+") for parameter '"+v.id+"' is not an instance of Type ("+v.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(v.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?v.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var v=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return h;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),h(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=L[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&h.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),h.update(!0),w.current)}).then(null,function(a){return a===D?S:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||h.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==v){d=n.$new(),v=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(h)}}var f,m,p,v,h=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:S(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function L(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function M(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return v.push(u),h[s]=r,function(){var e=v.indexOf(u);-1!==e&&v.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function E(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),h.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",h),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n){function a(e){e.absencePeriods&&c.absencePeriods.length&&(c.filters.period_id=o().id),e.absenceTypes&&c.absenceTypes.length&&(c.filters.type_id=s().id),(e.loggedInContactId||e.userRole)&&(c.filters.managed_by="manager"===c.userRole?c.loggedInContactId:void 0),r()&&c.submitFilters()}function r(){return e.every(c.filters,function(e){return null!==e})}function o(){return e.find(c.absencePeriods,function(e){return e.current})||c.absencePeriods.reduce(function(e,n){return t(e.end_date).isAfter(n.end_date)?e:n})}function s(){return c.absenceTypes.reduce(function(e,t){return e.title.localeCompare(t.title)?e:t})}function i(e){return e.current?"Current Period ("+e.title+")":e.title}function u(){n.$emit("LeaveBalanceFilters::update",c.filters)}var c=this;c.filters={period_id:null,type_id:null,managed_by:null},c.$onChanges=a,c.labelPeriod=i,c.submitFilters=u}n.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,t){return e.extend({all:function(e,n,a,r,o){return t.getLeaveBalances(this.processFilters(e),n,a,r,o)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){return r.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function p(){return o.all().then(o.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function v(){return s.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function h(){return n.all([m(),p(),v(),g(),q()]).catch(function(e){u.error("Error",e)})}function g(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function b(){return P.loading.report=!0,i.all(w,P.pagination,void 0,void 0,!1).then(function(e){P.report=y(e.list),P.reportCount=e.total}).catch(function(e){u.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function y(n){return n.map(function(n){return n=e.copy(n),n.absence_types=t.indexBy(n.absence_types,function(e){return e.id}),n})}function _(){a.$on("LeaveBalanceFilters::update",C),c.subscribe("LeaveRequest::new",$)}function q(){return f(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function $(e){C(e,w)}function C(e,t){w=t,P.pagination.page=1,A(),P.loadReportCurrentPage()}function A(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+w.type_id})}var w={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.loadReportCurrentPage=b,function(){_(),h().then(function(){P.loading.component=!1})}()}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(h.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(h.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=h.filters.userSettings.assignedTo.type;return f(e).then(function(e){h.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return h.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(m(),null,"display_name").then(function(e){return e.list})}function d(){return v?a.resolve(v):s.all()}function f(e){return"me"===e?r.leaveManagees(h.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function m(){return{department:h.filters.userSettings.department?h.filters.userSettings.department.value:null,level_type:h.filters.userSettings.level_type?h.filters.userSettings.level_type.value:null,location:h.filters.userSettings.location?h.filters.userSettings.location.value:null,region:h.filters.userSettings.region?h.filters.userSettings.region.value:null,id:{IN:h.filters.userSettings.contact?[h.filters.userSettings.contact.id]:h.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var v,h;return{init:function(e){return h=e,h.showContactDetailsLink=!0,h.showContactName=!0,h.showFilters=!0,h.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],h.filters.userSettings.assignedTo=h.filtersByAssignee[0],h.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(L.selectedPeriod.start_date).clone().startOf("month"),a=n(L.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");L.months=e}function p(){s.$new().$watch(function(){return L.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function v(e){L.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){L.loading.calendar=!1})}function h(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(L)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){L.absencePeriods=t.sortBy(e,"start_date"),L.selectedPeriod=t.find(L.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){L.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){L.filters.optionValues.regions=e.hrjc_region,L.filters.optionValues.locations=e.hrjc_location,L.filters.optionValues.levelTypes=e.hrjc_level_type,L.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){L.supportData.absenceTypes=e[0],L.supportData.publicHolidays=e[1],L.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,L.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,L.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,L.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return L.injectMonths&&(e=O("destroyed"),L.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){L.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){v("contacts"===e)})}function R(e){var n=L.selectedMonths.length?L.months.filter(function(e){return t.includes(L.selectedMonths,e.index)}):L.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){L.selectedMonths=[n().month()]}function T(){return L.roleOverride?r.resolve().then(function(){x=L.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===L.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,L=this;L.absencePeriods=[],L.contacts=[],L.contactIdsToReduceTo=null,L.injectMonths=!1,L.months=[],L.selectedMonths=null,L.selectedPeriod=null,L.showContactName=!1,L.showFilters=!1,L.supportData={},L.loading={calendar:!0,page:!0},L.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},L.labelPeriod=g,L.refresh=D,function(){T().then(p).then(h).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return L.showFilters?$():t.noop}).then(function(){v()}).then(function(){L.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function v(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function h(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),v())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){h()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function v(e){I(e),B(e)}function h(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",E)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",v)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?v(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([O(),T()]).then(g).then(M).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function L(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function M(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return L(e,t.id)}))}))}function E(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(v(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return L(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=h,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}), define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(v(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):v(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function v(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function h(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=h,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function v(e){return q.mode===e}function h(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=v,q.onBeforeSubmit=h,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function v(e){return t(e).format(u.serverDateFormat)}function h(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function S(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function T(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function L(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function E(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return v(te.request.from_date)===v(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?v(e.fromDate):null,te.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:E},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=v,te.dateChangeHandler=h,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),L()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(S).then(V).then(P).then(T).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||T.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=w,T.canRemoveAttachment=A,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=v,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function v(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function h(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:L(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:E(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function L(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function M(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function E(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=M(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=v,U.getAbsenceTypeByID=h,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=x,U.refresh=k,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),O(),P(),S(),R(),I()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function v(){return r.resolve()}function h(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),S(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(S)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function S(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function T(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=v,s.initDayTypesExtended=h,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=T,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){ -function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return h().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=k.from_date!==u.request.from_date||k.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&B.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function v(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function h(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&B.hasExpirationFromAdminSettings,t=B.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return B.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){B.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),M(),l(),O())})})}function D(){u.isMode("view")||(C(),A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",{},t).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function S(){return l(),O(),M()}function T(){return x(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),j?j=!1:O(),M()}function O(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function I(){k=e.cloneDeep(u.request.attributes())}function x(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function L(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){R(!1)})}function M(){return m()?d().catch(a.resolve):a.resolve()}function E(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var k,j=!u.isMode("create"),B={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=v,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=S,u.openToilInDaysAccrualOptionsEditor=L,u.setDaysSelectionModeExtended=T,u.updateExpiryDate=E,function(){I(),x(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function v(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function h(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?v.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([h.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([h.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,v,h,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Le.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Le.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==F())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function L(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function F(){return Me.request?Me.request.request_type:Me.leaveType||null}function U(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Se,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(ve).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(ve).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Le.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=F(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return v.all().then(function(e){Me.absencePeriods=e})}function ie(){return h.all(j()).then(h.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Se[e+"_date"]})}function ve(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function he(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Se=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():L()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Le.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Le=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=S,Me.canSubmit=T,Me.closeAlert=x,Me.deleteLeaveRequest=E,Me.dismissModal=k,Me.getStatuses=U,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(he).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){ -return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e){define("leave-absences/manager-leave/modules/config",["common/angular","leave-absences/manager-leave/modules/settings"],function(t){return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/manager-leave/requests"),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","leave-absences/shared/ui-router","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); +function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return h().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=j.from_date!==u.request.from_date||j.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&N.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function v(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function h(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&N.hasExpirationFromAdminSettings,t=N.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return N.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){N.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),E(),l(),O())})})}function D(){u.isMode("view")||(C(),A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function S(){return l(),O(),E()}function T(){return x(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),B?B=!1:O(),E()}function O(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function I(){j=e.cloneDeep(u.request.attributes())}function x(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function L(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){R(!1)})}function M(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function E(){return m()?d().catch(a.resolve):a.resolve()}function k(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var j,B=!u.isMode("create"),N={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=v,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=S,u.openToilInDaysAccrualOptionsEditor=L,u.setDaysSelectionModeExtended=T,u.updateExpiryDate=k,function(){I(),x(),M(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function v(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function h(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?v.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([h.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([h.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,v,h,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Le.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Le.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==F())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function L(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function F(){return Me.request?Me.request.request_type:Me.leaveType||null}function U(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Se,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(ve).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(ve).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Le.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=F(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return v.all().then(function(e){Me.absencePeriods=e})}function ie(){return h.all(j()).then(h.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Se[e+"_date"]})}function ve(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function he(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Se=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():L()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Le.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Le=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=S,Me.canSubmit=T,Me.closeAlert=x,Me.deleteLeaveRequest=E,Me.dismissModal=k,Me.getStatuses=U,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(he).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"}, +templateUrl:["settings",function(e){return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e){define("leave-absences/manager-leave/modules/config",["common/angular","leave-absences/manager-leave/modules/settings"],function(t){return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/manager-leave/requests"),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","common/services/crm-ang.service","leave-absences/shared/ui-router","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js index 48699661bd7..a1a04b83655 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js @@ -6,9 +6,9 @@ */ -!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[m]),c[r[m]]=e[r[m]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&f(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,f),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),f.$$values=b,f.$$promises=f.$$promises||!0,delete f.$$inheritedValues,c.resolve(b))}function u(e){f.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),f=c.promise,g=f.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),f;o.$$inheritedValues&&r(b,m(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,m(o.$$values,h)),f.$$inheritedValues=m(o.$$values,h),i()):(o.$$inheritedValues&&(f.$$inheritedValues=m(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(f.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),m=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(m++,g[e].then(function(t){b[e]=t,--m||l()},c))}),m||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return f}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(m,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",m=0,f=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),f.push(g.segment),m=c.lastIndex;y=e.substring(m);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,m+_),q.length>0)for(m=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),m=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",f.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=f[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:m}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,m=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(m=e),m},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(f(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function m(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),f(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:m})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(D.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!D[r])return f(r,t.self);for(var o in R)B(R[o])&&(t[o]=R[o](t,R.$delegates[o]));return D[n]=t,!t[T]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){A.$current.navigable==t&&c(e,n)||A.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=A.$current.name.split("."),a=0,r=t.length;a=D;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=D;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.$current=t,A.current=t.self,A.params=n,V(A.params,f),A.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),A.current)}).then(null,function(a){return a===P?R:A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},A.is=function(e,t,a){a=W({relative:A.$current},a||{});var r=m(e,a.relative);return j(r)?A.$current===r&&(!t||c(r.params.$$values(t),f)):n},A.includes=function(e,t,a){if(a=W({relative:A.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=A.$current.name}var r=m(e,a.relative);if(!j(r))return n;if(!j(A.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(m&&(m.remove(),m=null),p&&(p.$destroy(),p=null),f){var e=f.data("$uiViewAnim");b.leave(f,function(){e.$$animLeave.resolve(),m=null}),m=f,f=null}}function d(s){var d,m=P(n,c,i,r),y=m&&e.$current&&e.$current.locals[m];if(s||y!==h){d=n.$new(),h=e.$current.locals[m],d.$emit("$viewContentLoading",m);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});f=_,p=d,p.$emit("$viewContentLoaded",m),p.$eval(v)}}var m,f,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function D(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=P(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var m=t.extend({},d);o[d.$$resolveAs]=m;var f=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=m),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}f(o)}}}}}function P(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function T(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function R(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function x(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function O(e,t){return{relative:R(e)||t.$current,inherit:!0}}function I(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=T(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],m=null;c.options=W(O(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var f=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),m&&m(),d&&(m=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&f(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),f(),l.clickable&&(i=x(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){m.state=t[0],m.params=t[1],m.options=t[2],m.href=e.href(m.state,m.params,m.options),f&&f(),c&&(f=c.$$addStateInfo(m.state,m.params)),m.href&&r.$set(u.attr,m.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",m={state:null,params:null,options:null,href:null},f=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=x(a,e,t,u,function(){return m}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function L(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,R(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function m(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,m){function f(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(D(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||T()})}function h(e){E.injectMonths=!0,x("injected").then(function(){T(e)}).then(function(){E.loading.calendar=!1})}function v(){O=a("LeaveCalendar"+t.capitalize(I)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(f).then(R)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return O.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function w(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return E.injectMonths&&(e=x("destroyed"),E.injectMonths=!1),e}function D(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function P(e){ -e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(A).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function T(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function R(){E.selectedMonths=[n().month()]}function S(){return E.roleOverride?r.resolve().then(function(){I=E.roleOverride}):r.all([m(i.permissions.admin.administer),m(i.permissions.ssp.manage)]).then(function(e){I=e[0]?"admin":e[1]?"manager":"staff"})}function x(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var O,I,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=P,function(){S().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),w()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function m(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?f():p()}function f(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),m(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function m(e){return U[e]}function f(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){O(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",M)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function w(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function D(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function P(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function T(){return[P(u.statusNames.approved),P(u.statusNames.adminApproved),P(u.statusNames.awaitingApproval),P(u.statusNames.moreInformationRequired)]}function R(){return W.month.loading=!0,a.all([x(),S()]).then(g).then(L).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:T()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function x(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function O(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function I(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=m(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?w(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function L(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&R())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=D(e);t&&(h(t),-1!==T().indexOf(e.status_id)&&c(e))}function B(e){return a.all(A(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=I,W.contactsList=f,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),x("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return L()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(A).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,x("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function w(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(A)}function A(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function D(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():w()}function P(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function T(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function R(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function x(e){return te.selectedAbsenceType.calculation_unit_name===e}function O(e){return te.request.request_type===e}function I(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function L(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(A).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,f(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(O("sickness")||x("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(x("hours")||O("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=A,te.isCalculationUnit=x,te.isLeaveType=O,te.isNotWorkingDay=I,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),T(),te.initChildController().then(function(){return s.all([L(),E()])}).then(!te.isMode("create")&&P).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(R).then(V).then(D).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(A).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function m(){return S.getFilesAmount()0?P.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(P.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){R[e.label]=t})})).catch(function(){R=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){P=e})}function w(e){return!e.attachment_id||S.canManage}function A(){e.forEach(T,function(e){e()})}function D(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var P=[],T=[],R={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=A,S.canRemoveAttachment=w,S.canSubmit=d,S.canUploadMore=m,S.formatDateTime=f,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,r,o,s,i,u,c,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){k(e),H.sections.other.open&&f(e,H.sections.other)}function h(){Object.values(H.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):H.refresh()}function g(t){t.dataIndex=e.indexBy(t.data,"id")}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function y(){return o.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.selectedPeriod=e.find(H.absencePeriods,function(e){return!0===e.current})})}function _(){return s.all().then(s.loadCalculationUnits).then(function(t){H.absenceTypes=t,H.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return P("approved",{status_id:F(m.statusNames.approved)})}function $(){return n.all([u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,null,!0),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.approved)]),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){H.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function C(){return i.all({contact_id:H.contactId,period_id:H.selectedPeriod.id},!0).then(function(e){H.entitlements=e}).then(function(){H.absenceTypesFiltered=H.absenceTypes.filter(function(t){var n=e.find(H.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function w(){return i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id},H.entitlements).then(function(){return E(H.entitlements)}).then(function(e){H.sections.entitlements.data=e})}function A(){return n.all([i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id,expired:!0}),D({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:E(e[0]),expiredTOILS:L(e[1].list)})}).then(function(t){ -H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function D(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function P(e,t){return D(t).then(function(t){H.sections[e].data=t.list})}function T(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(O))}function R(){return P("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function S(){return P("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function x(){return P("holidays",{public_holiday:!0})}function O(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function I(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function E(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function L(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){k(e)})}function k(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([C(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([T(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&O(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:k,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:x},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([I(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([C(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return D(n,e),e})):r.reject([])}function f(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),R(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(w)).then(function(){["from","to"].forEach(function(e){b(e),T(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(R)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&T(e,!0))})}function $(e,t){return m(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return w(e).then(function(){T(e,!0)})})}function w(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){x[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return x[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function A(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function D(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function P(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),w("from").then(function(){T("from",!0)})):r.resolve()}function T(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=x[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function R(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?w("from").then(function(){T("from",!0)}):r.resolve()}var x={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=A,s.setDaysSelectionModeExtended=P}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/services/crm-ang.service"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function m(){return!!u.request.toil_to_accrue}function f(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=k.from_date!==u.request.from_date||k.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&B.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&B.hasExpirationFromAdminSettings,t=B.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return B.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){B.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(T)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function w(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function A(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function D(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),L(),l(),x())})})}function P(){u.isMode("view")||(C(),w(),D())}function T(t){return s.valuesOf("hrleaveandabsences_toil_amounts",{},t).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function R(){return l(),x(),L()}function S(){return I(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),j?j=!1:x(),L()}function x(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function O(){k=e.cloneDeep(u.request.attributes())}function I(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function E(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){T(!1)})}function L(){return f()?d().catch(a.resolve):a.resolve()}function M(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var k,j=!u.isMode("create"),B={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=m,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=A,u.initWatchersExtended=P,u.onDateChangeExtended=R,u.openToilInDaysAccrualOptionsEditor=E,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=M,function(){O(),I(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,m,f,p,h,v,g,b,y,_,q,$,C){function w(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function A(){["from","to"].forEach(w)}function D(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Re.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=P();return Le.isMode("edit")&&(e=e&&(V()||T())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function x(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function O(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==F())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function I(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){fe("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(Pe[e],function(e){return Le.requestStatuses[e]})}function F(){return Le.request?Le.request.request_type:Le.leaveType||null}function U(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Re,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Oe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Pe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Pe.awaiting_approval=e,Pe.more_information_required=e,Pe.rejected=e,Pe.approved=e,Pe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?f.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Te++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=F(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:xe}),e}function Q(){if(Ie="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Ie="admin")}).then(function(){return"staff"===Ie&&u(_.permissions.ssp.manage).then(function(e){e&&(Ie="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Ie===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){De={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:De.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){xe=e.contactId})}function le(){return Le.selectedContactId?f.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?f.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==xe})}):f.find(xe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){D(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Re[e+"_date"]})}function he(e){if(Le.absenceTypes=me(De.types,e),!Le.absenceTypes.length)return r.reject(Oe)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Re=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,x(),A(),Le.request.isValid().then(ee()&&O).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?Ae():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Te&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Te>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function we(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?fe("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var De,Pe={},Te=0,Re={},Se=[],xe="",Oe="No entitlement",Ie="",Ee=[],Le=n.assign(this,m);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=R,Le.canSubmit=S,Le.closeAlert=I,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=U,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=we,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM), -define("leave-absences/my-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/models/option-group","common/modules/dialog","common/services/check-permissions","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/my-leave/components/my-leave-container.component","leave-absences/my-leave/modules/config"],function(e){return e.module("my-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.mocks","common.models","common.services","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","my-leave.components","my-leave.config"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/my-leave":n+"/my-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/my-leave/app"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-my-leave]"),["my-leave"])})})}(CRM,require),define("my-leave",function(){}); +!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[m]),c[r[m]]=e[r[m]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&f(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,f),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),f.$$values=b,f.$$promises=f.$$promises||!0,delete f.$$inheritedValues,c.resolve(b))}function u(e){f.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),f=c.promise,g=f.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),f;o.$$inheritedValues&&r(b,m(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,m(o.$$values,h)),f.$$inheritedValues=m(o.$$values,h),i()):(o.$$inheritedValues&&(f.$$inheritedValues=m(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(f.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),m=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(m++,g[e].then(function(t){b[e]=t,--m||l()},c))}),m||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return f}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(m,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",m=0,f=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),f.push(g.segment),m=c.lastIndex;y=e.substring(m);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,m+_),q.length>0)for(m=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),m=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",f.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=f[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:m}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,m=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(m=e),m},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(f(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function m(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),f(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:m})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(D.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!D[r])return f(r,t.self);for(var o in R)B(R[o])&&(t[o]=R[o](t,R.$delegates[o]));return D[n]=t,!t[T]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){A.$current.navigable==t&&c(e,n)||A.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=A.$current.name.split("."),a=0,r=t.length;a=D;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=D;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.$current=t,A.current=t.self,A.params=n,V(A.params,f),A.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),A.current)}).then(null,function(a){return a===P?R:A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},A.is=function(e,t,a){a=W({relative:A.$current},a||{});var r=m(e,a.relative);return j(r)?A.$current===r&&(!t||c(r.params.$$values(t),f)):n},A.includes=function(e,t,a){if(a=W({relative:A.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=A.$current.name}var r=m(e,a.relative);if(!j(r))return n;if(!j(A.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(m&&(m.remove(),m=null),p&&(p.$destroy(),p=null),f){var e=f.data("$uiViewAnim");b.leave(f,function(){e.$$animLeave.resolve(),m=null}),m=f,f=null}}function d(s){var d,m=P(n,c,i,r),y=m&&e.$current&&e.$current.locals[m];if(s||y!==h){d=n.$new(),h=e.$current.locals[m],d.$emit("$viewContentLoading",m);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});f=_,p=d,p.$emit("$viewContentLoaded",m),p.$eval(v)}}var m,f,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function D(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=P(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var m=t.extend({},d);o[d.$$resolveAs]=m;var f=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=m),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}f(o)}}}}}function P(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function T(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function R(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function x(e,t){return{relative:R(e)||t.$current,inherit:!0}}function I(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=T(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],m=null;c.options=W(x(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var f=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),m&&m(),d&&(m=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&f(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),f(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){m.state=t[0],m.params=t[1],m.options=t[2],m.href=e.href(m.state,m.params,m.options),f&&f(),c&&(f=c.$$addStateInfo(m.state,m.params)),m.href&&r.$set(u.attr,m.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",m={state:null,params:null,options:null,href:null},f=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return m}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function L(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,R(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function m(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,m){function f(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(D(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||T()})}function h(e){E.injectMonths=!0,O("injected").then(function(){T(e)}).then(function(){E.loading.calendar=!1})}function v(){x=a("LeaveCalendar"+t.capitalize(I)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(f).then(R)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return x.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function w(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function D(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function P(e){ +e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(A).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function T(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function R(){E.selectedMonths=[n().month()]}function S(){return E.roleOverride?r.resolve().then(function(){I=E.roleOverride}):r.all([m(i.permissions.admin.administer),m(i.permissions.ssp.manage)]).then(function(e){I=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var x,I,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=P,function(){S().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),w()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function m(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?f():p()}function f(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),m(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function m(e){return U[e]}function f(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){x(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",M)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function w(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function D(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function P(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function T(){return[P(u.statusNames.approved),P(u.statusNames.adminApproved),P(u.statusNames.awaitingApproval),P(u.statusNames.moreInformationRequired)]}function R(){return W.month.loading=!0,a.all([O(),S()]).then(g).then(L).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:T()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function x(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function I(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=m(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?w(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function L(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&R())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=D(e);t&&(h(t),-1!==T().indexOf(e.status_id)&&c(e))}function B(e){return a.all(A(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=I,W.contactsList=f,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return L()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(A).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function w(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(A)}function A(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function D(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():w()}function P(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function T(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function R(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function x(e){return te.request.request_type===e}function I(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function L(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(A).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,f(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(x("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||x("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=A,te.isCalculationUnit=O,te.isLeaveType=x,te.isNotWorkingDay=I,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),T(),te.initChildController().then(function(){return s.all([L(),E()])}).then(!te.isMode("create")&&P).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(R).then(V).then(D).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(A).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function m(){return S.getFilesAmount()0?P.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(P.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){R[e.label]=t})})).catch(function(){R=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){P=e})}function w(e){return!e.attachment_id||S.canManage}function A(){e.forEach(T,function(e){e()})}function D(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var P=[],T=[],R={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=A,S.canRemoveAttachment=w,S.canSubmit=d,S.canUploadMore=m,S.formatDateTime=f,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,r,o,s,i,u,c,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){k(e),H.sections.other.open&&f(e,H.sections.other)}function h(){Object.values(H.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):H.refresh()}function g(t){t.dataIndex=e.indexBy(t.data,"id")}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function y(){return o.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.selectedPeriod=e.find(H.absencePeriods,function(e){return!0===e.current})})}function _(){return s.all().then(s.loadCalculationUnits).then(function(t){H.absenceTypes=t,H.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return P("approved",{status_id:F(m.statusNames.approved)})}function $(){return n.all([u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,null,!0),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.approved)]),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){H.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function C(){return i.all({contact_id:H.contactId,period_id:H.selectedPeriod.id},!0).then(function(e){H.entitlements=e}).then(function(){H.absenceTypesFiltered=H.absenceTypes.filter(function(t){var n=e.find(H.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function w(){return i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id},H.entitlements).then(function(){return E(H.entitlements)}).then(function(e){H.sections.entitlements.data=e})}function A(){return n.all([i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id,expired:!0}),D({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:E(e[0]),expiredTOILS:L(e[1].list)})}).then(function(t){ +H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function D(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function P(e,t){return D(t).then(function(t){H.sections[e].data=t.list})}function T(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(x))}function R(){return P("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function S(){return P("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function O(){return P("holidays",{public_holiday:!0})}function x(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function I(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function E(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function L(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){k(e)})}function k(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([C(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([T(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&x(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:k,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([I(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([C(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return D(n,e),e})):r.reject([])}function f(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),R(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(w)).then(function(){["from","to"].forEach(function(e){b(e),T(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(R)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&T(e,!0))})}function $(e,t){return m(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return w(e).then(function(){T(e,!0)})})}function w(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function A(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function D(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function P(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),w("from").then(function(){T("from",!0)})):r.resolve()}function T(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function R(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?w("from").then(function(){T("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=A,s.setDaysSelectionModeExtended=P}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function m(){return!!u.request.toil_to_accrue}function f(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=j.from_date!==u.request.from_date||j.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&N.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&N.hasExpirationFromAdminSettings,t=N.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return N.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){N.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(T)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function w(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function A(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function D(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),M(),l(),O())})})}function P(){u.isMode("view")||(C(),w(),D())}function T(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function R(){return l(),O(),M()}function S(){return I(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),B?B=!1:O(),M()}function O(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function x(){j=e.cloneDeep(u.request.attributes())}function I(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function E(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){T(!1)})}function L(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function M(){return f()?d().catch(a.resolve):a.resolve()}function k(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var j,B=!u.isMode("create"),N={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=m,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=A,u.initWatchersExtended=P,u.onDateChangeExtended=R,u.openToilInDaysAccrualOptionsEditor=E,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=k,function(){x(),I(),L(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,m,f,p,h,v,g,b,y,_,q,$,C){function w(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function A(){["from","to"].forEach(w)}function D(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Re.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=P();return Le.isMode("edit")&&(e=e&&(V()||T())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function O(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function x(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==F())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function I(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){fe("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(Pe[e],function(e){return Le.requestStatuses[e]})}function F(){return Le.request?Le.request.request_type:Le.leaveType||null}function U(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Re,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==xe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Pe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Pe.awaiting_approval=e,Pe.more_information_required=e,Pe.rejected=e,Pe.approved=e,Pe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?f.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Te++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=F(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:Oe}),e}function Q(){if(Ie="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Ie="admin")}).then(function(){return"staff"===Ie&&u(_.permissions.ssp.manage).then(function(e){e&&(Ie="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Ie===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){De={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:De.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Le.selectedContactId?f.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?f.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):f.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){D(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Re[e+"_date"]})}function he(e){if(Le.absenceTypes=me(De.types,e),!Le.absenceTypes.length)return r.reject(xe)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Re=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,O(),A(),Le.request.isValid().then(ee()&&x).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?Ae():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Te&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Te>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function we(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?fe("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var De,Pe={},Te=0,Re={},Se=[],Oe="",xe="No entitlement",Ie="",Ee=[],Le=n.assign(this,m);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=R,Le.canSubmit=S,Le.closeAlert=I,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=U,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=we,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM), +define("leave-absences/my-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/models/option-group","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/my-leave/components/my-leave-container.component","leave-absences/my-leave/modules/config"],function(e){return e.module("my-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.mocks","common.models","common.services","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","my-leave.components","my-leave.config"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/my-leave":n+"/my-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/my-leave/app"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-my-leave]"),["my-leave"])})})}(CRM,require),define("my-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/app.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/app.js index 0a1c4ce346d..40ec97e1787 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/app.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/app.js @@ -12,6 +12,7 @@ define([ 'common/modules/dialog', 'common/modules/directives', 'common/services/check-permissions', + 'common/services/crm-ang.service', 'common/services/angular-date/date-format', 'common/services/notification.service', 'leave-absences/shared/modules/shared-settings', diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/admin-dashboard/app.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/admin-dashboard/app.js index 581410a7ed0..e496863348b 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/admin-dashboard/app.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/admin-dashboard/app.js @@ -10,6 +10,7 @@ define([ 'common/filters/time-unit-applier.filter', 'common/modules/dialog', 'common/services/check-permissions', + 'common/services/crm-ang.service', 'common/services/angular-date/date-format', 'leave-absences/shared/ui-router', 'leave-absences/shared/components/leave-balance-tab.component', diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/manager-leave/app.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/manager-leave/app.js index b591216b9c0..ac140d1f4cb 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/manager-leave/app.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/manager-leave/app.js @@ -13,6 +13,7 @@ define([ 'common/modules/dialog', 'common/services/angular-date/date-format', 'common/services/check-permissions', + 'common/services/crm-ang.service', 'leave-absences/shared/ui-router', 'leave-absences/shared/models/absence-period.model', 'leave-absences/shared/models/absence-type.model', diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/my-leave/app.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/my-leave/app.js index a163035cfbd..a5adeb64718 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/my-leave/app.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/my-leave/app.js @@ -13,6 +13,7 @@ define([ 'common/models/option-group', 'common/modules/dialog', 'common/services/check-permissions', + 'common/services/crm-ang.service', 'common/services/angular-date/date-format', 'leave-absences/shared/ui-router', 'leave-absences/shared/modules/shared-settings', diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js index 315d79d8cb8..4ac929f8c97 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js @@ -3,8 +3,7 @@ define([ 'common/lodash', 'common/moment', - 'leave-absences/shared/modules/controllers', - 'common/services/crm-ang.service' + 'leave-absences/shared/modules/controllers' ], function (_, moment, controllers) { controllers.controller('RequestModalDetailsToilController', RequestModalDetailsToilController); @@ -38,6 +37,7 @@ define([ (function init () { setInitialRequestAttributes(); setTimeInputsRanges(); + toggleAccrualOptionsGroupEditorIcon(); !detailsController.isMode('create') && initDuration(); })(); @@ -353,7 +353,7 @@ define([ * @return {Promise} */ function loadToilAmounts (cache) { - return OptionGroup.valuesOf('hrleaveandabsences_toil_amounts', {}, cache) + return OptionGroup.valuesOf('hrleaveandabsences_toil_amounts', cache) .then(function (amounts) { detailsController.toilAmounts = _.sortBy(amounts, 'value'); }); @@ -429,6 +429,15 @@ define([ }); } + /** + * Toggles the TOIL accrual options group editor icon + * depending on the site section the Leave Request Modal is opened at + */ + function toggleAccrualOptionsGroupEditorIcon () { + detailsController.showTOILAccrualsOptionEditorIcon = + _.includes(['admin-dashboard', 'absence-tab'], $rootScope.section); + } + /** * Calculates the expiry date if all conditions are met, otherwise it resolves * into an empty promise. diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js index 0f26d2f37ef..cf639184a11 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js @@ -67,14 +67,6 @@ define([ spyOn(AbsenceType, 'canExpire').and.callThrough(); spyOn(AbsenceType, 'calculateToilExpiryDate').and.callThrough(); spyOn(OptionGroup, 'valuesOf').and.callThrough(); - - crmAngService.loadForm = function () { - return { - on: function (event, callback) { - callback(); - } - }; - }; })); describe('on initialize', function () { @@ -105,7 +97,7 @@ define([ }); it('caches TOIL accrual options', function () { - expect(OptionGroup.valuesOf.calls.mostRecent().args[2]).not.toBe(false); + expect(OptionGroup.valuesOf.calls.mostRecent().args[1]).not.toBe(false); }); it('sorts TOIL accrual options by value', function () { @@ -325,6 +317,13 @@ define([ beforeEach(function () { // flushing TOIL accrual options controller.toilAmounts = null; + crmAngService.loadForm = function () { + return { + on: function (event, callback) { + callback(); + } + }; + }; spyOn(crmAngService, 'loadForm').and.callThrough(); controller.openToilInDaysAccrualOptionsEditor(); @@ -343,8 +342,26 @@ define([ expect(Object.keys(controller.toilAmounts).length).toBeGreaterThan(0); }); - it('does not cache TOIL accrual options', function () { - expect(OptionGroup.valuesOf.calls.mostRecent().args[2]).toBe(false); + it('fetches updated TOIL accrual options from the backend', function () { + var retreiveCachedTOILOptions = OptionGroup.valuesOf.calls.mostRecent().args[1]; + + expect(retreiveCachedTOILOptions).toBe(false); + }); + }); + }); + }); + + describe('TOIL accrual options group editor icon', function () { + ['admin-dashboard', 'absence-tab'].forEach(function (siteSection) { + describe('when the leave request modal is opened in ' + siteSection + ' section', function () { + beforeEach(function () { + $rootScope.section = siteSection; + + compileComponent({ request: TOILRequestInstance.init() }); + }); + + it('shows the editor icon', function () { + expect(controller.showTOILAccrualsOptionEditorIcon).toBe(true); }); }); }); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html index 64910f6b201..e93c7512364 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html @@ -40,12 +40,10 @@
    -
    + ng-if="detailsTab.selectedAbsenceType.calculation_unit_name === 'days'"> +
    + class="crm_custom-select crm_custom-select--full"> \n \n \n \n \n
    \n\n \n
    \n\n
    \n
    \n'),e.put("civihr-ui-select/select-multiple.tpl.html",'
    \n
    \n
      \n \n
    • \n \n
    • \n
    \n \n
    \n
    \n'),e.put("civihr-ui-select/select.tpl.html",'
    \n
    \n \n
    \n'),e.put("components/heatmap.html",'
      \n
    • \n {{day.name.short}}\n
    • \n
    \n'),e.put("contact-actions/contact-actions.html",'
    \n'),e.put("contact-actions/modals/form.html",'
    \n \n \n \n
    \n')}])}),define("common/modules/controllers",["common/angular","common/angularBootstrap","common/modules/apis"],function(e){"use strict";return e.module("common.controllers",["ui.bootstrap","common.apis"])}),define("common/modules/directives",["common/angular","common/decorators/ui-select-focus.decorator","common/decorators/uib-datepicker-calendar-icon.decorator","common/decorators/uib-datepicker-mobile-version.decorator","common/decorators/xeditable-disable-calendar-icon.decorator","common/decorators/ui-bootstrap/uib-tabset","common/decorators/ui-bootstrap/uib-modal.decorator","common/angularBootstrap","common/angularXeditable","common/ui-select","common/modules/templates","common/modules/controllers","common/modules/services","common/modules/apis"],function(e,t,n,r,i,o,a){"use strict";return e.module("common.directives",["common.templates","common.controllers","ui.select","ui.bootstrap","xeditable"]).config(["$provide",function(e){e.decorator("uibDatepickerPopupDirective",r),e.decorator("uibDatepickerPopupDirective",n),e.decorator("uibTabsetDirective",o),e.decorator("$uibModal",a),e.decorator("editableBsdateDirective",i),e.decorator("uiSelectDirective",t)}]).run(["$templateCache",function(e){var t="uib/template/tabs/tabset.html",n=jQuery(e.get(t));n.find("ul").addClass("{{tabset.customHeaderClass}}"),e.put(t,n.wrap("
    ").parent().html())}])}),define("common/services/api/contact-actions",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.contactActions",["$q","api",function(e,t){function n(e,n){return t.sendGET(e,"getoptions",{field:n,context:"search"}).then(function(e){return e.values})}function r(e){return t.sendGET("UFField","get",{uf_group_id:e,is_active:!0}).then(function(e){return e.values})}function i(n,r){return e(function(e,i){if(r.contact_type=n,r.email)return t.sendGET("CustomField","get",{return:["id"],custom_group_id:"Emergency_Contacts",name:"email"}).then(function(t){r["custom_"+t.id]=r.email,delete r.email,e()});e()}).then(function(){return t.sendPOST("Contact","create",r).then(function(e){return e.values[0]})})}return t.extend({getOptions:{forContactType:function(){return n.call(this,"Contact","contact_type")},forGroup:function(){return n.call(this,"GroupContact","group_id")},forTag:function(){return n.call(this,"EntityTag","tag_id")},forStateProvince:function(){return n.call(this,"Address","state_province_id")},forCountry:function(){return n.call(this,"Address","country_id")},forGender:function(){return n.call(this,"Contact","gender_id")},forDeceased:function(){return n.call(this,"Contact","is_deceased")}},save:{newIndividual:function(e){return i.call(this,"Individual",e)},newOrganization:function(e){return i.call(this,"Organization",e)},newHousehold:function(e){return i.call(this,"Household",e)}},getFormFields:{forNewIndividual:function(){return r.call(this,"new_individual")},forNewOrganization:function(){return r.call(this,"new_organization")},forNewHousehold:function(){return r.call(this,"new_household")}}})}])}),define("common/controllers/contact-actions/modal-ctrl",[],function(){"use strict";return function(e,t){this.errorMsg="",this.loading=!0,this.formFields=[],this.init=function(e){e().then(function(e){this.loading=!1,this.formFields=e}.bind(this)).catch(function(){this.loading=!1,this.errorMsg="Error while loading form fields"}.bind(this))},this.cancel=function(){t.dismiss("cancel")},this.save=function(n,r){this.loading=!0,n(this.formFields.reduce(function(e,t){return e[t.field_name]=t.value,e},{})).then(function(n){this.loading=!1,e.$broadcast(r,n),t.dismiss("cancel")}.bind(this)).catch(function(){this.loading=!1,this.errorMsg="Error while saving data"}.bind(this))}}}),define("common/controllers/contact-actions/new-individual-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Individual",i.init(r.getFormFields.forNewIndividual),i.submit=function(){i.save(r.save.newIndividual,"newIndividualCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewIndividualModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/new-household-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Household",i.init(r.getFormFields.forNewHousehold),i.submit=function(){i.save(r.save.newHousehold,"newHouseholdCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewHouseholdModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/new-organization-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Organization",i.init(r.getFormFields.forNewOrganization),i.submit=function(){i.save(r.save.newOrganization,"newOrganizationCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewOrganizationModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/contact-actions-ctrl",["common/modules/controllers","common/services/api/contact-actions","common/controllers/contact-actions/new-individual-ctrl","common/controllers/contact-actions/new-household-ctrl","common/controllers/contact-actions/new-organization-ctrl"],function(e){"use strict";e.controller("ContactActionsCtrl",["$scope","$rootElement","$uibModal","api.contactActions",function(e,t,n,r){var i=this;e.$watch(function(){return i.refineSearch.selected},function(t,n){t!==n&&e.$emit("contactRefineSearch",{field:t.field?t.field.label:null,option:t.option?t.option.value:null})},!0),i.refineSearch={selected:{field:null,option:null},availableFields:[{label:"Contact Type",getOptions:r.getOptions.forContactType},{label:"Group",getOptions:r.getOptions.forGroup},{label:"Tag",getOptions:r.getOptions.forTag},{label:"State / Province",getOptions:r.getOptions.forStateProvince},{label:"Country",getOptions:r.getOptions.forCountry},{label:"Gender",getOptions:r.getOptions.forGender},{label:"Deceased",getOptions:r.getOptions.forDeceased}],availableOptions:{refresh:function(){i.refineSearch.selected.field?(this.options=null,i.refineSearch.selected.field.getOptions().then(function(e){this.options=e}.bind(this))):this.options=[]},options:[]}},i.showNewIndividualModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewIndividualModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})},i.showNewHouseholdModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewHouseholdModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})},i.showNewOrganizationModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewOrganizationModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})}}])}),define("common/directives/prevent-animations",["common/modules/directives"],function(e){"use strict";e.directive("preventAnimations",["$animate",function(e){return{restrict:"A",link:function(t,n,r){e.enabled(n,!1)}}}])}),define("common/directives/loading",["common/modules/directives","common/directives/prevent-animations"],function(e){"use strict";e.directive("crmLoading",["$templateCache",function(e){return{scope:{show:"="},restrict:"E",replace:!0,transclude:!0,template:e.get("loading.html")}}])}),define("common/directives/contact-actions/contact-actions",["common/modules/directives","common/controllers/contact-actions/contact-actions-ctrl","common/directives/loading"],function(e){"use strict";e.directive("contactActions",[function(){return{restrict:"E",templateUrl:"contact-actions/contact-actions.html",controller:"ContactActionsCtrl",controllerAs:"$ctrl",link:function(e,t,n){e.$ctrl.refineSearchVisible=t.parent().parent()[0].hasAttribute("refine-search")}}}])}),define("common/directives/help-text.directive",["common/lodash","common/moment","common/modules/directives","common/services/notification.service"],function(e,t,n){function r(e,t){function n(){var n=e.getHelpText();t.info(e.title||r,n)}var r="Help";this.displayHelpText=n}function i(e,t,n){function r(){return t.find(".help-text").html()}e.getHelpText=r}n.directive("helpText",["$templateCache",function(e){return{restrict:"E",scope:{title:"@?"},transclude:!0,controller:r,controllerAs:"helpText",template:e.get("help-text.html"),link:i}}]),r.$inject=["$scope","notificationService"]}),define("common/directives/scroll-shadows.directive",["common/angular","common/modules/directives"],function(e,t){"use strict";function n(t,n,r){function i(){u(),a(),l(),s()}function o(){var e=f.width(),t=p+"__shadows--show-left",n=p+"__shadows--show-right",r=d.scrollLeft(),i=d.width();if(e<=i)return void d.removeClass(t+" "+n);d[r>0?"addClass":"removeClass"](t),d[r
    ').parent(),d=f.wrap('
    ').parent(),d.wrap('
    ')}var f,d,p="chr_scroll-shadows";!function(){c(),i(),o()}()}t.directive("scrollShadows",[function(){return{restrict:"A",controller:n}}]),n.$inject=["$element","$scope","$window"]}),define("common/directives/timepicker-select.directive",["common/moment","common/modules/directives"],function(e,t){"use strict";function n(t){function n(){var n=+t.timepickerSelectInterval||1,i=e.duration(t.timepickerSelectTimeFrom||"00:00"),o=e.duration(t.timepickerSelectTimeTo||"23:59");for(r.options=[];i.asMinutes()<=o.asMinutes();){var a=e.utc(i.asMilliseconds());r.options.push(a.format("HH:mm")),i.add(n,"minutes")}}var r=this;r.placeholder=t.timepickerSelectPlaceholder,r.options=[],t.$watchGroup(["timepickerSelectTimeFrom","timepickerSelectTimeTo","timepickerSelectInterval"],function(){n()})}t.directive("timepickerSelect",["$templateCache",function(e){return{scope:{timepickerSelectPlaceholder:"@",timepickerSelectTimeFrom:"<",timepickerSelectTimeTo:"<",timepickerSelectInterval:"<"},restrict:"A",controllerAs:"selector",controller:["$scope",n],template:e.get("timepicker-select.html")}}]),n.$inject=["$scope"]}),define("common/directives/time-amount-picker.directive",["common/lodash","common/modules/directives"],function(e,t){"use strict";function n(t){function n(){var e=Math.floor(c);for(d.hoursOptions=[];e<=f;)d.hoursOptions.push(e),e++}function r(){var e,t,n,r=0;for(d.minutesOptions=[];r<60;)t=+d.selectedHours===Math.floor(c)&&rf%1*60,e=t||n,!e&&d.minutesOptions.push(r),r+=u;l()}function i(){u=+t.interval||1,c=isNaN(+t.minAmount)?0:+t.minAmount,f=isNaN(+t.maxAmount)?24:+t.maxAmount,n(),r()}function o(){""!==d.selectedHours&&""!==d.selectedMinutes&&(t.value=+d.selectedHours+d.selectedMinutes/60)}function a(){t.$watch("disabled",function(e){d.disabled=e}),t.$watch("value",function(){s()}),t.$watchGroup(["minAmount","maxAmount","interval"],function(){i()})}function s(){void 0!==t.value&&(d.selectedHours=""+Math.floor(t.value),d.selectedMinutes=""+Math.floor(t.value%1*60)),o()}function l(){d.selectedMinutese.last(d.minutesOptions)&&(d.selectedMinutes=""+e.last(d.minutesOptions))}var u,c,f,d=this;d.hoursOptions=[],d.minutesOptions=[],d.selectedHours="",d.selectedMinutes="",d.buildMinutesOptions=r,d.calculateSelectedValue=o,function(){s(),a()}()}t.directive("timeAmountPicker",["$templateCache",function(e){return{scope:{minAmount:".75?Math.floor(.25*Math.ceil(e/.25))+"h":"",n=e%1&&e%1<=.75&&e%1>0?.25*Math.ceil(e%1/.25)*60+"m":"",r+t+(t&&n?" ":"")+n)}};return function(t,n){var r=void 0===t?0:parseFloat(t);if(isNaN(r))throw new Error("Value must be a number or a numeric string: "+t);return e[n](r)}})}),define("common/bundles/filters",["common/filters/time-unit-applier.filter"],function(){}),define("common/decorators/angular-date/datepicker-popup",["common/lodash"],function(e){return["$delegate","HR_settings",function(t,n){"use strict";var r=t[0].link;return t[0].compile=function(){return function(t,i,o,a){o.uibDatepickerPopup=o.uibDatepickerPopup||n.DATE_FORMAT||"yyyy-MM-dd",o.showButtonBar=o.showButtonBar||!1,t.datepickerOptions=e.assign({formatDayHeader:"E",showWeeks:!1, +;return t.compile=function(){var e=n.apply(this,arguments);return function(t,n,r,i){var o=i[0];o.multiple&&n.click(function(e){0===angular.element(e.target).parents(".ui-select-match").length&&0===angular.element(e.target).parents(".ui-select-choices").length&&(n.find(".ui-select-search").focus(),o.open=!0,t.$apply())}),e.apply(this,arguments)}},e}]}),define("common/decorators/uib-datepicker-calendar-icon.decorator",["common/services/detect-device.service"],function(){"use strict";return["$delegate","detectDevice",function(e,t){function n(e,t){var n=angular.element('');r(n,t),e.after(n)}function r(e,n){function r(){n.isOpen=!0,n.$apply()}t.isMobile()||(e.on("click",r),n.$on("$destroy",function(){e.off("click",r)}))}var i=e[0],o=i.compile;return i.compile=function(){var e=o.apply(this,arguments);return function(t,i,o){e.apply(this,arguments),n(i,t),r(i,t)}},e}]}),define("common/decorators/uib-datepicker-mobile-version.decorator",["common/moment","common/services/detect-device.service"],function(e){"use strict";return["$delegate","detectDevice",function(t,n){function r(t){return t?e(t).format("Y-MM-DD"):""}var i=t[0],o=i.compile;return i.require=["ngModel","uibDatepickerPopup"],i.compile=function(){var e=o.apply(this,arguments);return function(t,i,o,a){n.isMobile()?(i.prop("type","date"),o.ngReadonly=!1,a[0].$formatters.push(function(e){return r(e)}),t.$watch("datepickerOptions.minDate",function(e){o.$set("min",r(e))}),t.$watch("datepickerOptions.maxDate",function(e){o.$set("max",r(e))})):e.apply(this,arguments)}},t}]}),define("common/decorators/xeditable-disable-calendar-icon.decorator",[],function(){"use strict";return["$delegate",function(e){var t=e[0],n=t.compile;return t.compile=function(){var e=n.apply(this,arguments);return function(t,n,r){e.apply(this,arguments),r.eShowCalendarButton=!1}},e}]}),define("common/decorators/ui-bootstrap/uib-tabset",[],function(){"use strict";return["$delegate",function(e){return e[0].bindToController.customHeaderClass="@",e}]}),define("common/decorators/ui-bootstrap/uib-modal.decorator",["common/angular"],function(e){"use strict";return["$delegate","$document",function(t,n){function r(){var t,r=[{item:e.element(n[0].body),styles:[{name:"overflow",old:null,new:"hidden"},{name:"height",old:null,new:"100%"},{name:"width",old:null,new:"100%"}]},{item:e.element(n[0].getElementsByTagName("html")[0]),styles:[{name:"overflow",old:null,new:"hidden"},{name:"height",old:null,new:"100%"},{name:"width",old:null,new:"100%"}]}];return r.forEach(function(e){e.styles.forEach(function(t){t.old=e.item.css(t.name),e.item.css(t.name,t.new)})}),t=i.apply(this,arguments),t.closed.then(function(){r.forEach(function(e){e.styles.forEach(function(t){e.item.css(t.name,t.old)})})}),t}var i=t.open;return t.open=r,t}]}),define("common/modules/templates",["common/angular"],function(e){"use strict";return e.module("common.templates",[]).run(["$templateCache",function(e){e.put("dialog.html",'\n\n\n'),e.put("help-text.html",'\n'),e.put("loading.html",'
    \n
    \n
    \n
    \n'),e.put("time-amount-picker.html",'
    \n
    \n \n \n
    \n h\n
    \n \n \n
    \n m\n
    \n'),e.put("timepicker-select.html",'\n\n'),e.put("civihr-ui-select/choices.tpl.html",'
      \n
    • \n
      \n
        \n
      • \n
        \n
      • \n
      \n
    • \n
    \n'),e.put("civihr-ui-select/match-multiple.tpl.html",'\n
  • \n \n \n
  • \n
    \n'),e.put("civihr-ui-select/match.tpl.html",'\n {{$select.contactList ? \'-select-\' : $select.placeholder}}\n \n \n \n\n'),e.put("civihr-ui-select/select-contacts-multiple.tpl.html",'
    \n
    \n
      \n \n
    • \n \n
    • \n
    \n\n \n\n \n
    \n
    \n'),e.put("civihr-ui-select/select-contacts.tpl.html",'
    \n
    \n \n
    \n'),e.put("civihr-ui-select/select-multiple.tpl.html",'
    \n
    \n
      \n \n
    • \n \n
    • \n
    \n \n
    \n
    \n'),e.put("civihr-ui-select/select.tpl.html",'
    \n
    \n \n
    \n'),e.put("components/heatmap.html",'
      \n
    • \n {{day.name.short}}\n
    • \n
    \n'),e.put("contact-actions/contact-actions.html",'
    \n \n \n
    \n'),e.put("contact-actions/modals/form.html",'
    \n \n \n \n
    \n')}])}),define("common/modules/controllers",["common/angular","common/angularBootstrap","common/modules/apis"],function(e){"use strict";return e.module("common.controllers",["ui.bootstrap","common.apis"])}),define("common/modules/directives",["common/angular","common/decorators/ui-select-focus.decorator","common/decorators/uib-datepicker-calendar-icon.decorator","common/decorators/uib-datepicker-mobile-version.decorator","common/decorators/xeditable-disable-calendar-icon.decorator","common/decorators/ui-bootstrap/uib-tabset","common/decorators/ui-bootstrap/uib-modal.decorator","common/angularBootstrap","common/angularXeditable","common/ui-select","common/modules/templates","common/modules/controllers","common/modules/services","common/modules/apis"],function(e,t,n,r,i,o,a){"use strict";return e.module("common.directives",["common.templates","common.controllers","ui.select","ui.bootstrap","xeditable"]).config(["$provide",function(e){e.decorator("uibDatepickerPopupDirective",r),e.decorator("uibDatepickerPopupDirective",n),e.decorator("uibTabsetDirective",o),e.decorator("$uibModal",a),e.decorator("editableBsdateDirective",i),e.decorator("uiSelectDirective",t)}]).run(["$templateCache",function(e){var t="uib/template/tabs/tabset.html",n=jQuery(e.get(t));n.find("ul").addClass("{{tabset.customHeaderClass}}"),e.put(t,n.wrap("
    ").parent().html())}])}),define("common/services/api/contact-actions",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.contactActions",["$q","api",function(e,t){function n(e,n){return t.sendGET(e,"getoptions",{field:n,context:"search"}).then(function(e){return e.values})}function r(e){return t.sendGET("UFField","get",{uf_group_id:e,is_active:!0}).then(function(e){return e.values})}function i(n,r){return e(function(e,i){if(r.contact_type=n,r.email)return t.sendGET("CustomField","get",{return:["id"],custom_group_id:"Emergency_Contacts",name:"email"}).then(function(t){r["custom_"+t.id]=r.email,delete r.email,e()});e()}).then(function(){return t.sendPOST("Contact","create",r).then(function(e){return e.values[0]})})}return t.extend({getOptions:{forContactType:function(){return n.call(this,"Contact","contact_type")},forGroup:function(){return n.call(this,"GroupContact","group_id")},forTag:function(){return n.call(this,"EntityTag","tag_id")},forStateProvince:function(){return n.call(this,"Address","state_province_id")},forCountry:function(){return n.call(this,"Address","country_id")},forGender:function(){return n.call(this,"Contact","gender_id")},forDeceased:function(){return n.call(this,"Contact","is_deceased")}},save:{newIndividual:function(e){return i.call(this,"Individual",e)},newOrganization:function(e){return i.call(this,"Organization",e)},newHousehold:function(e){return i.call(this,"Household",e)}},getFormFields:{forNewIndividual:function(){return r.call(this,"new_individual")},forNewOrganization:function(){return r.call(this,"new_organization")},forNewHousehold:function(){return r.call(this,"new_household")}}})}])}),define("common/controllers/contact-actions/modal-ctrl",[],function(){"use strict";return function(e,t){this.errorMsg="",this.loading=!0,this.formFields=[],this.init=function(e){e().then(function(e){this.loading=!1,this.formFields=e}.bind(this)).catch(function(){this.loading=!1,this.errorMsg="Error while loading form fields"}.bind(this))},this.cancel=function(){t.dismiss("cancel")},this.save=function(n,r){this.loading=!0,n(this.formFields.reduce(function(e,t){return e[t.field_name]=t.value,e},{})).then(function(n){this.loading=!1,e.$broadcast(r,n),t.dismiss("cancel")}.bind(this)).catch(function(){this.loading=!1,this.errorMsg="Error while saving data"}.bind(this))}}}),define("common/controllers/contact-actions/new-individual-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Individual",i.init(r.getFormFields.forNewIndividual),i.submit=function(){i.save(r.save.newIndividual,"newIndividualCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewIndividualModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/new-household-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Household",i.init(r.getFormFields.forNewHousehold),i.submit=function(){i.save(r.save.newHousehold,"newHouseholdCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewHouseholdModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/new-organization-ctrl",["common/modules/controllers","common/controllers/contact-actions/modal-ctrl","common/services/api/contact-actions"],function(e,t){"use strict";function n(e,n,r){var i=this;t.call(i,e,n),i.title="New Organization",i.init(r.getFormFields.forNewOrganization),i.submit=function(){i.save(r.save.newOrganization,"newOrganizationCreated")}}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,e.controller("NewOrganizationModalCtrl",["$rootScope","$uibModalInstance","api.contactActions",n])}),define("common/controllers/contact-actions/contact-actions-ctrl",["common/modules/controllers","common/services/api/contact-actions","common/controllers/contact-actions/new-individual-ctrl","common/controllers/contact-actions/new-household-ctrl","common/controllers/contact-actions/new-organization-ctrl"],function(e){"use strict";e.controller("ContactActionsCtrl",["$scope","$rootElement","$uibModal","api.contactActions",function(e,t,n,r){var i=this;e.$watch(function(){return i.refineSearch.selected},function(t,n){t!==n&&e.$emit("contactRefineSearch",{field:t.field?t.field.label:null,option:t.option?t.option.value:null})},!0),i.refineSearch={selected:{field:null,option:null},availableFields:[{label:"Contact Type",getOptions:r.getOptions.forContactType},{label:"Group",getOptions:r.getOptions.forGroup},{label:"Tag",getOptions:r.getOptions.forTag},{label:"State / Province",getOptions:r.getOptions.forStateProvince},{label:"Country",getOptions:r.getOptions.forCountry},{label:"Gender",getOptions:r.getOptions.forGender},{label:"Deceased",getOptions:r.getOptions.forDeceased}],availableOptions:{refresh:function(){i.refineSearch.selected.field?(this.options=null,i.refineSearch.selected.field.getOptions().then(function(e){this.options=e}.bind(this))):this.options=[]},options:[]}},i.showNewIndividualModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewIndividualModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})},i.showNewHouseholdModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewHouseholdModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})},i.showNewOrganizationModal=function(){n.open({appendTo:t.children().eq(0),controller:"NewOrganizationModalCtrl",controllerAs:"$ctrl",bindToController:!0,templateUrl:"contact-actions/modals/form.html"})}}])}),define("common/directives/prevent-animations",["common/modules/directives"],function(e){"use strict";e.directive("preventAnimations",["$animate",function(e){return{restrict:"A",link:function(t,n,r){e.enabled(n,!1)}}}])}),define("common/directives/loading",["common/modules/directives","common/directives/prevent-animations"],function(e){"use strict";e.directive("crmLoading",["$templateCache",function(e){return{scope:{show:"="},restrict:"E",replace:!0,transclude:!0,template:e.get("loading.html")}}])}),define("common/directives/contact-actions/contact-actions",["common/modules/directives","common/controllers/contact-actions/contact-actions-ctrl","common/directives/loading"],function(e){"use strict";e.directive("contactActions",[function(){return{restrict:"E",templateUrl:"contact-actions/contact-actions.html",controller:"ContactActionsCtrl",controllerAs:"$ctrl",link:function(e,t,n){e.$ctrl.refineSearchVisible=t.parent().parent()[0].hasAttribute("refine-search")}}}])}),define("common/directives/help-text.directive",["common/lodash","common/moment","common/modules/directives","common/services/notification.service"],function(e,t,n){function r(e,t){function n(){var n=e.getHelpText();t.info(e.title||r,n)}var r="Help";this.displayHelpText=n}function i(e,t,n){function r(){return t.find(".help-text").html()}e.getHelpText=r}n.directive("helpText",["$templateCache",function(e){return{restrict:"E",scope:{title:"@?"},transclude:!0,controller:r,controllerAs:"helpText",template:e.get("help-text.html"),link:i}}]),r.$inject=["$scope","notificationService"]}),define("common/directives/scroll-shadows.directive",["common/angular","common/modules/directives"],function(e,t){"use strict";function n(t,n,r){function i(){u(),a(),l(),s()}function o(){var e=f.width(),t=p+"__shadows--show-left",n=p+"__shadows--show-right",r=d.scrollLeft(),i=d.width();if(e<=i)return void d.removeClass(t+" "+n);d[r>0?"addClass":"removeClass"](t),d[r
    ').parent(),d=f.wrap('
    ').parent(),d.wrap('
    ')}var f,d,p="chr_scroll-shadows";!function(){c(),i(),o()}()}t.directive("scrollShadows",[function(){return{restrict:"A",controller:n}}]),n.$inject=["$element","$scope","$window"]}),define("common/directives/timepicker-select.directive",["common/moment","common/modules/directives"],function(e,t){"use strict";function n(t){function n(){var n=+t.timepickerSelectInterval||1,i=e.duration(t.timepickerSelectTimeFrom||"00:00"),o=e.duration(t.timepickerSelectTimeTo||"23:59");for(r.options=[];i.asMinutes()<=o.asMinutes();){var a=e.utc(i.asMilliseconds());r.options.push(a.format("HH:mm")),i.add(n,"minutes")}}var r=this;r.placeholder=t.timepickerSelectPlaceholder,r.options=[],t.$watchGroup(["timepickerSelectTimeFrom","timepickerSelectTimeTo","timepickerSelectInterval"],function(){n()})}t.directive("timepickerSelect",["$templateCache",function(e){return{scope:{timepickerSelectPlaceholder:"@",timepickerSelectTimeFrom:"<",timepickerSelectTimeTo:"<",timepickerSelectInterval:"<"},restrict:"A",controllerAs:"selector",controller:["$scope",n],template:e.get("timepicker-select.html")}}]),n.$inject=["$scope"]}),define("common/directives/time-amount-picker.directive",["common/lodash","common/modules/directives"],function(e,t){"use strict";function n(t){function n(){var e=Math.floor(c);for(d.hoursOptions=[];e<=f;)d.hoursOptions.push(e),e++}function r(){var e,t,n,r=0;for(d.minutesOptions=[];r<60;)t=+d.selectedHours===Math.floor(c)&&rf%1*60,e=t||n,!e&&d.minutesOptions.push(r),r+=u;l()}function i(){u=+t.interval||1,c=isNaN(+t.minAmount)?0:+t.minAmount,f=isNaN(+t.maxAmount)?24:+t.maxAmount,n(),r()}function o(){""!==d.selectedHours&&""!==d.selectedMinutes&&(t.value=+d.selectedHours+d.selectedMinutes/60)}function a(){t.$watch("disabled",function(e){d.disabled=e}),t.$watch("value",function(){s(),i()}),t.$watchGroup(["minAmount","maxAmount","interval"],function(){i()})}function s(){void 0!==t.value&&(d.selectedHours=""+Math.floor(t.value),d.selectedMinutes=""+Math.floor(t.value%1*60)),o()}function l(){d.selectedMinutese.last(d.minutesOptions)&&(d.selectedMinutes=""+e.last(d.minutesOptions))}var u,c,f,d=this;d.hoursOptions=[],d.minutesOptions=[],d.selectedHours="",d.selectedMinutes="",d.buildMinutesOptions=r,d.calculateSelectedValue=o,function(){s(),i(),a()}()}t.directive("timeAmountPicker",["$templateCache",function(e){return{scope:{minAmount:".75?Math.floor(.25*Math.ceil(e/.25))+"h":"",n=e%1&&e%1<=.75&&e%1>0?.25*Math.ceil(e%1/.25)*60+"m":"",r+t+(t&&n?" ":"")+n)}};return function(t,n){var r=void 0===t?0:parseFloat(t);if(isNaN(r))throw new Error("Value must be a number or a numeric string: "+t);return e[n](r)}})}),define("common/bundles/filters",["common/filters/time-unit-applier.filter"],function(){}),define("common/decorators/angular-date/datepicker-popup",["common/lodash"],function(e){return["$delegate","HR_settings",function(t,n){"use strict";var r=t[0].link;return t[0].compile=function(){return function(t,i,o,a){o.uibDatepickerPopup=o.uibDatepickerPopup||n.DATE_FORMAT||"yyyy-MM-dd",o.showButtonBar=o.showButtonBar||!1,t.datepickerOptions=e.assign({formatDayHeader:"E",showWeeks:!1, startingDay:1},t.datepickerOptions),r.apply(this,arguments)}},t}]}),define("common/decorators/angular-date/date-filter",[],function(){"use strict";return["$delegate",function(e){var t=e;return function(){if("E"===arguments[1]){var e=Array.prototype.slice.call(arguments);return e[1]="EEE",t.apply(this,e)[0]}return t.apply(this,arguments)}}]}),function(e){define("common/modules/angular-date",["common/angular","common/decorators/angular-date/datepicker-popup","common/decorators/angular-date/date-filter","common/modules/services","common/angularBootstrap","common/modules/templates"],function(t,n,r){"use strict";function i(t){var n="uib/template/datepicker/"+t+".html",r=o.get(n);r=r.replace(/glyphicon glyphicon-chevron-(left|right)/gm,"fa fa-chevron-$1"),"day"===t&&(r=function(t){return e(t).find('th[ng-if="showWeeks"]').parent().css({"border-top":"1px solid #DDD"}),e(t).prop("outerHTML")}(e.parseHTML(r))),o.put(n,r)}var o;return t.module("common.angularDate",["common.services","ui.bootstrap","common.templates"]).config(["$provide",function(e){e.decorator("uibDatepickerPopupDirective",n),e.decorator("dateFilter",r)}]).run(["$templateCache",function(e){o=e,["day","month","year"].forEach(i)}])})}(CRM.$),define("common/services/angular-date/date-format",["common/angular","common/modules/angular-date","common/services/hr-settings"],function(e,t){"use strict";t.factory("DateFormat",["$q","HR_settings",function(e,t){return{dateFormat:null,getDateFormat:function(){return this.dateFormat?e.when(this.dateFormat):e.when("dd/MM/yyyy").catch(function(){return"yyyy-MM-dd"}).then(function(e){return t.DATE_FORMAT=e,this.dateFormat=e,e}.bind(this))}}}])}),define("common/filters/angular-date/format-date",["common/moment","common/modules/angular-date","common/services/hr-settings"],function(e,t){"use strict";t.filter("formatDate",["HR_settings",function(t){var n=["DD-MM-YYYY","DD-MM-YYYY HH:mm:ss","YYYY-MM-DD","YYYY-MM-DD HH:mm:ss","DD/MM/YYYY","x","YYYY-MM-DD HH:mm:ss"];return function(r,i,o){var a,s=i||t.DATE_FORMAT||"YYYY-MM-DD",l=e(0);return r instanceof Date&&(r=e(r).format("YYYY-MM-DD HH:mm:ss")),a=e(r,n,!0),a.isValid()&&!a.isSame(l)?i===Date?a.toDate():a.format(s.toUpperCase())+("hours"===o?" "+a.format("HH:mm"):""):"Unspecified"}}])}),define("common/directives/angular-date/date-input",["common/modules/angular-date","common/filters/angular-date/format-date"],function(e){"use strict";e.directive("dateInput",["$filter",function(e){return{require:"ngModel",link:function(t,n,r,i){function o(t){var n=e("formatDate")(t);return n="Unspecified"==n?"":n}i.$formatters.push(o),i.$parsers=[]}}}])}),define("common/bundles/angular-date",["common/services/angular-date/date-format","common/filters/angular-date/format-date","common/directives/angular-date/date-input"],function(){}),define("common/modules/routers/compu-ng-route",["common/angular","common/angularRoute"],function(e){"use strict";return e.module("compuNgRoute",["ngRoute"]).config(["$routeProvider",function(t){var n=t.when;t.resolveForAll=function(e){return t.commonResolve=e,t},t.when=function(r,i){return e.extend(i.resolve||{},t.commonResolve||{}),n.call(t,r,i)}}])}),"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function r(e,t){return L(new(L(function(){},{prototype:e})),t)}function i(e){return j(arguments,function(t){t!==e&&j(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var r in e.path){if(e.path[r]!==t.path[r])break;n.push(e.path[r])}return n}function a(e){if(Object.keys)return Object.keys(e);var t=[];return j(e,function(e,n){t.push(n)}),t}function s(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,r=Number(arguments[2])||0;for(0>(r=0>r?Math.ceil(r):Math.floor(r))&&(r+=n);n>r;r++)if(r in e&&e[r]===t)return r;return-1}function l(e,t,n,r){var i,l=o(n,r),u={},c=[];for(var f in l)if(l[f].params&&(i=a(l[f].params),i.length))for(var d in i)s(c,i[d])>=0||(c.push(i[d]),u[i[d]]=e[i[d]]);return L({},u,t)}function u(e,t,n){if(!n){n=[];for(var r in e)n.push(r)}for(var i=0;i "));if(y[n]=r,I(e))g.push(n,[function(){return t.get(e)}],u);else{var i=t.annotate(e);j(i,function(e){e!==n&&l.hasOwnProperty(e)&&p(l[e],e)}),g.push(n,e,i)}v.pop(),y[n]=o}}function h(e){return P(e)&&e.then&&e.$$promises}if(!P(l))throw new Error("'invocables' must be an object");var m=a(l||{}),g=[],v=[],y={};return j(l,p),l=v=y=null,function(r,o,a){function s(){--b||($||i(y,o.$$values),p.$$values=y,p.$$promises=p.$$promises||!0,delete p.$$inheritedValues,u.resolve(y))}function l(e){p.$$failure=e,u.reject(e)}if(h(r)&&a===n&&(a=o,o=r,r=null),r){if(!P(r))throw new Error("'locals' must be an object")}else r=c;if(o){if(!h(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=f;var u=e.defer(),p=u.promise,v=p.$$promises={},y=L({},r),b=1+g.length/3,$=!1;if(N(o.$$failure))return l(o.$$failure),p;o.$$inheritedValues&&i(y,d(o.$$inheritedValues,m)),L(v,o.$$promises),o.$$values?($=i(y,d(o.$$values,m)),p.$$inheritedValues=d(o.$$values,m),s()):(o.$$inheritedValues&&(p.$$inheritedValues=d(o.$$inheritedValues,m)),o.then(s,l));for(var w=0,x=g.length;x>w;w+=3)r.hasOwnProperty(g[w])?s():function(n,i,o){function u(e){f.reject(e),l(e)}function c(){if(!N(p.$$failure))try{f.resolve(t.invoke(i,a,y)),f.promise.then(function(e){y[n]=e,s()},u)}catch(e){u(e)}}var f=e.defer(),d=0;j(o,function(e){v.hasOwnProperty(e)&&!r.hasOwnProperty(e)&&(d++,v[e].then(function(t){y[e]=t,--d||c()},u))}),d||c(),v[n]=f.promise}(g[w],g[w+1],g[w+2]);return p}},this.resolve=function(e,t,n,r){return this.study(e)(t,n,r)}}function g(e,t,n){this.fromConfig=function(e,t,n){return N(e.template)?this.fromString(e.template,t):N(e.templateUrl)?this.fromUrl(e.templateUrl,t):N(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return R(e)?e(t):e},this.fromUrl=function(n,r){return R(n)&&(n=n(r)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,r){return n.invoke(e,null,r||{params:t})}}function v(e,t,i){function o(t,n,r,i){if(g.push(t),h[t])return h[t];if(!/^\w+(-+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(m[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return m[t]=new H.Param(t,n,r,i),m[t]}function a(e,t,n,r){var i=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:i=["(",")"+(r?"?":"")];break;case!0:i=["?(",")?"];break;default:i=["("+n+"|",")?"]}return o+i[0]+t+i[1]}function s(i,o){var a,s,l,u,c;return a=i[2]||i[3],c=t.params[a],l=e.substring(d,i.index),s=o?i[4]:i[4]||("*"==i[1]?".*":null),u=H.type(s||"string")||r(H.type("string"),{pattern:new RegExp(s,t.caseInsensitive?"i":n)}),{id:a,regexp:s,segment:l,type:u,cfg:c}}t=L({params:{}},P(t)?t:{});var l,u=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,c=/([:]?)([\w\[\]-]+)|\{([\w\[\]-]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,f="^",d=0,p=this.segments=[],h=i?i.params:{},m=this.params=i?i.params.$$new():new H.ParamSet,g=[];this.source=e;for(var v,y,b;(l=u.exec(e))&&(v=s(l,!1),!(v.segment.indexOf("?")>=0));)y=o(v.id,v.type,v.cfg,"path"),f+=a(v.segment,y.type.pattern.source,y.squash,y.isOptional),p.push(v.segment),d=u.lastIndex;b=e.substring(d);var $=b.indexOf("?");if($>=0){var w=this.sourceSearch=b.substring($);if(b=b.substring(0,$),this.sourcePath=e.substring(0,d+$),w.length>0)for(d=0;l=c.exec(w);)v=s(l,!0),y=o(v.id,v.type,v.cfg,"search"),d=u.lastIndex}else this.sourcePath=e,this.sourceSearch="";f+=a(b)+(!1===t.strict?"/?":"")+"$",p.push(b),this.regexp=new RegExp(f,t.caseInsensitive?"i":n),this.prefix=p[0],this.$$paramNames=g}function y(e){L(this,e)}function b(){function e(e){return null!=e?e.toString().replace(/\//g,"%2F"):e}function i(e){return null!=e?e.toString().replace(/%2F/g,"/"):e}function o(){return{strict:m,caseInsensitive:d}}function l(e){return R(e)||F(e)&&R(e[e.length-1])}function u(){for(;x.length;){var e=x.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend($[e.name],f.invoke(e.def))}}function c(e){L(this,e||{})}H=this;var f,d=!1,m=!0,g=!1,$={},w=!0,x=[],C={string:{encode:e,decode:i,is:function(e){return null==e||!N(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return N(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};b.$$getDefaultValue=function(e){if(!l(e.value))return e.value;if(!f)throw new Error("Injectable functions cannot be called at configuration time");return f.invoke(e.value)},this.caseInsensitive=function(e){return N(e)&&(d=e),d},this.strictMode=function(e){return N(e)&&(m=e),m},this.defaultSquashPolicy=function(e){if(!N(e))return g;if(!0!==e&&!1!==e&&!I(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return g=e,e},this.compile=function(e,t){return new v(e,L(o(),t))},this.isMatcher=function(e){if(!P(e))return!1;var t=!0;return j(v.prototype,function(n,r){R(n)&&(t=t&&N(e[r])&&R(e[r]))}),t},this.type=function(e,t,n){if(!N(t))return $[e];if($.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return $[e]=new y(L({name:e},t)),n&&(x.push({name:e,def:n}),w||u()),this},j(C,function(e,t){$[t]=new y(L({name:t},e))}),$=r($,{}),this.$get=["$injector",function(e){return f=e,w=!1,u(),j(C,function(e,t){$[t]||($[t]=new y(e))}),this}],this.Param=function(e,t,r,i){function o(){if(!f)throw new Error("Injectable functions cannot be called at configuration time");var e=f.invoke(r.$$fn);if(null!==e&&e!==n&&!d.type.is(e))throw new Error("Default value ("+e+") for parameter '"+d.id+"' is not an instance of Type ("+d.type.name+")");return e}function u(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=h(p(d.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),N(e)?d.type.$normalize(e):o()}function c(){return"{Param:"+e+" "+t+" squash: '"+b+"' optional: "+v+"}"}var d=this;r=function(e){var t=P(e)?a(e):[];return-1===s(t,"value")&&-1===s(t,"type")&&-1===s(t,"squash")&&-1===s(t,"array")&&(e={value:e}),e.$$fn=l(e.value)?e.value:function(){return e.value},e}(r),t=function(t,n,r){if(t.type&&n)throw new Error("Param '"+e+"' has two type configurations.");return n||(t.type?t.type instanceof y?t.type:new y(t.type):"config"===r?$.any:$.string)}(r,t,i);var m=function(){var t={array:"search"===i&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return L(t,n,r).array}();t=m?t.$asArray(m,"search"===i):t,"string"!==t.name||m||"path"!==i||r.value!==n||(r.value="");var v=r.value!==n,b=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!N(n)||null==n)return g;if(!0===n||I(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,v),w=function(e,t,r,i){var o,a,l=[{from:"",to:r||t?n:""},{from:null,to:r||t?n:""}];return o=F(e.replace)?e.replace:[],I(i)&&o.push({from:i,to:n}),a=h(o,function(e){return e.from}),p(l,function(e){return-1===s(a,e.from)}).concat(o)}(r,m,v,b);L(this,{id:e,type:t,location:i,array:m,squash:b,replace:w,isOptional:v,value:u,dynamic:n,config:r,toString:c})},c.prototype={$$new:function(){return r(this,L(new c,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,r=a(c.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),j(t,function(t){j(a(t),function(t){-1===s(e,t)&&-1===s(r,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return j(n.$$keys(),function(r){t[r]=n[r].value(e&&e[r])}),t},$$equals:function(e,t){var n=!0,r=this;return j(r.$$keys(),function(i){var o=e&&e[i],a=t&&t[i];r[i].type.equals(o,a)||(n=!1)}),n},$$validates:function(e){var r,i,o,a,s,l=this.$$keys();for(r=0;ri;i++)if(t(u[i]))return;c&&t(c)}}function p(){return l=l||i.$on("$locationChangeSuccess",d)}var h,m=a.baseHref(),g=r.url();return f||p(),{sync:function(){d()},listen:function(){return p()},update:function(e){return e?void(g=r.url()):void(r.url()!==g&&(r.url(g),r.replace()))},push:function(e,t,i){var o=e.format(t||{});null!==o&&t&&t["#"]&&(o+="#"+t["#"]),r.url(o),h=i&&i.$$avoidResync?r.url():n,i&&i.replace&&r.replace()},href:function(n,i,o){if(!n.validates(i))return null;var a=e.html5Mode();t.isObject(a)&&(a=a.enabled);var l=n.format(i);if(o=o||{},a||null===l||(l="#"+e.hashPrefix()+l),null!==l&&i&&i["#"]&&(l+="#"+i["#"]),l=s(l,a,o.absolute),!o.absolute||!l)return l;var u=!a&&l?"/":"",c=r.port();return c=80===c||443===c?"":":"+c,[r.protocol(),"://",r.host(),c,u,l].join("")}}}var l,u=[],c=null,f=!1;this.rule=function(e){if(!R(e))throw new Error("'rule' must be a function");return u.push(e),this},this.otherwise=function(e){if(I(e)){var t=e;e=function(){return t}}else if(!R(e))throw new Error("'rule' must be a function");return c=e,this},this.when=function(e,t){var n,s=I(t);if(I(e)&&(e=r.compile(e)),!s&&!R(t)&&!F(t))throw new Error("invalid 'handler' in when()");var l={matcher:function(e,t){return s&&(n=r.compile(t),t=["$match",function(e){return n.format(e)}]),L(function(n,r){return a(n,t,e.exec(r.path(),r.search()))},{prefix:I(e.prefix)?e.prefix:""})},regex:function(e,t){if(e.global||e.sticky)throw new Error("when() RegExp must not be global or sticky");return s&&(n=t,t=["$match",function(e){return o(n,e)}]),L(function(n,r){return a(n,t,e.exec(r.path()))},{prefix:i(e)})}},u={matcher:r.isMatcher(e),regex:e instanceof RegExp};for(var c in u)if(u[c])return this.rule(l[c](e,t));throw new Error("invalid 'what' in when()")},this.deferIntercept=function(e){e===n&&(e=!0),f=e},this.$get=s,s.$inject=["$location","$rootScope","$injector","$browser"]}function w(e,i){function o(e){return 0===e.indexOf(".")||0===e.indexOf("^")}function d(e,t){if(!e)return n;var r=I(e),i=r?e:e.name;if(o(i)){if(!t)throw new Error("No reference point given for path '"+i+"'");t=d(t);for(var a=i.split("."),s=0,l=a.length,u=t;l>s;s++)if(""!==a[s]||0!==s){if("^"!==a[s])break;if(!u.parent)throw new Error("Path '"+i+"' not valid for state '"+t.name+"'");u=u.parent}else u=t;a=a.slice(s).join("."),i=u.name+(u.name&&a?".":"")+a}var c=E[i];return!c||!r&&(r||c!==e&&c.self!==e)?n:c}function p(e,t){S[e]||(S[e]=[]),S[e].push(t)}function m(e){for(var t=S[e]||[];t.length;)g(t.shift())}function g(t){t=r(t,{self:t,resolve:t.resolve||{},toString:function(){return this.name}});var n=t.name;if(!I(n)||n.indexOf("@")>=0)throw new Error("State must have a valid name");if(E.hasOwnProperty(n))throw new Error("State '"+n+"'' is already defined");var i=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):I(t.parent)?t.parent:P(t.parent)&&I(t.parent.name)?t.parent.name:"";if(i&&!E[i])return p(i,t.self);for(var o in M)R(M[o])&&(t[o]=M[o](t,M.$delegates[o]));return E[n]=t,!t[_]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){k.$current.navigable==t&&u(e,n)||k.transitionTo(t,e,{inherit:!0,location:!1})}]),m(n),t}function v(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=k.$current.name.split("."),r=0,i=t.length;i>r;r++)"*"===t[r]&&(n[r]="*");return"**"===t[0]&&(n=n.slice(s(n,t[1])),n.unshift("**")),"**"===t[t.length-1]&&(n.splice(s(n,t[t.length-2])+1,Number.MAX_VALUE),n.push("**")),t.length==n.length&&n.join("")===t.join("")}function b(e,t){return I(e)&&!N(t)?M[e]:R(t)&&I(e)?(M[e]&&!M.$delegates[e]&&(M.$delegates[e]=M[e]),M[e]=t,this):this}function $(e,t){return P(e)?t=e:t.name=e,g(t),this}function w(e,i,o,s,f,p,m,g,b){function $(t,n,r,o){var a=e.$broadcast("$stateNotFound",t,n,r);if(a.defaultPrevented)return m.update(),T;if(!a.retry)return null;if(o.$retry)return m.update(),D;var s=k.transition=i.when(a.retry);return s.then(function(){return s!==k.transition?S:(t.options.$retry=!0,k.transitionTo(t.to,t.toParams,t.options))},function(){return T}),m.update(),s}function w(e,n,r,a,l,u){function d(){var n=[];return j(e.views,function(r,i){var a=r.resolve&&r.resolve!==e.resolve?r.resolve:{};a.$template=[function(){return o.load(i,{view:r,locals:l.globals,params:p,notify:u.notify})||""}],n.push(f.resolve(a,l.globals,l.resolve,e).then(function(n){if(R(r.controllerProvider)||F(r.controllerProvider)){var o=t.extend({},a,l.globals);n.$$controller=s.invoke(r.controllerProvider,null,o)}else n.$$controller=r.controller;n.$$state=e,n.$$controllerAs=r.controllerAs,l[i]=n}))}),i.all(n).then(function(){return l.globals})}var p=r?n:c(e.params.$$keys(),n),h={$stateParams:p};l.resolve=f.resolve(e.resolve,h,l.resolve,e);var m=[l.resolve.then(function(e){l.globals=e})];return a&&m.push(a),i.all(m).then(d).then(function(e){return l})}var S=i.reject(new Error("transition superseded")),M=i.reject(new Error("transition prevented")),T=i.reject(new Error("transition aborted")),D=i.reject(new Error("transition failed"));return C.locals={resolve:null,globals:{$stateParams:{}}},k={params:{},current:C.self,$current:C,transition:null},k.reload=function(e){return k.transitionTo(k.current,p,{reload:e||!0,inherit:!1,notify:!0})},k.go=function(e,t,n){return k.transitionTo(e,t,L({inherit:!0,relative:k.$current},n))},k.transitionTo=function(t,n,o){n=n||{},o=L({location:!0,inherit:!1,relative:null,notify:!0,reload:!1,$retry:!1},o||{});var a,u=k.$current,f=k.params,h=u.path,g=d(t,o.relative),v=n["#"];if(!N(g)){var y={to:t,toParams:n,options:o},b=$(y,u.self,f,o);if(b)return b;if(t=y.to,n=y.toParams,o=y.options,g=d(t,o.relative),!N(g)){if(!o.relative)throw new Error("No such state '"+t+"'");throw new Error("Could not resolve '"+t+"' from state '"+o.relative+"'")}}if(g[_])throw new Error("Cannot transition to abstract state '"+t+"'");if(o.inherit&&(n=l(p,n||{},k.$current,g)),!g.params.$$validates(n))return D;n=g.params.$$values(n),t=g;var E=t.path,T=0,A=E[T],O=C.locals,R=[];if(o.reload){if(I(o.reload)||P(o.reload)){if(P(o.reload)&&!o.reload.name)throw new Error("Invalid reload state object");var F=!0===o.reload?h[0]:d(o.reload);if(o.reload&&!F)throw new Error("No such reload state '"+(I(o.reload)?o.reload:o.reload.name)+"'");for(;A&&A===h[T]&&A!==F;)O=R[T]=A.locals,T++,A=E[T]}}else for(;A&&A===h[T]&&A.ownParams.$$equals(n,f);)O=R[T]=A.locals,T++,A=E[T];if(x(t,n,u,f,O,o))return v&&(n["#"]=v),k.params=n,U(k.params,p),o.location&&t.navigable&&t.navigable.url&&(m.push(t.navigable.url,n,{$$avoidResync:!0,replace:"replace"===o.location}),m.update(!0)),k.transition=null,i.when(k.current);if(n=c(t.params.$$keys(),n||{}),o.notify&&e.$broadcast("$stateChangeStart",t.self,n,u.self,f).defaultPrevented)return e.$broadcast("$stateChangeCancel",t.self,n,u.self,f),m.update(),M;for(var j=i.when(O),H=T;H=T;r--)a=h[r],a.self.onExit&&s.invoke(a.self.onExit,a.self,a.locals.globals),a.locals=null;for(r=T;r=0?i:i+"@"+(o?o.state.name:"")}function _(e,t){var n,r=e.match(/^\s*({[^}]*})\s*$/);if(r&&(e=t+"("+r[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function M(e){var t=e.parent().inheritedData("$uiView");return t&&t.state&&t.state.name?t.state:void 0}function T(e,n){var r=["location","inherit","reload","absolute"];return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(i,o,a,s){var l=_(a.uiSref,e.current.name),u=null,c=M(o)||e.$current,f="[object SVGAnimatedString]"===Object.prototype.toString.call(o.prop("href"))?"xlink:href":"href",d=null,p="A"===o.prop("tagName").toUpperCase(),h="FORM"===o[0].nodeName,m=h?"action":f,g=!0,v={relative:c,inherit:!0},y=i.$eval(a.uiSrefOpts)||{};t.forEach(r,function(e){e in y&&(v[e]=y[e])});var b=function(n){if(n&&(u=t.copy(n)),g){d=e.href(l.state,u,v);var r=s[1]||s[0];return r&&r.$$addStateInfo(l.state,u),null===d?(g=!1,!1):void a.$set(m,d)}};l.paramExpr&&(i.$watch(l.paramExpr,function(e,t){e!==u&&b(e)},!0),u=t.copy(i.$eval(l.paramExpr))),b(),h||o.bind("click",function(t){if(!((t.which||t.button)>1||t.ctrlKey||t.metaKey||t.shiftKey||o.attr("target"))){var r=n(function(){e.go(l.state,u,v)});t.preventDefault();var i=p&&!d?1:0;t.preventDefault=function(){i--<=0&&n.cancel(r)}}})}}}function D(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs",function(t,r,i){function o(){a()?r.addClass(l):r.removeClass(l)}function a(){for(var e=0;er;r++){o=a[r];var c=this.params[o],f=n[r+1];for(i=0;ir;r++)o=a[r],u[o]=this.params[o].value(t[o]);return u},v.prototype.parameters=function(e){return N(e)?this.params[e]||null:this.$$paramNames},v.prototype.validates=function(e){return this.params.$$validates(e)},v.prototype.format=function(e){function t(e){return encodeURIComponent(e).replace(/-/g,function(e){return"%5C%"+e.charCodeAt(0).toString(16).toUpperCase()})}e=e||{};var n=this.segments,r=this.parameters(),i=this.params;if(!this.validates(e))return null;var o,a=!1,s=n.length-1,l=r.length,u=n[0];for(o=0;l>o;o++){var c=s>o,f=r[o],d=i[f],p=d.value(e[f]),m=d.isOptional&&d.type.equals(d.value(),p),g=!!m&&d.squash,v=d.type.encode(p);if(c){var y=n[o+1];if(!1===g)null!=v&&(u+=F(v)?h(v,t).join("-"):encodeURIComponent(v)),u+=y;else if(!0===g){var b=u.match(/\/$/)?/\/?(.*)/:/(.*)/;u+=y.match(b)[1]}else I(g)&&(u+=g+y)}else{if(null==v||m&&!1!==g)continue;F(v)||(v=[v]),v=h(v,encodeURIComponent).join("&"+f+"="),u+=(a?"&":"?")+f+"="+v,a=!0}}return u},y.prototype.is=function(e,t){return!0},y.prototype.encode=function(e,t){return e},y.prototype.decode=function(e,t){return e},y.prototype.equals=function(e,t){return e==t},y.prototype.$subPattern=function(){var e=this.pattern.toString();return e.substr(1,e.length-2)},y.prototype.pattern=/.*/,y.prototype.toString=function(){return"{Type:"+this.name+"}"},y.prototype.$normalize=function(e){return this.is(e)?e:this.decode(e)},y.prototype.$asArray=function(e,t){function r(e,t){function r(e,t){return function(){return e[t].apply(e,arguments)}}function i(e){return F(e)?e:N(e)?[e]:[]}function o(e){switch(e.length){case 0:return n;case 1:return"auto"===t?e[0]:e;default:return e}}function a(e){return!e}function s(e,t){return function(n){n=i(n);var r=h(n,e);return!0===t?0===p(r,a).length:o(r)}}this.encode=s(r(e,"encode")),this.decode=s(r(e,"decode")),this.is=s(r(e,"is"),!0),this.equals=function(e){return function(t,n){var r=i(t),o=i(n);if(r.length!==o.length)return!1 ;for(var a=0;a=":n(e.from)}:{"<=":n(e.to)}}function o(e){return e.in?{IN:e.in}:{"NOT IN":e.nin}}return{extend:function(t){return e.assign(Object.create(this),t)},compactFilters:function(t){return t?e.pick(t,function(e){return 0===e||!1===e||!!e}):null},processFilters:function(t){return t?(t=this.compactFilters(t),e.transform(t,function(e,t,n){t.from||t.to?e[n]=i(t):t.in||t.nin?e[n]=o(t):e[n]=t},{})):null}}})}),define("common/models/contact-job-role.model",["common/modules/models","common/models/model","common/instances/contact-job-role-instance.instance","common/services/api/contact-job-role-api.api"],function(e){"use strict";e.factory("ContactJobRole",["$log","Model","ContactJobRoleAPI","ContactJobRoleInstance",function(e,t,n,r){return e.debug("ContactJobRole"),t.extend({all:function(e){return n.all(e).then(function(e){return e.list.map(function(e){return r.init(e,!0)})})}})}])}),define("common/models/instances/group-instance",["common/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("GroupInstance",["ModelInstance",function(e){var t=["id","name","title","description"];return e.extend({fromAPIFilter:function(e,n,r){_.includes(t,r)&&(e[r]=this[r])}})}])}),define("common/mocks/module",["common/angular"],function(e){"use strict";return e.module("common.mocks",[])}),define("common/mocks/services/api/group-mock",["common/lodash","common/mocks/module"],function(e,t){"use strict";t.factory("api.group.mock",["$q",function(t){function n(e){var n=t.defer();return n.resolve(e),n.promise}return{all:function(e,t,r){var i,o,a;return i=r||this.mockedGroups().list,e&&(i=i.filter(function(t){return Object.keys(e).every(function(n){return t[n]===e[n]})})),t&&(o=(t.page-1)*t.size,a=o+t.size,i=i.slice(o,a)),n({list:i,total:i.length,allIds:i.map(function(e){return e.id}).join(",")})},find:function(e,t){return n(t||this.mockedGroups().list.filter(function(t){return t.id===e})[0])},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedGroups:function(){return{total:5,list:[{id:"1",name:"Administrators",title:"Administrators",description:"Contacts in this group are assigned Administrator role permissions.",is_active:"1",visibility:"User and User Admin Only",group_type:["1"],is_hidden:"0",is_reserved:"0"},{id:"2",name:"Newsletter Subscribers",title:"Newsletter Subscribers",is_active:'"1',visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"3",name:"Summer Program Volunteers",title:"Summer Program Volunteers",is_active:"1",visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"4",name:"Advisory Board",title:"Advisory Board",is_active:"1",visibility:"Public Pages",where_clause:"...",select_tables:"...",where_tables:"...",group_type:["1","2"],is_hidden:"0",is_reserved:"0"},{id:"5",name:"Case_Resources",title:"Case Resources",description:"Contacts in this group are listed with their phone number and email when viewing case. You also can send copies of case activities to these contacts.",is_active:"1",visibility:"User and User Admin Only",where_clause:"...",select_tables:"...",where_tables:"...",group_type:"2",is_hidden:"0",is_reserved:"0"}]}}}}])}),define("common/mocks/data/contact.data",[],function(){return{all:{is_error:0,version:3,count:26,values:[{id:"1",contact_id:"1",display_name:"Dr. Kiara Jensen-Parker",email:"kh.jensen-parker@testing.info",contact_type:"Individual"},{id:"2",contact_id:"2",display_name:"jacobc82@lol.co.pl",email:"cruz.v.jacob@spamalot.com",contact_type:"Individual"},{id:"3",contact_id:"3",display_name:"Mei Müller-Nielsen",email:"mz.mller-nielsen75@infomail.co.pl",contact_type:"Individual"},{id:"4",contact_id:"4",display_name:"Ms. Brigette Deforest",email:"deforest.p.brigette9@fakemail.info",contact_type:"Individual"},{id:"5",contact_id:"5",display_name:"robertsc@testing.net",email:"clintr56@mymail.org",contact_type:"Individual"},{id:"6",contact_id:"6",display_name:"Dr. Allen Samuels Sr.",email:"samuelsa@mymail.org",contact_type:"Individual"},{id:"7",contact_id:"7",display_name:"Mei Wilson",email:"wilson.u.mei59@sample.org",contact_type:"Individual"},{id:"8",contact_id:"8",display_name:"Dr. Betty Díaz",email:"dazb@sample.co.nz",contact_type:"Individual"},{id:"9",contact_id:"9",display_name:"Bob Jones-Dimitrov",email:"bobj@testmail.biz",contact_type:"Individual"},{id:"10",contact_id:"10",display_name:"Truman Samuels III",email:"trumans@spamalot.org",contact_type:"Individual"},{id:"11",contact_id:"11",display_name:"Iris Wagner",email:"iwagner75@notmail.info",contact_type:"Individual"},{id:"12",contact_id:"12",display_name:"Mr. Rosario McReynolds",email:"rosariomcreynolds@testmail.org",contact_type:"Individual"},{id:"13",contact_id:"13",display_name:"Shad Jones-Dimitrov III",email:"shadj@lol.net",contact_type:"Individual"},{id:"14",contact_id:"14",display_name:"Toby Cruz Sr.",email:"",contact_type:"Individual"},{id:"15",contact_id:"15",display_name:"lareedaz61@testing.com",email:"lareedaz61@testing.com",contact_type:"Individual"},{id:"16",contact_id:"16",display_name:"Dr. Jay Deforest",email:"jayd@fishmail.org",contact_type:"Individual"},{id:"17",contact_id:"17",display_name:"Mr. Norris Cruz",email:"norriscruz@spamalot.info",contact_type:"Individual"},{id:"18",contact_id:"18",display_name:"herminiac@fishmail.com",email:"herminiac@fishmail.com",contact_type:"Individual"},{id:"19",contact_id:"19",display_name:"Ashley Terrell",email:"terrell.ashley@testmail.info",contact_type:"Individual"},{id:"20",contact_id:"20",display_name:"Kandace Parker-Díaz",email:"parker-daz.kandace67@fishmail.co.uk",contact_type:"Individual"},{id:"21",contact_id:"21",display_name:"Nicole Samuels",email:"ng.samuels@testmail.net",contact_type:"Individual"},{id:"22",contact_id:"22",display_name:"Dr. Kandace Wattson",email:"kandacewattson@testing.info",contact_type:"Individual"},{id:"23",contact_id:"23",display_name:"Brittney Cruz",email:"cruz.brittney@spamalot.co.nz",contact_type:"Individual"},{id:"24",contact_id:"24",display_name:"Shauna Olsen",email:"",contact_type:"Individual"},{id:"202",contact_id:"202",display_name:"civihr_staff@compucorp.co.uk",email:"civihr_staff@compucorp.co.uk",contact_type:"Individual"},{id:"203",contact_id:"203",display_name:"civihr_manager@compucorp.co.uk",email:"civihr_manager@compucorp.co.uk",contact_type:"Individual"}]}}}),define("common/mocks/services/api/contact-mock",["common/lodash","common/mocks/module","common/mocks/data/contact.data"],function(e,t,n){"use strict";t.factory("api.contact.mock",["$q",function(t){function r(e){var n=t.defer();return n.resolve(e),n.promise}return{all:function(t,i,o,a,s){var l,u,c;return l=s||n.all.values,t&&(l=l.filter(function(n){return Object.keys(t).every(function(r){return null===t[r]||("display_name"===r?new RegExp(t[r],"i").test(n[r]):t[r].IN?e.includes(t[r].IN,n[r]):n[r]===t[r])})})),i&&(u=(i.page-1)*i.size,c=u+i.size,l=l.slice(u,c)),r({list:l,total:l.length,allIds:l.map(function(e){return e.id}).join(",")})},find:function(e,t){return r(t||n.all.values.filter(function(t){return t.id===e})[0])},leaveManagees:function(){return r(this.mockedContacts().list)},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedContacts:function(){var e=n.all.values;return{total:e.length,list:e.map(function(e){return e})}}}}])}),define("common/mocks/services/api/group-contact-mock",["common/lodash","common/mocks/module","common/mocks/services/api/contact-mock","common/mocks/services/api/group-mock"],function(e,t){"use strict";t.factory("api.group-contact.mock",["$q","api.contact.mock","api.group.mock",function(t,n,r){function i(t){return e.sample(t)}function o(e){var n=t.defer();return n.resolve(e),n.promise}var a=n.mockedContacts().list,s=r.mockedGroups().list;return{all:function(e,t,n){var r,i,a;return r=n||this.mockedGroupsContacts.list,e&&(r=r.filter(function(t){return Object.keys(e).every(function(n){return t[n]===e[n]})})),t&&(i=(t.page-1)*t.size,a=i+t.size,r=r.slice(i,a)),o({list:r,total:r.length,allIds:r.map(function(e){return e.id}).join(",")})},spyOnMethods:function(){e.functions(this).forEach(function(e){spyOn(this,e).and.callThrough()}.bind(this))},mockedGroupsContacts:{total:a.length,list:function(){var e=1;return a.map(function(t){return{id:""+e++,group_id:i(s).id,contact_id:t.id,status:"Added"}})}()}}}])}),define("common/models/group",["common/modules/models","common/models/model","common/models/instances/group-instance","common/mocks/services/api/group-mock","common/mocks/services/api/group-contact-mock"],function(e){"use strict";e.factory("Group",["Model","api.group.mock","api.group-contact.mock","GroupInstance",function(e,t,n,r){return e.extend({all:function(e,n){return t.all(this.processFilters(e),n).then(function(e){return e.list=e.list.map(function(e){return r.init(e,!0)}),e})},find:function(e){return t.find(e).then(function(e){return r.init(e,!0)})},contactIdsOf:function(e){return n.all({group_id:e}).then(function(e){return e.list.map(function(e){return e.contact_id})})}})}])}),define("common/models/instances/job-role-instance",["common/lodash","common/moment","common/modules/models-instances","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("JobRoleInstance",["ModelInstance","HR_settings",function(n,r){return n.extend({fromAPIFilter:function(n,i,o){var a=r.DATE_FORMAT.toUpperCase();e.endsWith(o,"_date")?n[o]=t(this[o],"YYYY-MM-DD HH:mm:ss").format(a):"api.HRJobContract.getsingle"===o?(n.contact_id=this[o].contact_id,n.job_contract_id=this[o].id):n[o]=this[o]},toAPIFilter:function(n,i,o){var a=["contact_id","job_contract_id"],s=r.DATE_FORMAT.toUpperCase();if(e.endsWith(o,"_date"))n[o]=t(this[o],s).format("YYYY-MM-DD HH:mm:ss");else{if(e.includes(a,o))return;n[o]=this[o]}}})}])}),define("common/services/api/job-role",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.job-role",["$log","api",function(e,t){return e.debug("api.jobRole"),t.extend({all:function(t,n,r,i){return e.debug("api.jobRole.api"),this.getAll("HrJobRoles",t,n,r,i)},find:function(t){return e.debug("api.jobRole.find"),this.sendGET("HRJobRole","get",{id:""+t},!1).then(function(e){return e.values[0]})}})}])}),define("common/models/job-role",["common/modules/models","common/models/model","common/models/instances/job-role-instance","common/services/api/job-role"],function(e){"use strict";e.factory("JobRole",["Model","api.job-role","JobRoleInstance",function(e,t,n){return e.extend({all:function(e,r){return t.all(this.processFilters(e),r).then(function(e){return e.list=e.list.map(function(e){return n.init(e,!0)}),e})},find:function(e){return t.find(e).then(function(e){return n.init(e,!0)})}})}])}),define("common/services/api/contact",["common/modules/apis","common/services/api"],function(e){"use strict";e.factory("api.contact",["$log","api",function(e,t){return e.debug("api.contact"),t.extend({all:function(t,n,r,i){return e.debug("api.contact.api"),this.getAll("Contact",t,n,r,i)},find:function(t){return e.debug("api.contact.find"),this.sendGET("Contact","get",{id:""+t},!1).then(function(e){return e.values[0]})},leaveManagees:function(t,n){return e.debug("api.contact.leaveManagees"),n=_.assign({},n,{managed_by:t}),this.sendGET("Contact","getleavemanagees",n).then(function(e){return e.values})}})}])}),define("common/models/instances/contact-instance",["common/modules/models-instances","common/models/instances/instance","common/services/api/contact"],function(e){"use strict";e.factory("ContactInstance",["ModelInstance","api.contact",function(e,t){return e.extend({leaveManagees:function(e){return t.leaveManagees(this.id,e)}})}])}),define("common/models/contact",["common/lodash","common/modules/models","common/models/model","common/models/contact-job-role.model","common/models/group","common/models/job-role","common/models/instances/contact-instance","common/services/api/contact"],function(e,t){"use strict";t.factory("Contact",["$q","Model","api.contact","Group","JobRole","ContactJobRole","ContactInstance",function(t,n,r,i,o,a,s){function l(t,n){return!e.isEmpty(e.intersection(e.keys(t),n))}function u(e){return a.all(e).then(function(e){return e.map(function(e){return e.contact_id})})}function c(t,n){return e(t).omit(d).omit(p).assign({id:{in:e.intersection.apply(null,n)}}).value()}function f(n){var r=t.defer(),o=[];return n=this.compactFilters(n),l(n,p)&&o.push(u(e.pick(n,p))),l(n,d)&&o.push(i.contactIdsOf(n.group_id)),e.isEmpty(o)?r.resolve(this.processFilters(n)):t.all(o).then(function(e){n=c(n,e),r.resolve(this.processFilters(n))}.bind(this)),r.promise}var d=["group_id"],p=["region","department","level_type","location"];return n.extend({all:function(e,t,n,i){return f.call(this,e).then(function(e){return e&&e.id&&!e.id.IN.length?{list:[]}:r.all(e,t,n,i)}).then(function(e){return e.list=e.list.map(function(e){return s.init(e,!0)}),e})},find:function(e){return r.find(e).then(function(e){return s.init(e,!0)})},leaveManagees:function(e,t){return f.call(this,t).then(function(t){return t&&t.id&&!t.id.IN.length?[]:r.leaveManagees(e,t)})}})}])}),define("common/models/instances/contract-instance",["common/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("ContractInstance",["ModelInstance",function(e){return e.extend({})}])}),define("common/services/api/contract",["common/lodash","common/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("api.contract",["$log","api",function(t,n){function r(t){var n=e.clone(t);return n.info=n["api.HRJobContract.getfulldetails"],delete n["api.HRJobContract.getfulldetails"],n}return t.debug("api.contract"),n.extend({all:function(e){return t.debug("ContractAPI.all"),e=e||{},e["api.HRJobContract.getfulldetails"]={jobcontract_id:"$value.id"},e.deleted=0,this.sendGET("HRJobContract","get",e,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r)})}})}])}),define("common/models/contract",["common/modules/models","common/models/model","common/models/instances/contract-instance","common/services/api/contract"],function(e){"use strict";e.factory("Contract",["$log","Model","api.contract","ContractInstance",function(e,t,n,r){return e.debug("Contract"),t.extend({all:function(e){return n.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})}})}])}),define("common/models/option-group",["common/modules/models","common/models/model","common/services/api/option-group"],function(e){"use strict";e.factory("OptionGroup",["Model","api.optionGroup",function(e,t){return e.extend({valuesOf:function(e,n){return t.valuesOf(e,n)}})}])}),function(e,t){define("common/models/session.model",["common/modules/models","common/models/model"],function(n){"use strict";n.factory("Session",["$log","$q","Model",function(n,r,i){return n.debug("Session"),i.extend({get:function(){var n={contactId:e.vars.session?e.vars.session.contact_id:t.settings.currentCiviCRMUserId};if(!n.contactId)throw new Error("Session Error: *Logged In Contact Id* is not defined");return r.resolve(n)}})}])})}(CRM,window.Drupal),define("common/bundles/models",["common/instances/contact-job-role-instance.instance","common/models/model","common/models/contact","common/models/contact-job-role.model","common/models/contract","common/models/group","common/models/job-role","common/models/option-group","common/models/session.model","common/models/instances/instance","common/models/instances/contact-instance","common/models/instances/contract-instance","common/models/instances/group-instance","common/models/instances/job-role-instance"],function(){}),define("common/services/dialog/dialog",["common/lodash","common/modules/services"],function(e,t){"use strict";function n(t,n,r){function i(i){var o;if(!e.isObject(i))throw new Error("Dialog Service: Options passed should be an object");return o=n.children(),t.open({appendTo:o.length?o.eq(0):n,size:"sm",controller:"DialogController",template:r.get("dialog.html"),resolve:{options:function(){return i}}}).result}return{open:i}}t.factory("dialog",n),n.$inject=["$uibModal","$rootElement","$templateCache"]}),define("common/controllers/dialog/dialog-ctrl",["common/lodash","common/modules/controllers"],function(e,t){"use strict";function n(t,n,r,i){function o(t){e.assign(n,e.defaultsDeep(t,{title:"CiviHR",msg:"",copyConfirm:"",copyCancel:"",classConfirm:"btn-primary",loading:!1}))}function a(){r.close(!1)}function s(){n.loading=!0,r.closed.then(n.onCloseAfterConfirm),t.resolve().then(n.onConfirm).then(function(){r.close(!0)})}n.cancel=a,n.confirm=s,function(){o(i),i.optionsPromise&&i.optionsPromise().then(function(e){o(e)})}()}t.controller("DialogController",n),n.$inject=["$q","$scope","$uibModalInstance","options"]}),define("common/modules/dialog",["common/angular","common/services/dialog/dialog","common/controllers/dialog/dialog-ctrl","common/angularBootstrap","common/directives/loading","common/modules/templates"],function(e){"use strict";return e.module("common.dialog",["ui.bootstrap","common.directives","common.templates"])}),define("common/decorators/xeditable-civi/editable-directive-factory",[],function(){"use strict";return["$delegate",function(e){return function(t){var n=e(t);return n.compile=function(e){var t,r=e[0].attributes.getNamedItem("ng-href");return e.append(''),r&&(t=angular.element(""),t.text("Follow link"),t.attr(r.nodeName,r.value),t.attr("ng-click","$event.stopPropagation();"),t.addClass("editable-link"),e.append(t),e.addClass("editable-with-link")),{post:n.link}},n}}]}),define("common/directives/xeditable-civi/editable-ta",[],function(){"use strict";return["editableDirectiveFactory","$timeout",function(e,t){var n,r;return r=e({directiveName:"editableTa",inputTpl:"",render:function(){this.parent.render.call(this),this.inputEl.parent().parent().removeClass("form-inline"),this.inputEl.addClass("editable-ta"),this.inputEl.attr("ng-model","ta.$data"),this.inputEl.attr("ta-toolbar",this.attrs.eTaToolbar||'[["bold","italics","underline","strikeThrough","ul","ol","undo","redo","clear"]]'),t(function(){this.inputEl.find("textarea").hide()}.bind(this),0)},save:function(){this.scope.$data=this.scope.ta.$data,this.parent.save.call(this)},setLocalValue:function(){this.parent.setLocalValue.call(this),this.scope.ta.$data=this.scope.$data}}),n=r.link,r.link=function(e,t,r,i){return e.ta={},n(e,t,r,i)},r}]}),define("common/modules/xeditable-civi",["common/angular","common/decorators/xeditable-civi/editable-directive-factory","common/directives/xeditable-civi/editable-ta","common/angularXeditable","common/text-angular"],function(e,t,n){"use strict";return e.module("xeditable-civi",["xeditable","textAngular"]).directive("editableTa",n)}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/org.civicrm.reqangular/dist/reqangular.min.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js index 32bf4fcad04..d6b36fe1374 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js @@ -1,5 +1,5 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,o){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:t(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,o,s,i){return t.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return s.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,o,s){return t.debug("WorkPatternAPI.getCalendar",n,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,o){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,o,s,i){function r(t,n){return u().then(function(a){var o=this.days[c(t).valueOf()];return!!o&&e.find(a,function(e){return e.name===n}).value===o.type}.bind(this))}function c(e){return t(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[c(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,o){return t.debug("Calendar"),n.extend({get:function(n,s,i,r){return t.debug("Calendar.get"),a.getCalendar(n,s,i,r).then(function(t){var a=t.values.map(function(e){return o.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function o(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,o,s){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return o.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",t,n,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t,n,o,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var i=a.defer();t&&n||i.reject("contact_id and period_id are mandatory");var r={contact_id:t,period_id:n,statuses:o?{IN:o}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",r,!1).then(function(e){i.resolve(e.values)}),i.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?o.reject(t(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(t){return s.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,o&&(i.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return r.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),n.all(t)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(s.permissions.admin.administer).then(function(t){return t?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,o,s,i){return n.all(this.processFilters(e),t,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,o){return n.balanceChangeByAbsenceType(e,t,a,o)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/instances/work-pattern.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("WorkPatternInstance",["$log","ModelInstance",function(e,t){return e.debug("WorkPatternInstance"),t.extend({})}])}),define("leave-absences/shared/models/work-pattern.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/work-pattern.instance"],function(e,t){"use strict";t.factory("WorkPattern",["$log","Model","WorkPatternAPI","WorkPatternInstance",function(t,n,a,o){return t.debug("WorkPattern"),n.extend({assignWorkPattern:function(e,t,n,o,s,i){return a.assignWorkPattern(e,t,n,o,s,i)},default:function(){return a.get({is_default:!0}).then(function(t){return o.init(e.first(t),!0)})},unassignWorkPattern:function(e){return a.unassignWorkPattern(e)},workPatternsOf:function(e,t,n){return a.workPatternsOf(e,t,n).then(function(e){return e.map(function(e){return o.init(e,!0)})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function u(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?c():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return o.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):i.all()}function m(e){return"me"===e?o.leaveManagees(v.contactId):"unassigned"===e?o.leaveManagees(void 0,{unassigned:!0}):o.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){r.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,u()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:i.contactId}).leaveManagees().then(function(e){i.lookupContacts=e}).then(o)}}}function o(){return t.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:i.filters.userSettings.department?i.filters.userSettings.department.value:null,level_type:i.filters.userSettings.level_type?i.filters.userSettings.level_type.value:null,location:i.filters.userSettings.location?i.filters.userSettings.location.value:null,region:i.filters.userSettings.region?i.filters.userSettings.region.value:null,id:{IN:i.filters.userSettings.contact?[i.filters.userSettings.contact.id]:i.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var i;return{init:function(e){return i=e,i.showContactName=!0,i.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function o(a,o,s,i,r,c,u,l,d,m){function f(){for(var e=[],t=n(M.selectedPeriod.start_date).clone().startOf("month"),a=n(M.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(R(t)),t.add(1,"month");M.months=e}function p(){i.$new().$watch(function(){return M.selectedMonths},function(t,n){null===n||e.equals(t,n)||I()})}function h(e){M.injectMonths=!0,S("injected").then(function(){I(e)}).then(function(){M.loading.calendar=!1})}function v(){L=a("LeaveCalendar"+t.capitalize(k)+"Controller").init(M)}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function g(){return c.all().then(function(e){M.absencePeriods=t.sortBy(e,"start_date"),M.selectedPeriod=t.find(M.absencePeriods,function(e){return!!e.current})}).then(f).then(w)}function _(){return u.all().then(u.loadCalculationUnits)}function y(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return L.loadContacts().then(function(e){M.contacts=e})}function C(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){M.filters.optionValues.regions=e.hrjc_region,M.filters.optionValues.locations=e.hrjc_location,M.filters.optionValues.levelTypes=e.hrjc_level_type,M.filters.optionValues.departments=e.hrjc_department})}function D(){return l.all()}function T(){return o.all([_(),D(),y()]).then(function(e){M.supportData.absenceTypes=e[0],M.supportData.publicHolidays=e[1],M.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,M.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,M.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,M.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function P(){var e=o.resolve();return M.injectMonths&&(e=S("destroyed"),M.injectMonths=!1),e}function R(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function A(e){e=t.includes(["contacts","period"],e)?e:"period",o.resolve().then(function(){M.loading.calendar=!0}).then(P).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function I(e){var n=M.selectedMonths.length?M.months.filter(function(e){return t.includes(M.selectedMonths,e.index)}):M.months;i.$emit("LeaveCalendar::showMonths",n,!!e)}function w(){M.selectedMonths=[n().month()]}function O(){return M.roleOverride?o.resolve().then(function(){k=M.roleOverride}):o.all([m(r.permissions.admin.administer),m(r.permissions.ssp.manage)]).then(function(e){k=e[0]?"admin":e[1]?"manager":"staff"})}function S(e){return o(function(n){var a=0,o=i.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===M.months.length&&(o(),n())})})}s.debug("Component: leave-calendar");var L,k,M=this;M.absencePeriods=[],M.contacts=[],M.contactIdsToReduceTo=null,M.injectMonths=!1,M.months=[],M.selectedMonths=null,M.selectedPeriod=null,M.showContactName=!1,M.showFilters=!1,M.supportData={},M.loading={calendar:!0,page:!0},M.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},M.labelPeriod=b,M.refresh=A,function(){O().then(p).then(v).then(P).then(g).then(function(){return o.all([q(),T()])}).then(function(){return M.showFilters?C():t.noop}).then(function(){h()}).then(function(){M.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",o]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,o){"use strict";function s(){y.calculationUnit=i(y.supportData.calculationUnits,"value",b.calculation_unit)}function i(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function r(){var e,n;return n=t(y.contactData.leaveRequest.from_date).isSame(y.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+y.calculationUnit.name+"-on-"+e+"-tooltip"}function c(){b=i(y.supportData.absenceTypes,"id",y.contactData.leaveRequest.type_id),y.contactData.leaveRequest["type_id.title"]=b.title}function u(){"days"===y.calculationUnit.name&&(g=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.from_date_type),_=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.to_date_type),y.contactData.leaveRequest["from_date_type.label"]=g.label,y.contactData.leaveRequest["to_date_type.label"]=_.label)}function l(e,t,n,a,s){e.stopPropagation(),o.openModal(t,n,a,s)}function d(){y.dates.from=new Date(y.contactData.leaveRequest.from_date),y.dates.to=new Date(y.contactData.leaveRequest.to_date)}function m(){y.contactData.isAccruedTOIL?y.label="AT":"days"===y.calculationUnit.name?f():p()}function f(){y.label=y.contactData.isAM?"AM":y.contactData.isPM?"PM":""}function p(){var e=t(y.contactData.leaveRequest.from_date).isSame(y.date,"day"),n=t(y.contactData.leaveRequest.to_date).isSame(y.date,"day");y.label=e?t(y.contactData.leaveRequest.from_date).format("HH:mm"):n?t(y.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){y.tooltipTemplate=y.contactData.isAccruedTOIL?"accrued-toil-tooltip":r()}function v(){a.$watch("day.contactData.leaveRequest",function(){y.contactData&&y.contactData.leaveRequest&&(c(),s(),u(),m(),d(),h()) -})}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(e){_([e]),U(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return j[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){L(e),U(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=P(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){N.push(o.$on("LeaveCalendar::showMonths",$)),N.push(r.subscribe("LeaveRequest::new",u)),N.push(r.subscribe("LeaveRequest::edit",B)),N.push(r.subscribe("LeaveRequest::updatedByManager",B)),N.push(r.subscribe("LeaveRequest::delete",h)),N.push(r.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function D(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function T(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function P(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function R(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function A(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function I(){return[A(c.statusNames.approved),A(c.statusNames.adminApproved),A(c.statusNames.awaitingApproval),A(c.statusNames.moreInformationRequired)]}function w(){return H.month.loading=!0,a.all([S(),O()]).then(b).then(x).then(function(){F=!0}).then(function(){H.month.loading=!1})}function O(){return i.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:I()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function S(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){j=e.indexBy(t,"contact_id")})}function L(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function k(){o.$emit("LeaveCalendar::monthDestroyed"),N.map(function(e){e.remove?e.remove():e()})}function M(t,n,o){var s,i;return t.contactsData[n]=t.contactsData[n]||{},i=m(n),s=!0===o?a.resolve():a.all([i.isWeekend(p(t.date)),i.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:D(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?T(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function x(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return M(e,t.id)}))}))}function $(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!F)&&w())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=R(e);t&&(h(t),-1!==I().indexOf(e.status_id)&&u(e))}function U(e){return a.all(P(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var F=!1,N=[],j={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=k,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,i,r,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(i.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=D[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&r.publish("ManagerBadge:: Update Count"),r.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(D,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:D[e].label,isDirectAction:D[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,D={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return r.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,c.serverDateFormat).toDate()}function h(e){return t(e).format(c.serverDateFormat)}function v(e){var t;return i.resolve().then(function(){N(e),"from"===e&&F(),S("hours")&&(_(e),"from"!==e||te.uiOptions.multipleDays||_("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return i.reject("Please change date as it is not in any absence period")}).then(W).then(function(){if(t)return x()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(V(),!t)return E();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(P).finally(y)}function b(){return V(),E()}function g(){return te.uiOptions.toDate=null,N("to"),i.resolve().then(V).then(te.setDaysSelectionModeExtended).then(y).then(!te.uiOptions.multipleDays&&E)}function _(e){te.uiOptions.times[e].loading=!0}function y(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,S("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function C(){return te.request?te.request.request_type:te.leaveType||null}function D(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(j).catch(P)}function P(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function R(){return te.isMode("create")||te.forceRecalculateBalanceChange?E():T()}function A(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():i.resolve()}function I(){ee.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){Q()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){J(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",E))}function w(){te.isMode("edit")&&(te.isLeaveStatus(c.statusNames.approved)||te.isLeaveStatus(c.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function O(){o.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(K(e),V()))})}function S(e){return te.selectedAbsenceType.calculation_unit_name===e}function L(e){return te.request.request_type===e}function k(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function M(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function x(){return u.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function $(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function E(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(j).catch(P).finally(function(){te.loading.balanceChange=!1})):i.resolve()}function B(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function U(){return h(te.request.from_date)===h(te.request.to_date)}function F(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,N("to"))}function N(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),V(),z()}function j(e){te.balance.change=e,te.request.balance_change=e.amount,f(),B(),te.loading.balanceChange=!1}function W(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function H(){return!te.isMode("create")&&U()||te.isMode("create")&&(L("sickness")||S("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,i.resolve().then(te.setDaysSelectionModeExtended)}function G(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function Y(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function V(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(S("hours")||L("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function X(){e.forEach(ee,function(e){e()})}function Q(){var e,t=te.selectedAbsenceType.calculation_unit_name;return Y(),e=t!==te.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&H).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&V).then(y).then(E)}function J(e){return te.absenceTypes=e,Y(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,N("to")),G(),E()}function K(e){var t=D(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(D(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(D(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=c.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:$},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:r.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=b,te.daysSelectionModeChangeHandler=g,te.disableAndShowLoadingTimeInput=_,te.getMomentDateWithGivenTime=D,te.handleError=P,te.isCalculationUnit=S,te.isLeaveType=L,te.isNotWorkingDay=k,te.performBalanceChangeCalculation=E,te.setRequestDateTimesAndDateTypes=V,te.updateEndTimeInputMinTime=K,te.$onDestroy=X,function(){n("RequestModalDetails"+e.capitalize(C(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",te),I(),te.initChildController().then(function(){return i.all([x(),M()])}).then(!te.isMode("create")&&A).then(H).then(function(){if(!te.isMode("create"))return i.resolve().then(te.initTimesExtended).then(V)}).then(!te.isMode("create")&&W).then(w).then(G).then(R).then(O).then(!te.isMode("view")&&te.initWatchersExtended).catch(P).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l){function d(){return O.fileUploader&&O.fileUploader.queue.length>0}function m(){return O.getFilesAmount()0?A.map(function(e){return e.label}).join(", "):""}function q(){return O.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(A.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){w[e.label]=t})})).catch(function(){w=null})}function D(){return c.valuesOf("safe_file_extension").then(function(e){A=e})}function T(e){return!e.attachment_id||O.canManage}function P(){e.forEach(I,function(e){e()})}function R(e,t){O.fileUploader.queue&&O.fileUploader.queue.length>0?O.fileUploader.uploadAll({entityID:O.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var A=[],I=[],w={},O=Object.create(this);return O.filesLoaded=!1,O.fileUploader=null,O.today=Date.now(),O.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",O.userDateFormat=i.DATE_FORMAT,O.$onDestroy=P,O.canRemoveAttachment=T,O.canSubmit=d,O.canUploadMore=m,O.formatDateTime=f,O.getAuthorName=p,O.getFilesAmount=h,O.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",O),g(),a.all([D(),q()]).then(_).finally(function(){O.filesLoaded=!0})}(),O}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,o){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],s.openLeavePopup=a,function(){o=n.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,o,s,i,r,c,u,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var t=j[e.status];t?t(e.leaveRequest):W.refresh()}function b(t){t.dataIndex=e.indexBy(t.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return i.all().then(i.loadCalculationUnits).then(function(t){W.absenceTypes=t,W.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return A("approved",{status_id:N(m.statusNames.approved)})}function C(){return n.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[N(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[N(m.statusNames.awaitingApproval),N(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function D(){return r.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(t){var n=e.find(W.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function T(){return r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return M(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function P(){return n.all([r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),R({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:M(e[0]),expiredTOILS:x(e[1].list)})}).then(function(t){W.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function R(t){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function A(e,t){return R(t).then(function(t){W.sections[e].data=t.list})}function I(){return n.all(Object.values(W.sections).filter(function(e){return e.open}).map(L))}function w(){return A("other",{status_id:{in:[N(m.statusNames.rejected),N(m.statusNames.cancelled)]}})}function O(){return A("pending",{status_id:{in:[N(m.statusNames.awaitingApproval),N(m.statusNames.moreInformationRequired)]}})}function S(){return A("holidays",{public_holiday:!0})}function L(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function k(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){W.leaveRequestStatuses=e.indexBy(t,"value")})}function M(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(W.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function x(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function $(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(W.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],B(t,a))})}function B(e,t){var n=W.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function U(){W.loading.content=!0,n.all([D(),C()]).then(function(){W.loading.content=!1}).then(function(){return n.all([I(),h()])})}function F(e){var t=W.sections[e];t.open=!t.open,t.open&&!t.data.length&&L(t)}function N(t){return e.find(W.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var j={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:T},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:P},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w}},W.labelPeriod=g,W.refresh=U,W.toggleSection=F,function(){n.all([k(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return n.all([D(),C()])}).then(function(){W.loading.content=!1}),$()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report", -controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function u(){var e=i.request,t=!!e.from_date&&!!e.to_date,n=i.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return i.canCalculateChange()}function d(t,n){var a=i.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);i.uiOptions.multipleDays||("from"===t&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=i.convertDateToServerFormat(t),r.isPublicHoliday(t).then(function(n){return n?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,i.requestDayTypes).then(function(t){return t.length?t:i.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return R(n,e),e})):o.reject([])}function f(e,n){return e=t(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return o.resolve()}function v(){return C(i.uiOptions.fromDate,"from").then(function(){return C(i.uiOptions.toDate,"to")})}function b(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,t){i.isCalculationUnit("days")||+e==+t||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function g(e){var n=t(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),i.uiOptions.times[e].time=n}function _(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],t=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(T)).then(function(){["from","to"].forEach(function(e){g(e),I(e),t[e].amount=Math.min(i.request[e+"_date_amount"],t[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function y(){["from","to"].forEach(function(e){b(e),q(e)})}function q(e){s.$watch(function(){return i.uiOptions.times[e].time},function(t,n){i.isCalculationUnit("days")||t===n||(i.setRequestDateTimesAndDateTypes(),t&&I(e,!0))})}function C(e,t){return m(e,t).then(function(){i.loading[t+"DayTypes"]=!1})}function D(e){return C(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return T(e).then(function(){I(e,!0)})})}function T(e){var t=i.uiOptions[e+"Date"],n=!i.uiOptions.multipleDays;return t?i.request.getWorkDayForDate(i.convertDateToServerFormat(t)).then(function(t){S[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return S[e]={},i.handleError(t)}).finally(function(){n&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(t){var n=i.uiOptions.times[t];i["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function R(t,n){var a="request"+e.startCase(t)+"DayTypes";i[a]=n,i.isMode("create")&&(i.request[t+"_date_type"]=i[a][0].value)}function A(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),T("from").then(function(){I("from",!0)})):o.resolve()}function I(e,t){var n=i.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,c=S[a].number_of_hours?p(s,r).toString():"0";o.maxAmount=c,t&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function O(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?T("from").then(function(){I("from",!0)}):o.resolve()}var S={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=c,i.canCalculateChange=u,i.canSubmit=l,i.initChildController=h,i.initDayTypesExtended=v,i.initTimesExtended=_,i.initWatchersExtended=y,i.onAbsenceTypeUpdateExtended=O,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=A}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function i(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function r(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=i,s.initChildController=r,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=t.duration(t(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,t=!c.uiOptions.multipleDays&&!!c.request.from_date,n=t||e,a=B.from_date!==c.request.from_date||B.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&n&&F.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,t=c.request;return b({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function b(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&F.hasExpirationFromAdminSettings,t=F.hasPreviousExpirationDate,n=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=n&&(a||e||t)}function _(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function y(){return F.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){F.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",y().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function D(){o.$watch(function(){return c.request.toil_to_accrue},function(e,t){+e!=+t&&c.performBalanceChangeCalculation()})}function T(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,t){c.isCalculationUnit("hours")&&e!==t&&(c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function P(){var e=c.uiOptions.times;e.from.time=t(c.request.from_date).format("HH:mm"),e.to.time=t(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,t){e!==t&&(c.setRequestDateTimesAndDateTypes(),$(),l(),S())})})}function A(){c.isMode("view")||(D(),T(),R())}function I(t){return i.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){c.toilAmounts=e.sortBy(t,"value")})}function w(){return l(),S(),$()}function O(){return k(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),U?U=!1:S(),$()}function S(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function L(){B=e.cloneDeep(c.request.attributes())}function k(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function M(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){I(!1)})}function x(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function $(){return f()?d().catch(a.resolve):a.resolve()}function E(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var B,U=!c.isMode("create"),F={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=P,c.initWatchersExtended=A,c.onDateChangeExtended=w,c.openToilInDaysAccrualOptionsEditor=M,c.setDaysSelectionModeExtended=O,c.updateExpiryDate=E,function(){L(),k(),x(),!c.isMode("create")&&_()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,D){function T(e){"days"===xe.selectedAbsenceType.calculation_unit_name?delete xe.request[e+"_date_amount"]:delete xe.request[e+"_date_type"]}function P(){["from","to"].forEach(T)}function R(){var e=xe.requestStatuses[y.statusNames.awaitingApproval].value;we.status_id===e&&e!==xe.request.status_id&&d.publish("ManagerBadge:: Update Count")}function A(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!xe.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function O(){var e=A();return xe.isMode("edit")&&(e=e&&(G()||I())),xe.canManage&&xe.requestStatuses&&(e=e&&!!xe.getStatusFromValue(xe.newStatusOnSave)),(e=e&&!!xe.period.id)&&!xe.isMode("view")}function S(){xe.isSelfRecord?xe.request.status_id=xe.requestStatuses[y.statusNames.awaitingApproval].value:xe.canManage&&(xe.request.status_id=xe.newStatusOnSave||xe.request.status_id)}function L(){if(xe.isMode("edit")&&!xe.isRole("staff")&&"toil"!==N())return xe.request.calculateBalanceChange(xe.selectedAbsenceType.calculation_unit_name).then(function(e){if(+xe.balance.change.amount!=+e.amount)return D.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function k(){xe.errors=[]}function M(){return xe.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function x(){ee()&&!xe.isRole("staff")&&(xe.request.change_balance=!0)}function $(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return xe.request.delete().then(function(){xe.dismissModal(),d.publish("LeaveRequest::delete",xe.request)})}})}function E(){r.dismiss({$value:"cancel"})}function B(){var e=N();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return F(xe.getStatusFromValue(xe.request.status_id).name)}function F(e){return n.map(Ae[e],function(e){return xe.requestStatuses[e]})}function N(){return xe.request?xe.request.request_type:xe.leaveType||null}function j(){return!xe.request||e.equals({},xe.requestStatuses)?[]:xe.request.status_id?U():F("none")}function W(e){return n.find(xe.requestStatuses,function(t){return t.value===e})}function H(e){xe.errors=n.isArray(e)?e:[e],xe.loading.absenceTypes=!1,xe.submitting=!1}function G(){return!e.equals(we,xe.request.attributes())||xe.canManage&&xe.newStatusOnSave}function Y(){return xe.postContactSelection=!0,xe.staffMemberSelectionComplete=!1,xe.request.contact_id?o.resolve().then(re).then(ce).then(he).then(be).then(Z).then(z).then(xe.isMode("edit")?ge:n.noop).then(function(){xe.postContactSelection=!1,xe.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Le)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Ae.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Ae.awaiting_approval=e,Ae.more_information_required=e,Ae.rejected=e,Ae.approved=e,Ae.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return xe.canManage?f.find(xe.request.contact_id).then(function(e){xe.contactName=e.display_name}):o.resolve()}function X(){Oe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",xe.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Ie++})),i.$on("$destroy",De),i.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function Q(){var e,t;xe.request=xe.leaveRequest||null,e=N(),t=xe.initRequestAttributes(),"leave"===e?xe.request=_.init(t):"sickness"===e?xe.request=q.init(t):"toil"===e&&(xe.request=C.init(t))}function J(){var e={};return xe.request?e=xe.request.attributes():xe.canManage||(e={contact_id:Se}),e}function K(){if(ke="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(ke="admin")}).then(function(){return"staff"===ke&&c(y.permissions.ssp.manage).then(function(e){e&&(ke="manager")})}).finally(function(){xe.canManage=xe.isRole("manager")||xe.isRole("admin")})}function Z(){(xe.isRole("admin")||xe.isMode("create")&&xe.isRole("manager"))&&(xe.newStatusOnSave=xe.requestStatuses[y.statusNames.approved].value)}function ee(){return!xe.request.status_id||!n.includes(["cancelled","rejected"],W(xe.request.status_id).name)}function te(e){var t=xe.getStatusFromValue(xe.request.status_id);return!!t&&t.name===e}function ne(e){return xe.request&&xe.request.request_type===e}function ae(e){return xe.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return ke===e}function ie(){return h.all().then(function(e){xe.absencePeriods=e})}function re(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Re={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return xe.loading.entitlements=!0,b.all({contact_id:xe.request.contact_id,period_id:xe.period.id,type_id:{IN:Re.ids}},!0).finally(function(){xe.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Se=e.contactId})}function le(){return xe.selectedContactId?f.find(xe.selectedContactId).then(function(e){xe.managedContacts=[e]}):xe.isRole("admin")?f.all().then(function(e){xe.managedContacts=n.remove(e.list,function(e){return e.id!==Se})}):f.find(Se).then(function(e){return e.leaveManagees()}).then(function(e){xe.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){xe.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){R(),d.publish(e,xe.request),xe.errors=[],xe.dismissModal()}function pe(){["from","to"].forEach(function(e){xe.request[e+"_date"]=we[e+"_date"]})}function he(e){if(xe.absenceTypes=me(Re.types,e),!xe.absenceTypes.length)return o.reject(Le)}function ve(){xe.period=n.find(xe.absencePeriods,function(e){return xe.isMode("create")?e.current:oe(xe.request,e)})}function be(){xe.isMode("create")?(xe.selectedAbsenceType=xe.absenceTypes[0],xe.request.type_id=xe.selectedAbsenceType.id):xe.selectedAbsenceType=n.find(xe.absenceTypes,function(e){return e.id===xe.request.type_id})}function ge(){we=e.copy(xe.request.attributes())}function _e(){var e;xe.request.id?(e=[xe.requestStatuses[y.statusNames.approved].value,xe.requestStatuses[y.statusNames.adminApproved].value,xe.requestStatuses[y.statusNames.rejected].value,xe.requestStatuses[y.statusNames.cancelled].value],xe.mode="edit",xe.isRole("staff")&&e.indexOf(xe.request.status_id)>-1&&(xe.mode="view")):xe.mode="create"}function ye(){var e=xe.request.status_id;if(!xe.isMode("view")&&!xe.submitting)return xe.submitting=!0,S(),P(),xe.request.isValid().then(ee()&&L).then(x).then(!xe.request.change_balance&&pe).then(qe).then(function(){return xe.isMode("edit")?Pe():M()}).catch(function(t){xe.request.status_id=e,t&&H(t)}).finally(function(){xe.submitting=!1})}function qe(){return o.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===Ie&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return Ie>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function De(){Oe.forEach(function(e){e()})}function Te(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Pe(){return xe.request.update().then(Ce).then(function(){xe.isRole("manager")?fe("LeaveRequest::updatedByManager"):(xe.isRole("staff")||xe.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Re,Ae={},Ie=0,we={},Oe=[],Se="",Le="No entitlement",ke="",Me=[],xe=n.assign(this,m);xe.absencePeriods=[],xe.absenceTypes=[],xe.canManage=!1,xe.contactName=null,xe.errors=[],xe.loading={absenceTypes:!0,entitlements:!0},xe.managedContacts=[],xe.mode="",xe.newStatusOnSave=null,xe.period={},xe.postContactSelection=!1,xe.requestStatuses={},xe.selectedAbsenceType={},xe.staffMemberSelectionComplete=!1,xe.submitting=!1,xe.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},xe.canChangeAbsenceType=w,xe.canSubmit=O,xe.closeAlert=k,xe.deleteLeaveRequest=$,xe.dismissModal=E,xe.getStatuses=j,xe.getStatusFromValue=W,xe.initAfterContactSelection=Y,xe.initRequestAttributes=J,xe.isLeaveStatus=te,xe.isLeaveType=ne,xe.isMode=ae,xe.isRole=se,xe.submit=ye,xe.updateAbsenceType=Te,function(){xe.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),ie(),de()]).then(Q).then(_e).then(ve).then(function(){return xe.canManage&&!xe.isMode("edit")&&le()}).then(function(){if(xe.selectedContactId&&(xe.request.contact_id=xe.selectedContactId),xe.request.contact_id)return xe.initAfterContactSelection()}).catch(H).finally(function(){xe.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,i,r,c){function u(e){return r.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,i,r){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:i,forceRecalculateBalanceChange:r}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,i){function r(e){l.errorMessage=e}function c(){return i.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrjc_revision_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,i.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(r).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrjc_revision_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"}) -;return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(),g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){r.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){i.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i){function r(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,i){n=o.entitlements.slice(0,i),a=e.entitlements.slice(i+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,i;return s=e.indexBy(n,"entitlement_id.type_id"),i=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:i}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t];e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,i){o.comment&&(t=s.concat(o).concat(i),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(r).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,i,r,c,u,l,d){function m(){D.absencePeriods=t.chain(D.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){D.absenceTypes=t.filter(D.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:D.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:D.contactId,returnUrl:n})}function h(){return c.all().then(function(e){D.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:D.contactId}).then(function(e){q=e})}function g(e){i.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=D.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){D.absencePeriods=t.map(D.absencePeriods,function(e){var n=t.map(D.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

    Last updated:
    By: "+e.author_name+"
    Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
    ";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],D=this;D.absencePeriods=[],D.loading={absencePeriods:!0},D.getEditEntitlementsPageURL=p,D.openAnnualEntitlementChangeLog=g,D.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){D.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i,r){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return i.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){r.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); +})}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(e){_([e]),U(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return j[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){L(e),U(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=P(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){F.push(o.$on("LeaveCalendar::showMonths",$)),F.push(r.subscribe("LeaveRequest::new",u)),F.push(r.subscribe("LeaveRequest::edit",B)),F.push(r.subscribe("LeaveRequest::updatedByManager",B)),F.push(r.subscribe("LeaveRequest::delete",h)),F.push(r.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function D(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function T(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function P(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function R(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function A(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function I(){return[A(c.statusNames.approved),A(c.statusNames.adminApproved),A(c.statusNames.awaitingApproval),A(c.statusNames.moreInformationRequired)]}function w(){return H.month.loading=!0,a.all([S(),O()]).then(b).then(x).then(function(){N=!0}).then(function(){H.month.loading=!1})}function O(){return i.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:I()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function S(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){j=e.indexBy(t,"contact_id")})}function L(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function k(){o.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function M(t,n,o){var s,i;return t.contactsData[n]=t.contactsData[n]||{},i=m(n),s=!0===o?a.resolve():a.all([i.isWeekend(p(t.date)),i.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:D(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?T(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function x(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return M(e,t.id)}))}))}function $(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!N)&&w())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=R(e);t&&(h(t),-1!==I().indexOf(e.status_id)&&u(e))}function U(e){return a.all(P(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],j={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=k,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,i,r,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(i.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=D[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&r.publish("ManagerBadge:: Update Count"),r.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(D,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:D[e].label,isDirectAction:D[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,D={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return r.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,c.serverDateFormat).toDate()}function h(e){return t(e).format(c.serverDateFormat)}function v(e){var t;return i.resolve().then(function(){F(e),"from"===e&&N(),S("hours")&&(_(e),"from"!==e||te.uiOptions.multipleDays||_("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return i.reject("Please change date as it is not in any absence period")}).then(W).then(function(){if(t)return x()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(V(),!t)return E();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(P).finally(y)}function b(){return V(),E()}function g(){return te.uiOptions.toDate=null,F("to"),i.resolve().then(V).then(te.setDaysSelectionModeExtended).then(y).then(!te.uiOptions.multipleDays&&E)}function _(e){te.uiOptions.times[e].loading=!0}function y(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,S("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function C(){return te.request?te.request.request_type:te.leaveType||null}function D(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(j).catch(P)}function P(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function R(){return te.isMode("create")||te.forceRecalculateBalanceChange?E():T()}function A(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():i.resolve()}function I(){ee.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){Q()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){J(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",E))}function w(){te.isMode("edit")&&(te.isLeaveStatus(c.statusNames.approved)||te.isLeaveStatus(c.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function O(){o.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(K(e),V()))})}function S(e){return te.selectedAbsenceType.calculation_unit_name===e}function L(e){return te.request.request_type===e}function k(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function M(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function x(){return u.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function $(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function E(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(j).catch(P).finally(function(){te.loading.balanceChange=!1})):i.resolve()}function B(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function U(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),V(),z()}function j(e){te.balance.change=e,te.request.balance_change=e.amount,f(),B(),te.loading.balanceChange=!1}function W(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function H(){return!te.isMode("create")&&U()||te.isMode("create")&&(L("sickness")||S("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,i.resolve().then(te.setDaysSelectionModeExtended)}function G(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function Y(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function V(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(S("hours")||L("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function X(){e.forEach(ee,function(e){e()})}function Q(){var e,t=te.selectedAbsenceType.calculation_unit_name;return Y(),e=t!==te.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&H).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&V).then(y).then(E)}function J(e){return te.absenceTypes=e,Y(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),G(),E()}function K(e){var t=D(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(D(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(D(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=c.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:$},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:r.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=b,te.daysSelectionModeChangeHandler=g,te.disableAndShowLoadingTimeInput=_,te.getMomentDateWithGivenTime=D,te.handleError=P,te.isCalculationUnit=S,te.isLeaveType=L,te.isNotWorkingDay=k,te.performBalanceChangeCalculation=E,te.setRequestDateTimesAndDateTypes=V,te.updateEndTimeInputMinTime=K,te.$onDestroy=X,function(){n("RequestModalDetails"+e.capitalize(C(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",te),I(),te.initChildController().then(function(){return i.all([x(),M()])}).then(!te.isMode("create")&&A).then(H).then(function(){if(!te.isMode("create"))return i.resolve().then(te.initTimesExtended).then(V)}).then(!te.isMode("create")&&W).then(w).then(G).then(R).then(O).then(!te.isMode("view")&&te.initWatchersExtended).catch(P).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l){function d(){return O.fileUploader&&O.fileUploader.queue.length>0}function m(){return O.getFilesAmount()0?A.map(function(e){return e.label}).join(", "):""}function q(){return O.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(A.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){w[e.label]=t})})).catch(function(){w=null})}function D(){return c.valuesOf("safe_file_extension").then(function(e){A=e})}function T(e){return!e.attachment_id||O.canManage}function P(){e.forEach(I,function(e){e()})}function R(e,t){O.fileUploader.queue&&O.fileUploader.queue.length>0?O.fileUploader.uploadAll({entityID:O.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var A=[],I=[],w={},O=Object.create(this);return O.filesLoaded=!1,O.fileUploader=null,O.today=Date.now(),O.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",O.userDateFormat=i.DATE_FORMAT,O.$onDestroy=P,O.canRemoveAttachment=T,O.canSubmit=d,O.canUploadMore=m,O.formatDateTime=f,O.getAuthorName=p,O.getFilesAmount=h,O.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",O),g(),a.all([D(),q()]).then(_).finally(function(){O.filesLoaded=!0})}(),O}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,o){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],s.openLeavePopup=a,function(){o=n.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,o,s,i,r,c,u,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var t=j[e.status];t?t(e.leaveRequest):W.refresh()}function b(t){t.dataIndex=e.indexBy(t.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return i.all().then(i.loadCalculationUnits).then(function(t){W.absenceTypes=t,W.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return A("approved",{status_id:F(m.statusNames.approved)})}function C(){return n.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function D(){return r.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(t){var n=e.find(W.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function T(){return r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return M(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function P(){return n.all([r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),R({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:M(e[0]),expiredTOILS:x(e[1].list)})}).then(function(t){W.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function R(t){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function A(e,t){return R(t).then(function(t){W.sections[e].data=t.list})}function I(){return n.all(Object.values(W.sections).filter(function(e){return e.open}).map(L))}function w(){return A("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function O(){return A("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function S(){return A("holidays",{public_holiday:!0})}function L(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function k(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){W.leaveRequestStatuses=e.indexBy(t,"value")})}function M(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(W.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function x(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function $(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(W.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],B(t,a))})}function B(e,t){var n=W.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function U(){W.loading.content=!0,n.all([D(),C()]).then(function(){W.loading.content=!1}).then(function(){return n.all([I(),h()])})}function N(e){var t=W.sections[e];t.open=!t.open,t.open&&!t.data.length&&L(t)}function F(t){return e.find(W.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var j={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:T},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:P},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w}},W.labelPeriod=g,W.refresh=U,W.toggleSection=N,function(){n.all([k(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return n.all([D(),C()])}).then(function(){W.loading.content=!1}),$()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report", +controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function u(){var e=i.request,t=!!e.from_date&&!!e.to_date,n=i.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return i.canCalculateChange()}function d(t,n){var a=i.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);i.uiOptions.multipleDays||("from"===t&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=i.convertDateToServerFormat(t),r.isPublicHoliday(t).then(function(n){return n?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,i.requestDayTypes).then(function(t){return t.length?t:i.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return R(n,e),e})):o.reject([])}function f(e,n){return e=t(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return o.resolve()}function v(){return C(i.uiOptions.fromDate,"from").then(function(){return C(i.uiOptions.toDate,"to")})}function b(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,t){i.isCalculationUnit("days")||+e==+t||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function g(e){var n=t(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),i.uiOptions.times[e].time=n}function _(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],t=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(T)).then(function(){["from","to"].forEach(function(e){g(e),I(e),t[e].amount=Math.min(i.request[e+"_date_amount"],t[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function y(){["from","to"].forEach(function(e){b(e),q(e)})}function q(e){s.$watch(function(){return i.uiOptions.times[e].time},function(t,n){i.isCalculationUnit("days")||t===n||(i.setRequestDateTimesAndDateTypes(),t&&I(e,!0))})}function C(e,t){return m(e,t).then(function(){i.loading[t+"DayTypes"]=!1})}function D(e){return C(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return T(e).then(function(){I(e,!0)})})}function T(e){var t=i.uiOptions[e+"Date"],n=!i.uiOptions.multipleDays;return t?i.request.getWorkDayForDate(i.convertDateToServerFormat(t)).then(function(t){S[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return S[e]={},i.handleError(t)}).finally(function(){n&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(t){var n=i.uiOptions.times[t];i["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function R(t,n){var a="request"+e.startCase(t)+"DayTypes";i[a]=n,i.isMode("create")&&(i.request[t+"_date_type"]=i[a][0].value)}function A(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),T("from").then(function(){I("from",!0)})):o.resolve()}function I(e,t){var n=i.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,c=S[a].number_of_hours?p(s,r).toString():"0";o.maxAmount=c,t&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function O(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?T("from").then(function(){I("from",!0)}):o.resolve()}var S={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=c,i.canCalculateChange=u,i.canSubmit=l,i.initChildController=h,i.initDayTypesExtended=v,i.initTimesExtended=_,i.initWatchersExtended=y,i.onAbsenceTypeUpdateExtended=O,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=A}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function i(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function r(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=i,s.initChildController=r,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=t.duration(t(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,t=!c.uiOptions.multipleDays&&!!c.request.from_date,n=t||e,a=U.from_date!==c.request.from_date||U.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&n&&F.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,t=c.request;return b({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function b(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&F.hasExpirationFromAdminSettings,t=F.hasPreviousExpirationDate,n=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=n&&(a||e||t)}function _(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function y(){return F.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){F.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",y().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function D(){o.$watch(function(){return c.request.toil_to_accrue},function(e,t){+e!=+t&&c.performBalanceChangeCalculation()})}function T(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,t){c.isCalculationUnit("hours")&&e!==t&&(c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function P(){var e=c.uiOptions.times;e.from.time=t(c.request.from_date).format("HH:mm"),e.to.time=t(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,t){e!==t&&(c.setRequestDateTimesAndDateTypes(),E(),l(),L())})})}function A(){c.isMode("view")||(D(),T(),R())}function I(t){return i.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){c.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function w(){return l(),L(),E()}function O(){return M(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),N?N=!1:L(),E()}function S(e){c.uiOptions.times[e].time=""}function L(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function k(){U=e.cloneDeep(c.request.attributes())}function M(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function x(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){I(!1)})}function $(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function E(){return f()?d().catch(a.resolve):a.resolve()}function B(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var U,N=!c.isMode("create"),F={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=P,c.initWatchersExtended=A,c.onDateChangeExtended=w,c.openToilInDaysAccrualOptionsEditor=x,c.resetUIInputsExtended=S,c.setDaysSelectionModeExtended=O,c.updateExpiryDate=B,function(){k(),M(),$(),!c.isMode("create")&&_()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,D){function T(e){"days"===xe.selectedAbsenceType.calculation_unit_name?delete xe.request[e+"_date_amount"]:delete xe.request[e+"_date_type"]}function P(){["from","to"].forEach(T)}function R(){var e=xe.requestStatuses[y.statusNames.awaitingApproval].value;we.status_id===e&&e!==xe.request.status_id&&d.publish("ManagerBadge:: Update Count")}function A(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!xe.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function O(){var e=A();return xe.isMode("edit")&&(e=e&&(G()||I())),xe.canManage&&xe.requestStatuses&&(e=e&&!!xe.getStatusFromValue(xe.newStatusOnSave)),(e=e&&!!xe.period.id)&&!xe.isMode("view")}function S(){xe.isSelfRecord?xe.request.status_id=xe.requestStatuses[y.statusNames.awaitingApproval].value:xe.canManage&&(xe.request.status_id=xe.newStatusOnSave||xe.request.status_id)}function L(){if(xe.isMode("edit")&&!xe.isRole("staff")&&"toil"!==F())return xe.request.calculateBalanceChange(xe.selectedAbsenceType.calculation_unit_name).then(function(e){if(+xe.balance.change.amount!=+e.amount)return D.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function k(){xe.errors=[]}function M(){return xe.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function x(){ee()&&!xe.isRole("staff")&&(xe.request.change_balance=!0)}function $(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return xe.request.delete().then(function(){xe.dismissModal(),d.publish("LeaveRequest::delete",xe.request)})}})}function E(){r.dismiss({$value:"cancel"})}function B(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return N(xe.getStatusFromValue(xe.request.status_id).name)}function N(e){return n.map(Ae[e],function(e){return xe.requestStatuses[e]})}function F(){return xe.request?xe.request.request_type:xe.leaveType||null}function j(){return!xe.request||e.equals({},xe.requestStatuses)?[]:xe.request.status_id?U():N("none")}function W(e){return n.find(xe.requestStatuses,function(t){return t.value===e})}function H(e){xe.errors=n.isArray(e)?e:[e],xe.loading.absenceTypes=!1,xe.submitting=!1}function G(){return!e.equals(we,xe.request.attributes())||xe.canManage&&xe.newStatusOnSave}function Y(){return xe.postContactSelection=!0,xe.staffMemberSelectionComplete=!1,xe.request.contact_id?o.resolve().then(re).then(ce).then(he).then(be).then(Z).then(z).then(xe.isMode("edit")?ge:n.noop).then(function(){xe.postContactSelection=!1,xe.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Le)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Ae.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Ae.awaiting_approval=e,Ae.more_information_required=e,Ae.rejected=e,Ae.approved=e,Ae.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return xe.canManage?f.find(xe.request.contact_id).then(function(e){xe.contactName=e.display_name}):o.resolve()}function X(){Oe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",xe.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Ie++})),i.$on("$destroy",De),i.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function Q(){var e,t;xe.request=xe.leaveRequest||null,e=F(),t=xe.initRequestAttributes(),"leave"===e?xe.request=_.init(t):"sickness"===e?xe.request=q.init(t):"toil"===e&&(xe.request=C.init(t))}function J(){var e={};return xe.request?e=xe.request.attributes():xe.canManage||(e={contact_id:Se}),e}function K(){if(ke="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(ke="admin")}).then(function(){return"staff"===ke&&c(y.permissions.ssp.manage).then(function(e){e&&(ke="manager")})}).finally(function(){xe.canManage=xe.isRole("manager")||xe.isRole("admin")})}function Z(){(xe.isRole("admin")||xe.isMode("create")&&xe.isRole("manager"))&&(xe.newStatusOnSave=xe.requestStatuses[y.statusNames.approved].value)}function ee(){return!xe.request.status_id||!n.includes(["cancelled","rejected"],W(xe.request.status_id).name)}function te(e){var t=xe.getStatusFromValue(xe.request.status_id);return!!t&&t.name===e}function ne(e){return xe.request&&xe.request.request_type===e}function ae(e){return xe.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return ke===e}function ie(){return h.all().then(function(e){xe.absencePeriods=e})}function re(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Re={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return xe.loading.entitlements=!0,b.all({contact_id:xe.request.contact_id,period_id:xe.period.id,type_id:{IN:Re.ids}},!0).finally(function(){xe.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Se=e.contactId})}function le(){return xe.selectedContactId?f.find(xe.selectedContactId).then(function(e){xe.managedContacts=[e]}):xe.isRole("admin")?f.all().then(function(e){xe.managedContacts=n.remove(e.list,function(e){return e.id!==Se})}):f.find(Se).then(function(e){return e.leaveManagees()}).then(function(e){xe.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){xe.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){R(),d.publish(e,xe.request),xe.errors=[],xe.dismissModal()}function pe(){["from","to"].forEach(function(e){xe.request[e+"_date"]=we[e+"_date"]})}function he(e){if(xe.absenceTypes=me(Re.types,e),!xe.absenceTypes.length)return o.reject(Le)}function ve(){xe.period=n.find(xe.absencePeriods,function(e){return xe.isMode("create")?e.current:oe(xe.request,e)})}function be(){xe.isMode("create")?(xe.selectedAbsenceType=xe.absenceTypes[0],xe.request.type_id=xe.selectedAbsenceType.id):xe.selectedAbsenceType=n.find(xe.absenceTypes,function(e){return e.id===xe.request.type_id})}function ge(){we=e.copy(xe.request.attributes())}function _e(){var e;xe.request.id?(e=[xe.requestStatuses[y.statusNames.approved].value,xe.requestStatuses[y.statusNames.adminApproved].value,xe.requestStatuses[y.statusNames.rejected].value,xe.requestStatuses[y.statusNames.cancelled].value],xe.mode="edit",xe.isRole("staff")&&e.indexOf(xe.request.status_id)>-1&&(xe.mode="view")):xe.mode="create"}function ye(){var e=xe.request.status_id;if(!xe.isMode("view")&&!xe.submitting)return xe.submitting=!0,S(),P(),xe.request.isValid().then(ee()&&L).then(x).then(!xe.request.change_balance&&pe).then(qe).then(function(){return xe.isMode("edit")?Pe():M()}).catch(function(t){xe.request.status_id=e,t&&H(t)}).finally(function(){xe.submitting=!1})}function qe(){return o.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===Ie&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return Ie>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function De(){Oe.forEach(function(e){e()})}function Te(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Pe(){return xe.request.update().then(Ce).then(function(){xe.isRole("manager")?fe("LeaveRequest::updatedByManager"):(xe.isRole("staff")||xe.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Re,Ae={},Ie=0,we={},Oe=[],Se="",Le="No entitlement",ke="",Me=[],xe=n.assign(this,m);xe.absencePeriods=[],xe.absenceTypes=[],xe.canManage=!1,xe.contactName=null,xe.errors=[],xe.loading={absenceTypes:!0,entitlements:!0},xe.managedContacts=[],xe.mode="",xe.newStatusOnSave=null,xe.period={},xe.postContactSelection=!1,xe.requestStatuses={},xe.selectedAbsenceType={},xe.staffMemberSelectionComplete=!1,xe.submitting=!1,xe.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},xe.canChangeAbsenceType=w,xe.canSubmit=O,xe.closeAlert=k,xe.deleteLeaveRequest=$,xe.dismissModal=E,xe.getStatuses=j,xe.getStatusFromValue=W,xe.initAfterContactSelection=Y,xe.initRequestAttributes=J,xe.isLeaveStatus=te,xe.isLeaveType=ne,xe.isMode=ae,xe.isRole=se,xe.submit=ye,xe.updateAbsenceType=Te,function(){xe.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),ie(),de()]).then(Q).then(_e).then(ve).then(function(){return xe.canManage&&!xe.isMode("edit")&&le()}).then(function(){if(xe.selectedContactId&&(xe.request.contact_id=xe.selectedContactId),xe.request.contact_id)return xe.initAfterContactSelection()}).catch(H).finally(function(){xe.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,i,r,c){function u(e){return r.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,i,r){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:i,forceRecalculateBalanceChange:r}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,i){function r(e){l.errorMessage=e}function c(){return i.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrjc_revision_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,i.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(r).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrjc_revision_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){ +var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(),g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){r.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){i.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i){function r(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,i){n=o.entitlements.slice(0,i),a=e.entitlements.slice(i+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,i;return s=e.indexBy(n,"entitlement_id.type_id"),i=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:i}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t];e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,i){o.comment&&(t=s.concat(o).concat(i),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(r).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,i,r,c,u,l,d){function m(){D.absencePeriods=t.chain(D.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){D.absenceTypes=t.filter(D.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:D.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:D.contactId,returnUrl:n})}function h(){return c.all().then(function(e){D.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:D.contactId}).then(function(e){q=e})}function g(e){i.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=D.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){D.absencePeriods=t.map(D.absencePeriods,function(e){var n=t.map(D.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

    Last updated:
    By: "+e.author_name+"
    Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
    ";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],D=this;D.absencePeriods=[],D.loading={absencePeriods:!0},D.getEditEntitlementsPageURL=p,D.openAnnualEntitlementChangeLog=g,D.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){D.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i,r){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return i.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){r.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js index 2e7963f07f9..9566e9617f1 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js @@ -6,9 +6,9 @@ */ -!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),w.current)}).then(null,function(a){return a===D?S:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:S(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function M(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function L(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;aWhen All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){E.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){E.selectedMonths=[n().month()]}function T(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=D,function(){T().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",L)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([O(),T()]).then(g).then(M).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function M(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function L(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}), -define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function S(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function T(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function L(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:L},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),E()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(S).then(V).then(P).then(T).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||T.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=w,T.canRemoveAttachment=A,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=h,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:E(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:L(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function E(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function M(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function L(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=M(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=h,U.getAbsenceTypeByID=v,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=x,U.refresh=k,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),O(),P(),S(),R(),I()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),S(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(S)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function S(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function T(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=T,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=j.from_date!==u.request.from_date||j.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&N.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&N.hasExpirationFromAdminSettings,t=N.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return N.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){N.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),L(),l(),O())})})}function D(){u.isMode("view")||(C(), -A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function S(){return l(),O(),L()}function T(){return x(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),B?B=!1:O(),L()}function O(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function I(){j=e.cloneDeep(u.request.attributes())}function x(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function E(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){R(!1)})}function M(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function L(){return m()?d().catch(a.resolve):a.resolve()}function k(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var j,B=!u.isMode("create"),N={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=S,u.openToilInDaysAccrualOptionsEditor=E,u.setDaysSelectionModeExtended=T,u.updateExpiryDate=k,function(){I(),x(),M(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,r,o){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(o.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==F())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function E(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function L(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function F(){return Me.request?Me.request.request_type:Me.leaveType||null}function U(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Se,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=F(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Me.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Se[e+"_date"]})}function he(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function ve(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Se=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():E()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Ee=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=S,Me.canSubmit=T,Me.closeAlert=x,Me.deleteLeaveRequest=L,Me.dismissModal=k,Me.getStatuses=U,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(t){return t.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug, -pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM),define("leave-absences/admin-dashboard/modules/config",["common/angular","leave-absences/admin-dashboard/modules/settings"],function(e){return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(e,t,n,a,r,o){var s={format:["DateFormat",function(e){return e.getDateFormat()}]};r.debugEnabled(o.debug),t.defaults.stripTrailingSlashes=!1,a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:s}).state("calendar",{url:"/calendar",template:'',resolve:s}).state("leave-balances",{url:"/leave-balances",template:"",resolve:s})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function t(e,t){e.debug("Component: admin-dashboard-container"),t.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",t]})}),define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/admin-dashboard":n+"/admin-dashboard"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); +!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return U(e)&&e.then&&e.$$promises}if(!U(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!U(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},U(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||F(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!U(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=U(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=F(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:U(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in T)B(T[o])&&(t[o]=T[o](t,T.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),w.current)}).then(null,function(a){return a===D?T:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function T(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:T(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function M(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,T(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return U(n)?e+G(n):(n=t.$eval(n),U(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function L(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,U=t.isObject,F=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;aWhen All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){E.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(m).then(T)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function T(){E.selectedMonths=[n().month()]}function S(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=D,function(){S().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return F[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){U.push(r.$on("LeaveCalendar::showMonths",L)),U.push(i.subscribe("LeaveRequest::new",c)),U.push(i.subscribe("LeaveRequest::edit",j)),U.push(i.subscribe("LeaveRequest::updatedByManager",j)),U.push(i.subscribe("LeaveRequest::delete",h)),U.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function T(){return W.month.loading=!0,a.all([O(),S()]).then(g).then(M).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){F=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),U.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function M(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function L(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&T())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,U=[],F={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}), +define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){U(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,U("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(F).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function T(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function L(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(F).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,U("to"))}function U(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function F(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,U("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:L},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),E()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(T).then(V).then(P).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function f(){return S.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){T[e.label]=t})})).catch(function(){T=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||S.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],T={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=w,S.canRemoveAttachment=A,S.canSubmit=d,S.canUploadMore=f,S.formatDateTime=m,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){F.filters.leaveRequest.contact_id=null,F.refresh()}function p(){var e=F.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?F.leaveRequests.filter.list.length:F.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(F.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(F.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(F.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(F.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){F.absencePeriods=e.sortBy(t,"start_date"),F.filters.leaveRequest.selectedPeriod=e.find(F.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){F.absenceTypes=e})}function w(e){return(F.isAdmin?r.all(p()):r.leaveManagees(F.contactId,p())).then(function(t){return F.filteredUsers=F.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){F.filters.leaveRequest.leaveStatus!==H&&0===F.leaveRequests.table.list.length&&F.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){F.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:F.pagination,r="filter"===e?{return:["status_id"]}:{};return F.loading[n]=!0,l.all(S(t),a,"from_date DESC",r,!1).then(function(t){F.leaveRequests[e]=t}).catch(function(){F.leaveRequests[e].list=[]}).finally(function(){F.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){F.levelTypes=e})}function T(){return s.valuesOf("hrjc_location").then(function(e){F.locations=e})}function S(t){var n=F.filters.leaveRequest;return{contact_id:E(),managed_by:F.isAdmin&&"me"!==n.assignedTo.type?void 0:F.contactId,status_id:L(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(F.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){F.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){F.leaveRequestStatuses=e.concat(F.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function E(){return F.filteredUsers.length>0&&F.filters.leaveRequest.contact_id?F.filters.leaveRequest.contact_id:{IN:F.filteredUsers.map(function(e){return e.id})}}function M(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function L(e){var t=F.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=M(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(F.filters.leaveRequest.leaveStatus=H),(e<=F.totalNoOfPages()||0===F.totalNoOfPages())&&(F.pagination.page=e,w(n))}function j(e){F.filters.leaveRequest.leaveStatus=e,F.refresh(1,!1,"table")}function B(e){F.filters.leaveRequest.assignedTo=e,F.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){F.refresh()}),f.subscribe("LeaveRequest::new",function(){F.refresh()}),f.subscribe("LeaveRequest::edit",function(){F.refresh()}),f.subscribe("LeaveRequest::delete",function(){F.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){F.refresh()})}function U(){return Math.ceil(F.leaveRequests.table.total/F.pagination.size)}t.debug("Component: manage-leave-requests");var F=this,H={name:"all",label:"All"};F.absencePeriods=[],F.absenceTypes=[],F.filteredUsers=[],F.isFilterExpanded=!1,F.isAdmin=!1,F.leaveRequests={table:{list:[]},filter:{list:[]}},F.leaveRequestStatuses=[H],F.loading={content:!0,page:!0,table:!0},F.pagination={page:1,size:7},F.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],F.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:F.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:F.filtersByAssignee[0]}},F.clearStaffSelection=m,F.countLeaveRequestByStatus=h,F.getAbsenceTypeByID=v,F.getArrayOfSize=g,F.getLeaveStatusByValue=b,F.getNavBadge=y,F.getUserNameByID=q,F.labelPeriod=$,F.openLeavePopup=x,F.refresh=k,F.refreshWithFilter=j,F.refreshWithFilterByAssignee=B,F.totalNoOfPages=U,function(){o(i.permissions.admin.administer).then(function(e){F.isAdmin=e,n.all([C(),A(),O(),P(),T(),R(),I()]).then(function(){F.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),T(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(T)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function T(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=B.from_date!==u.request.from_date||B.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&U.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&U.hasExpirationFromAdminSettings,t=U.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return U.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){U.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),k(),l(),I())})})}function D(){u.isMode("view")||(C(), +A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function T(){return l(),I(),k()}function S(){return E(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),N?N=!1:I(),k()}function O(e){u.uiOptions.times[e].time=""}function I(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function x(){B=e.cloneDeep(u.request.attributes())}function E(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function M(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){R(!1)})}function L(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function k(){return m()?d().catch(a.resolve):a.resolve()}function j(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var B,N=!u.isMode("create"),U={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=T,u.openToilInDaysAccrualOptionsEditor=M,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=j,function(){x(),E(),L(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,r,o){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(o.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Te.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==U())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function E(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function L(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=U();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function U(){return Me.request?Me.request.request_type:Me.leaveType||null}function F(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Te,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=U(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Me.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Te[e+"_date"]})}function he(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function ve(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Te=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():E()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Te={},Se=[],Oe="",Ie="No entitlement",xe="",Ee=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=T,Me.canSubmit=S,Me.closeAlert=x,Me.deleteLeaveRequest=L,Me.dismissModal=k,Me.getStatuses=F,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(t){return t.module("admin-dashboard.settings",[]).constant("settings",{ +contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM),define("leave-absences/admin-dashboard/modules/config",["common/angular","leave-absences/admin-dashboard/modules/settings"],function(e){return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(e,t,n,a,r,o){var s={format:["DateFormat",function(e){return e.getDateFormat()}]};r.debugEnabled(o.debug),t.defaults.stripTrailingSlashes=!1,a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:s}).state("calendar",{url:"/calendar",template:'',resolve:s}).state("leave-balances",{url:"/leave-balances",template:"",resolve:s})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function t(e,t){e.debug("Component: admin-dashboard-container"),t.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",t]})}),define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/admin-dashboard":n+"/admin-dashboard"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js index fcb5fb68730..cfb12653f3d 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js @@ -6,9 +6,9 @@ */ -!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))h.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),h.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var v=s(u||{}),h=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+h.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,v)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,v)),m.$$inheritedValues=f(o.$$values,v),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,v)),o.then(i,u));for(var q=0,$=h.length;q<$;q+=3)a.hasOwnProperty(h[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(h[q],h[q+1],h[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(h.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(v[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return v[t]=new Y.Param(t,n,a,r),v[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},v=this.params=r?r.params.$$new():new Y.ParamSet,h=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=h}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:v,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,v=!0,h=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(v=e),v},this.defaultSquashPolicy=function(e){if(!j(e))return h;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return h=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!v.type.is(e))throw new Error("Default value ("+e+") for parameter '"+v.id+"' is not an instance of Type ("+v.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(v.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?v.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var v=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return h;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),h(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=L[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&h.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),h.update(!0),w.current)}).then(null,function(a){return a===D?S:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||h.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==v){d=n.$new(),v=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(h)}}var f,m,p,v,h=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:S(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function L(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function M(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return v.push(u),h[s]=r,function(){var e=v.indexOf(u);-1!==e&&v.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function E(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),h.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",h),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n){function a(e){e.absencePeriods&&c.absencePeriods.length&&(c.filters.period_id=o().id),e.absenceTypes&&c.absenceTypes.length&&(c.filters.type_id=s().id),(e.loggedInContactId||e.userRole)&&(c.filters.managed_by="manager"===c.userRole?c.loggedInContactId:void 0),r()&&c.submitFilters()}function r(){return e.every(c.filters,function(e){return null!==e})}function o(){return e.find(c.absencePeriods,function(e){return e.current})||c.absencePeriods.reduce(function(e,n){return t(e.end_date).isAfter(n.end_date)?e:n})}function s(){return c.absenceTypes.reduce(function(e,t){return e.title.localeCompare(t.title)?e:t})}function i(e){return e.current?"Current Period ("+e.title+")":e.title}function u(){n.$emit("LeaveBalanceFilters::update",c.filters)}var c=this;c.filters={period_id:null,type_id:null,managed_by:null},c.$onChanges=a,c.labelPeriod=i,c.submitFilters=u}n.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,t){return e.extend({all:function(e,n,a,r,o){return t.getLeaveBalances(this.processFilters(e),n,a,r,o)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){return r.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function p(){return o.all().then(o.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function v(){return s.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function h(){return n.all([m(),p(),v(),g(),q()]).catch(function(e){u.error("Error",e)})}function g(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function b(){return P.loading.report=!0,i.all(w,P.pagination,void 0,void 0,!1).then(function(e){P.report=y(e.list),P.reportCount=e.total}).catch(function(e){u.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function y(n){return n.map(function(n){return n=e.copy(n),n.absence_types=t.indexBy(n.absence_types,function(e){return e.id}),n})}function _(){a.$on("LeaveBalanceFilters::update",C),c.subscribe("LeaveRequest::new",$)}function q(){return f(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function $(e){C(e,w)}function C(e,t){w=t,P.pagination.page=1,A(),P.loadReportCurrentPage()}function A(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+w.type_id})}var w={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.loadReportCurrentPage=b,function(){_(),h().then(function(){P.loading.component=!1})}()}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(h.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(h.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=h.filters.userSettings.assignedTo.type;return f(e).then(function(e){h.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return h.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(m(),null,"display_name").then(function(e){return e.list})}function d(){return v?a.resolve(v):s.all()}function f(e){return"me"===e?r.leaveManagees(h.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function m(){return{department:h.filters.userSettings.department?h.filters.userSettings.department.value:null,level_type:h.filters.userSettings.level_type?h.filters.userSettings.level_type.value:null,location:h.filters.userSettings.location?h.filters.userSettings.location.value:null,region:h.filters.userSettings.region?h.filters.userSettings.region.value:null,id:{IN:h.filters.userSettings.contact?[h.filters.userSettings.contact.id]:h.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var v,h;return{init:function(e){return h=e,h.showContactDetailsLink=!0,h.showContactName=!0,h.showFilters=!0,h.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],h.filters.userSettings.assignedTo=h.filtersByAssignee[0],h.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(L.selectedPeriod.start_date).clone().startOf("month"),a=n(L.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");L.months=e}function p(){s.$new().$watch(function(){return L.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function v(e){L.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){L.loading.calendar=!1})}function h(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(L)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){L.absencePeriods=t.sortBy(e,"start_date"),L.selectedPeriod=t.find(L.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){L.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){L.filters.optionValues.regions=e.hrjc_region,L.filters.optionValues.locations=e.hrjc_location,L.filters.optionValues.levelTypes=e.hrjc_level_type,L.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){L.supportData.absenceTypes=e[0],L.supportData.publicHolidays=e[1],L.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,L.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,L.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,L.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return L.injectMonths&&(e=O("destroyed"),L.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){L.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){v("contacts"===e)})}function R(e){var n=L.selectedMonths.length?L.months.filter(function(e){return t.includes(L.selectedMonths,e.index)}):L.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){L.selectedMonths=[n().month()]}function T(){return L.roleOverride?r.resolve().then(function(){x=L.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===L.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,L=this;L.absencePeriods=[],L.contacts=[],L.contactIdsToReduceTo=null,L.injectMonths=!1,L.months=[],L.selectedMonths=null,L.selectedPeriod=null,L.showContactName=!1,L.showFilters=!1,L.supportData={},L.loading={calendar:!0,page:!0},L.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},L.labelPeriod=g,L.refresh=D,function(){T().then(p).then(h).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return L.showFilters?$():t.noop}).then(function(){v()}).then(function(){L.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function v(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function h(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),v())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){h()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function v(e){I(e),B(e)}function h(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",E)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",v)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?v(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([O(),T()]).then(g).then(M).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function L(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function M(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return L(e,t.id)}))}))}function E(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(v(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return L(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=h,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}), -define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(v(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):v(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function v(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function h(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=h,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function v(e){return q.mode===e}function h(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=v,q.onBeforeSubmit=h,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function v(e){return t(e).format(u.serverDateFormat)}function h(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function S(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function T(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function L(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function E(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return v(te.request.from_date)===v(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?v(e.fromDate):null,te.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:E},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=v,te.dateChangeHandler=h,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),L()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(S).then(V).then(P).then(T).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||T.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=w,T.canRemoveAttachment=A,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=v,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function v(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function h(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function T(t){var n=U.filters.leaveRequest;return{contact_id:L(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:E(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function L(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function M(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function E(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=M(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=v,U.getAbsenceTypeByID=h,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=x,U.refresh=k,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),O(),P(),S(),R(),I()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function v(){return r.resolve()}function h(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),S(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(S)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function S(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function T(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=v,s.initDayTypesExtended=h,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=T,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){ -function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return h().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=j.from_date!==u.request.from_date||j.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&N.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function v(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function h(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&N.hasExpirationFromAdminSettings,t=N.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return N.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){N.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),E(),l(),O())})})}function D(){u.isMode("view")||(C(),A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function S(){return l(),O(),E()}function T(){return x(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),B?B=!1:O(),E()}function O(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function I(){j=e.cloneDeep(u.request.attributes())}function x(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function L(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){R(!1)})}function M(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function E(){return m()?d().catch(a.resolve):a.resolve()}function k(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var j,B=!u.isMode("create"),N={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=v,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=S,u.openToilInDaysAccrualOptionsEditor=L,u.setDaysSelectionModeExtended=T,u.updateExpiryDate=k,function(){I(),x(),M(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function v(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function h(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?v.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([h.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([h.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,v,h,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Le.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Le.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==F())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function L(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function F(){return Me.request?Me.request.request_type:Me.leaveType||null}function U(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Se,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(ve).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(ve).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Le.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=F(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return v.all().then(function(e){Me.absencePeriods=e})}function ie(){return h.all(j()).then(h.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Se[e+"_date"]})}function ve(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function he(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Se=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():L()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Le.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Le=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=S,Me.canSubmit=T,Me.closeAlert=x,Me.deleteLeaveRequest=E,Me.dismissModal=k,Me.getStatuses=U,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(he).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"}, -templateUrl:["settings",function(e){return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e){define("leave-absences/manager-leave/modules/config",["common/angular","leave-absences/manager-leave/modules/settings"],function(t){return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/manager-leave/requests"),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","common/services/crm-ang.service","leave-absences/shared/ui-router","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); +!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in T)B(T[o])&&(t[o]=T[o](t,T.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=L[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),w.current)}).then(null,function(a){return a===D?T:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function T(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:T(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function L(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function E(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,T(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n){function a(e){e.absencePeriods&&c.absencePeriods.length&&(c.filters.period_id=o().id),e.absenceTypes&&c.absenceTypes.length&&(c.filters.type_id=s().id),(e.loggedInContactId||e.userRole)&&(c.filters.managed_by="manager"===c.userRole?c.loggedInContactId:void 0),r()&&c.submitFilters()}function r(){return e.every(c.filters,function(e){return null!==e})}function o(){return e.find(c.absencePeriods,function(e){return e.current})||c.absencePeriods.reduce(function(e,n){return t(e.end_date).isAfter(n.end_date)?e:n})}function s(){return c.absenceTypes.reduce(function(e,t){return e.title.localeCompare(t.title)?e:t})}function i(e){return e.current?"Current Period ("+e.title+")":e.title}function u(){n.$emit("LeaveBalanceFilters::update",c.filters)}var c=this;c.filters={period_id:null,type_id:null,managed_by:null},c.$onChanges=a,c.labelPeriod=i,c.submitFilters=u}n.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,t){return e.extend({all:function(e,n,a,r,o){return t.getLeaveBalances(this.processFilters(e),n,a,r,o)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){return r.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function p(){return o.all().then(o.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function h(){return s.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function v(){return n.all([m(),p(),h(),g(),q()]).catch(function(e){u.error("Error",e)})}function g(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function b(){return P.loading.report=!0,i.all(w,P.pagination,void 0,void 0,!1).then(function(e){P.report=y(e.list),P.reportCount=e.total}).catch(function(e){u.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function y(n){return n.map(function(n){return n=e.copy(n),n.absence_types=t.indexBy(n.absence_types,function(e){return e.id}),n})}function _(){a.$on("LeaveBalanceFilters::update",C),c.subscribe("LeaveRequest::new",$)}function q(){return f(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function $(e){C(e,w)}function C(e,t){w=t,P.pagination.page=1,A(),P.loadReportCurrentPage()}function A(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+w.type_id})}var w={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.loadReportCurrentPage=b,function(){_(),v().then(function(){P.loading.component=!1})}()}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return f(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(m(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function f(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function m(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(L.selectedPeriod.start_date).clone().startOf("month"),a=n(L.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");L.months=e}function p(){s.$new().$watch(function(){return L.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){L.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){L.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(L)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){L.absencePeriods=t.sortBy(e,"start_date"),L.selectedPeriod=t.find(L.absencePeriods,function(e){return!!e.current})}).then(m).then(T)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){L.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){L.filters.optionValues.regions=e.hrjc_region,L.filters.optionValues.locations=e.hrjc_location,L.filters.optionValues.levelTypes=e.hrjc_level_type,L.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){L.supportData.absenceTypes=e[0],L.supportData.publicHolidays=e[1],L.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,L.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,L.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,L.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return L.injectMonths&&(e=O("destroyed"),L.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){L.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=L.selectedMonths.length?L.months.filter(function(e){return t.includes(L.selectedMonths,e.index)}):L.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function T(){L.selectedMonths=[n().month()]}function S(){return L.roleOverride?r.resolve().then(function(){x=L.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===L.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,L=this;L.absencePeriods=[],L.contacts=[],L.contactIdsToReduceTo=null,L.injectMonths=!1,L.months=[],L.selectedMonths=null,L.selectedPeriod=null,L.showContactName=!1,L.showFilters=!1,L.supportData={},L.loading={calendar:!0,page:!0},L.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},L.labelPeriod=g,L.refresh=D,function(){S().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return L.showFilters?$():t.noop}).then(function(){h()}).then(function(){L.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",M)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function T(){return W.month.loading=!0,a.all([O(),S()]).then(g).then(E).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function L(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function E(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return L(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&T())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return L(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}), +define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return E()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function T(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function L(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function E(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([E(),L()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(T).then(V).then(P).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function f(){return S.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){T[e.label]=t})})).catch(function(){T=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||S.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],T={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=w,S.canRemoveAttachment=A,S.canSubmit=d,S.canUploadMore=f,S.formatDateTime=m,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(S(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function T(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function S(t){var n=U.filters.leaveRequest;return{contact_id:L(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:M(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function L(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function E(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function M(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=E(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=h,U.getAbsenceTypeByID=v,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=x,U.refresh=k,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),O(),P(),T(),R(),I()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),T(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(T)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function T(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){ +function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=B.from_date!==u.request.from_date||B.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&F.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&F.hasExpirationFromAdminSettings,t=F.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return F.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){F.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),k(),l(),I())})})}function D(){u.isMode("view")||(C(),A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function T(){return l(),I(),k()}function S(){return L(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),N?N=!1:I(),k()}function O(e){u.uiOptions.times[e].time=""}function I(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function x(){B=e.cloneDeep(u.request.attributes())}function L(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function E(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){R(!1)})}function M(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function k(){return m()?d().catch(a.resolve):a.resolve()}function j(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var B,N=!u.isMode("create"),F={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=T,u.openToilInDaysAccrualOptionsEditor=E,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=j,function(){x(),L(),M(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Ee.selectedAbsenceType.calculation_unit_name?delete Ee.request[e+"_date_amount"]:delete Ee.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Ee.requestStatuses[_.statusNames.awaitingApproval].value;Te.status_id===e&&e!==Ee.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Le.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Le.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return!Ee.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=D();return Ee.isMode("edit")&&(e=e&&(V()||R())),Ee.canManage&&Ee.requestStatuses&&(e=e&&!!Ee.getStatusFromValue(Ee.newStatusOnSave)),(e=e&&!!Ee.period.id)&&!Ee.isMode("view")}function O(){Ee.isSelfRecord?Ee.request.status_id=Ee.requestStatuses[_.statusNames.awaitingApproval].value:Ee.canManage&&(Ee.request.status_id=Ee.newStatusOnSave||Ee.request.status_id)}function I(){if(Ee.isMode("edit")&&!Ee.isRole("staff")&&"toil"!==F())return Ee.request.calculateBalanceChange(Ee.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ee.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Ee.errors=[]}function L(){return Ee.request.create().then($e).then(function(){me("LeaveRequest::new")})}function E(){ee()&&!Ee.isRole("staff")&&(Ee.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ee.request.delete().then(function(){Ee.dismissModal(),d.publish("LeaveRequest::delete",Ee.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Ee.getStatusFromValue(Ee.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Ee.requestStatuses[e]})}function F(){return Ee.request?Ee.request.request_type:Ee.leaveType||null}function U(){return!Ee.request||e.equals({},Ee.requestStatuses)?[]:Ee.request.status_id?B():N("none")}function H(e){return n.find(Ee.requestStatuses,function(t){return t.value===e})}function W(e){Ee.errors=n.isArray(e)?e:[e],Ee.loading.absenceTypes=!1,Ee.submitting=!1}function V(){return!e.equals(Te,Ee.request.attributes())||Ee.canManage&&Ee.newStatusOnSave}function G(){return Ee.postContactSelection=!0,Ee.staffMemberSelectionComplete=!1,Ee.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Ee.isMode("edit")?be:n.noop).then(function(){Ee.postContactSelection=!1,Ee.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Ee.canManage?m.find(Ee.request.contact_id).then(function(e){Ee.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ee.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Le.push(t)})}function K(){var e,t;Ee.request=Ee.leaveRequest||null,e=F(),t=Ee.initRequestAttributes(),"leave"===e?Ee.request=y.init(t):"sickness"===e?Ee.request=q.init(t):"toil"===e&&(Ee.request=$.init(t))}function X(){var e={};return Ee.request?e=Ee.request.attributes():Ee.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Ee.canManage=Ee.isRole("manager")||Ee.isRole("admin")})}function Z(){(Ee.isRole("admin")||Ee.isMode("create")&&Ee.isRole("manager"))&&(Ee.newStatusOnSave=Ee.requestStatuses[_.statusNames.approved].value)}function ee(){return!Ee.request.status_id||!n.includes(["cancelled","rejected"],H(Ee.request.status_id).name)}function te(e){var t=Ee.getStatusFromValue(Ee.request.status_id);return!!t&&t.name===e}function ne(e){return Ee.request&&Ee.request.request_type===e}function ae(e){return Ee.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Ee.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Ee.loading.entitlements=!0,g.all({contact_id:Ee.request.contact_id,period_id:Ee.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Ee.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Ee.selectedContactId?m.find(Ee.selectedContactId).then(function(e){Ee.managedContacts=[e]}):Ee.isRole("admin")?m.all().then(function(e){Ee.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Ee.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ee.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Ee.request),Ee.errors=[],Ee.dismissModal()}function pe(){["from","to"].forEach(function(e){Ee.request[e+"_date"]=Te[e+"_date"]})}function he(e){if(Ee.absenceTypes=fe(Pe.types,e),!Ee.absenceTypes.length)return r.reject(Ie)}function ve(){Ee.period=n.find(Ee.absencePeriods,function(e){return Ee.isMode("create")?e.current:re(Ee.request,e)})}function ge(){Ee.isMode("create")?(Ee.selectedAbsenceType=Ee.absenceTypes[0],Ee.request.type_id=Ee.selectedAbsenceType.id):Ee.selectedAbsenceType=n.find(Ee.absenceTypes,function(e){return e.id===Ee.request.type_id})}function be(){Te=e.copy(Ee.request.attributes())}function ye(){var e;Ee.request.id?(e=[Ee.requestStatuses[_.statusNames.approved].value,Ee.requestStatuses[_.statusNames.adminApproved].value,Ee.requestStatuses[_.statusNames.rejected].value,Ee.requestStatuses[_.statusNames.cancelled].value],Ee.mode="edit",Ee.isRole("staff")&&e.indexOf(Ee.request.status_id)>-1&&(Ee.mode="view")):Ee.mode="create"}function _e(){var e=Ee.request.status_id;if(!Ee.isMode("view")&&!Ee.submitting)return Ee.submitting=!0,O(),w(),Ee.request.isValid().then(ee()&&I).then(E).then(!Ee.request.change_balance&&pe).then(qe).then(function(){return Ee.isMode("edit")?we():L()}).catch(function(t){Ee.request.status_id=e,t&&W(t)}).finally(function(){Ee.submitting=!1})}function qe(){return r.all(Le.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Ee.request.update().then($e).then(function(){Ee.isRole("manager")?me("LeaveRequest::updatedByManager"):(Ee.isRole("staff")||Ee.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Te={},Se=[],Oe="",Ie="No entitlement",xe="",Le=[],Ee=n.assign(this,f);Ee.absencePeriods=[],Ee.absenceTypes=[],Ee.canManage=!1,Ee.contactName=null,Ee.errors=[],Ee.loading={absenceTypes:!0,entitlements:!0},Ee.managedContacts=[],Ee.mode="",Ee.newStatusOnSave=null,Ee.period={},Ee.postContactSelection=!1,Ee.requestStatuses={},Ee.selectedAbsenceType={},Ee.staffMemberSelectionComplete=!1,Ee.submitting=!1,Ee.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ee.canChangeAbsenceType=T,Ee.canSubmit=S,Ee.closeAlert=x,Ee.deleteLeaveRequest=M,Ee.dismissModal=k,Ee.getStatuses=U,Ee.getStatusFromValue=H,Ee.initAfterContactSelection=G,Ee.initRequestAttributes=X,Ee.isLeaveStatus=te,Ee.isLeaveType=ne,Ee.isMode=ae,Ee.isRole=oe,Ee.submit=_e,Ee.updateAbsenceType=Ae,function(){Ee.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Ee.canManage&&!Ee.isMode("edit")&&le()}).then(function(){if(Ee.selectedContactId&&(Ee.request.contact_id=Ee.selectedContactId),Ee.request.contact_id)return Ee.initAfterContactSelection()}).catch(W).finally(function(){Ee.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}), +define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e){define("leave-absences/manager-leave/modules/config",["common/angular","leave-absences/manager-leave/modules/settings"],function(t){return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/manager-leave/requests"),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","common/services/crm-ang.service","leave-absences/shared/ui-router","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js index a1a04b83655..020ba2588d8 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js @@ -6,9 +6,9 @@ */ -!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[m]),c[r[m]]=e[r[m]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&f(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,f),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),f.$$values=b,f.$$promises=f.$$promises||!0,delete f.$$inheritedValues,c.resolve(b))}function u(e){f.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),f=c.promise,g=f.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),f;o.$$inheritedValues&&r(b,m(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,m(o.$$values,h)),f.$$inheritedValues=m(o.$$values,h),i()):(o.$$inheritedValues&&(f.$$inheritedValues=m(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(f.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),m=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(m++,g[e].then(function(t){b[e]=t,--m||l()},c))}),m||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return f}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(m,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",m=0,f=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),f.push(g.segment),m=c.lastIndex;y=e.substring(m);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,m+_),q.length>0)for(m=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),m=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",f.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=f[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:m}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,m=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(m=e),m},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(f(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function m(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),f(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:m})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(D.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!D[r])return f(r,t.self);for(var o in R)B(R[o])&&(t[o]=R[o](t,R.$delegates[o]));return D[n]=t,!t[T]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){A.$current.navigable==t&&c(e,n)||A.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=A.$current.name.split("."),a=0,r=t.length;a=D;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=D;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.$current=t,A.current=t.self,A.params=n,V(A.params,f),A.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),A.current)}).then(null,function(a){return a===P?R:A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},A.is=function(e,t,a){a=W({relative:A.$current},a||{});var r=m(e,a.relative);return j(r)?A.$current===r&&(!t||c(r.params.$$values(t),f)):n},A.includes=function(e,t,a){if(a=W({relative:A.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=A.$current.name}var r=m(e,a.relative);if(!j(r))return n;if(!j(A.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(m&&(m.remove(),m=null),p&&(p.$destroy(),p=null),f){var e=f.data("$uiViewAnim");b.leave(f,function(){e.$$animLeave.resolve(),m=null}),m=f,f=null}}function d(s){var d,m=P(n,c,i,r),y=m&&e.$current&&e.$current.locals[m];if(s||y!==h){d=n.$new(),h=e.$current.locals[m],d.$emit("$viewContentLoading",m);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});f=_,p=d,p.$emit("$viewContentLoaded",m),p.$eval(v)}}var m,f,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function D(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=P(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var m=t.extend({},d);o[d.$$resolveAs]=m;var f=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=m),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}f(o)}}}}}function P(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function T(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function R(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function x(e,t){return{relative:R(e)||t.$current,inherit:!0}}function I(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=T(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],m=null;c.options=W(x(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var f=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),m&&m(),d&&(m=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&f(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),f(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){m.state=t[0],m.params=t[1],m.options=t[2],m.href=e.href(m.state,m.params,m.options),f&&f(),c&&(f=c.$$addStateInfo(m.state,m.params)),m.href&&r.$set(u.attr,m.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",m={state:null,params:null,options:null,href:null},f=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return m}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function L(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,R(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function m(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,m){function f(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(D(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||T()})}function h(e){E.injectMonths=!0,O("injected").then(function(){T(e)}).then(function(){E.loading.calendar=!1})}function v(){x=a("LeaveCalendar"+t.capitalize(I)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(f).then(R)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return x.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function w(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function D(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function P(e){ -e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(A).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function T(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function R(){E.selectedMonths=[n().month()]}function S(){return E.roleOverride?r.resolve().then(function(){I=E.roleOverride}):r.all([m(i.permissions.admin.administer),m(i.permissions.ssp.manage)]).then(function(e){I=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var x,I,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=P,function(){S().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),w()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function m(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?f():p()}function f(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),m(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function m(e){return U[e]}function f(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){x(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",M)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function w(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function D(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function P(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function T(){return[P(u.statusNames.approved),P(u.statusNames.adminApproved),P(u.statusNames.awaitingApproval),P(u.statusNames.moreInformationRequired)]}function R(){return W.month.loading=!0,a.all([O(),S()]).then(g).then(L).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:T()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function x(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function I(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=m(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?w(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function L(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&R())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=D(e);t&&(h(t),-1!==T().indexOf(e.status_id)&&c(e))}function B(e){return a.all(A(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=I,W.contactsList=f,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return L()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(A).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function w(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(A)}function A(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function D(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():w()}function P(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function T(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function R(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function x(e){return te.request.request_type===e}function I(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function L(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(A).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,f(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(x("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||x("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=A,te.isCalculationUnit=O,te.isLeaveType=x,te.isNotWorkingDay=I,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),T(),te.initChildController().then(function(){return s.all([L(),E()])}).then(!te.isMode("create")&&P).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(R).then(V).then(D).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(A).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function m(){return S.getFilesAmount()0?P.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(P.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){R[e.label]=t})})).catch(function(){R=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){P=e})}function w(e){return!e.attachment_id||S.canManage}function A(){e.forEach(T,function(e){e()})}function D(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var P=[],T=[],R={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=A,S.canRemoveAttachment=w,S.canSubmit=d,S.canUploadMore=m,S.formatDateTime=f,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,r,o,s,i,u,c,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){k(e),H.sections.other.open&&f(e,H.sections.other)}function h(){Object.values(H.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):H.refresh()}function g(t){t.dataIndex=e.indexBy(t.data,"id")}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function y(){return o.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.selectedPeriod=e.find(H.absencePeriods,function(e){return!0===e.current})})}function _(){return s.all().then(s.loadCalculationUnits).then(function(t){H.absenceTypes=t,H.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return P("approved",{status_id:F(m.statusNames.approved)})}function $(){return n.all([u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,null,!0),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.approved)]),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){H.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function C(){return i.all({contact_id:H.contactId,period_id:H.selectedPeriod.id},!0).then(function(e){H.entitlements=e}).then(function(){H.absenceTypesFiltered=H.absenceTypes.filter(function(t){var n=e.find(H.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function w(){return i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id},H.entitlements).then(function(){return E(H.entitlements)}).then(function(e){H.sections.entitlements.data=e})}function A(){return n.all([i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id,expired:!0}),D({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:E(e[0]),expiredTOILS:L(e[1].list)})}).then(function(t){ -H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function D(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function P(e,t){return D(t).then(function(t){H.sections[e].data=t.list})}function T(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(x))}function R(){return P("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function S(){return P("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function O(){return P("holidays",{public_holiday:!0})}function x(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function I(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function E(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function L(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){k(e)})}function k(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([C(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([T(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&x(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:k,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([I(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([C(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return D(n,e),e})):r.reject([])}function f(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),R(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(w)).then(function(){["from","to"].forEach(function(e){b(e),T(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(R)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&T(e,!0))})}function $(e,t){return m(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return w(e).then(function(){T(e,!0)})})}function w(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function A(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function D(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function P(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),w("from").then(function(){T("from",!0)})):r.resolve()}function T(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function R(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?w("from").then(function(){T("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=A,s.setDaysSelectionModeExtended=P}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function m(){return!!u.request.toil_to_accrue}function f(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=j.from_date!==u.request.from_date||j.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&N.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&N.hasExpirationFromAdminSettings,t=N.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return N.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){N.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(T)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function w(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function A(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function D(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),M(),l(),O())})})}function P(){u.isMode("view")||(C(),w(),D())}function T(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,"value")})}function R(){return l(),O(),M()}function S(){return I(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),B?B=!1:O(),M()}function O(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function x(){j=e.cloneDeep(u.request.attributes())}function I(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function E(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmFormSuccess",function(){T(!1)})}function L(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function M(){return f()?d().catch(a.resolve):a.resolve()}function k(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var j,B=!u.isMode("create"),N={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=m,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=A,u.initWatchersExtended=P,u.onDateChangeExtended=R,u.openToilInDaysAccrualOptionsEditor=E,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=k,function(){x(),I(),L(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,m,f,p,h,v,g,b,y,_,q,$,C){function w(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function A(){["from","to"].forEach(w)}function D(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Re.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=P();return Le.isMode("edit")&&(e=e&&(V()||T())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function O(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function x(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==F())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function I(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){fe("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(Pe[e],function(e){return Le.requestStatuses[e]})}function F(){return Le.request?Le.request.request_type:Le.leaveType||null}function U(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Re,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==xe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Pe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Pe.awaiting_approval=e,Pe.more_information_required=e,Pe.rejected=e,Pe.approved=e,Pe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?f.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Te++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=F(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:Oe}),e}function Q(){if(Ie="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Ie="admin")}).then(function(){return"staff"===Ie&&u(_.permissions.ssp.manage).then(function(e){e&&(Ie="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Ie===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){De={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:De.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Le.selectedContactId?f.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?f.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):f.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){D(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Re[e+"_date"]})}function he(e){if(Le.absenceTypes=me(De.types,e),!Le.absenceTypes.length)return r.reject(xe)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Re=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,O(),A(),Le.request.isValid().then(ee()&&x).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?Ae():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Te&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Te>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function we(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?fe("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var De,Pe={},Te=0,Re={},Se=[],Oe="",xe="No entitlement",Ie="",Ee=[],Le=n.assign(this,m);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=R,Le.canSubmit=S,Le.closeAlert=I,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=U,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=we,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM), +!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[m]),c[r[m]]=e[r[m]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&f(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,f),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),f.$$values=b,f.$$promises=f.$$promises||!0,delete f.$$inheritedValues,c.resolve(b))}function u(e){f.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),f=c.promise,g=f.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),f;o.$$inheritedValues&&r(b,m(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,m(o.$$values,h)),f.$$inheritedValues=m(o.$$values,h),i()):(o.$$inheritedValues&&(f.$$inheritedValues=m(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(f.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),m=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(m++,g[e].then(function(t){b[e]=t,--m||l()},c))}),m||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return f}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(m,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",m=0,f=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),f.push(g.segment),m=c.lastIndex;y=e.substring(m);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,m+_),q.length>0)for(m=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),m=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",f.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=f[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:m}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,m=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(m=e),m},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(f(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function m(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),f(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:m})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(D.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!D[r])return f(r,t.self);for(var o in R)B(R[o])&&(t[o]=R[o](t,R.$delegates[o]));return D[n]=t,!t[T]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){A.$current.navigable==t&&c(e,n)||A.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=A.$current.name.split("."),a=0,r=t.length;a=D;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=D;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.$current=t,A.current=t.self,A.params=n,V(A.params,f),A.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),A.current)}).then(null,function(a){return a===P?R:A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},A.is=function(e,t,a){a=W({relative:A.$current},a||{});var r=m(e,a.relative);return j(r)?A.$current===r&&(!t||c(r.params.$$values(t),f)):n},A.includes=function(e,t,a){if(a=W({relative:A.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=A.$current.name}var r=m(e,a.relative);if(!j(r))return n;if(!j(A.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(m&&(m.remove(),m=null),p&&(p.$destroy(),p=null),f){var e=f.data("$uiViewAnim");b.leave(f,function(){e.$$animLeave.resolve(),m=null}),m=f,f=null}}function d(s){var d,m=P(n,c,i,r),y=m&&e.$current&&e.$current.locals[m];if(s||y!==h){d=n.$new(),h=e.$current.locals[m],d.$emit("$viewContentLoading",m);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});f=_,p=d,p.$emit("$viewContentLoaded",m),p.$eval(v)}}var m,f,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function D(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=P(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var m=t.extend({},d);o[d.$$resolveAs]=m;var f=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=m),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}f(o)}}}}}function P(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function T(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function R(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:R(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=T(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],m=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var f=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),m&&m(),d&&(m=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&f(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),f(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){m.state=t[0],m.params=t[1],m.options=t[2],m.href=e.href(m.state,m.params,m.options),f&&f(),c&&(f=c.$$addStateInfo(m.state,m.params)),m.href&&r.$set(u.attr,m.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",m={state:null,params:null,options:null,href:null},f=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return m}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function L(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,R(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function m(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,m){function f(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(D(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||T()})}function h(e){E.injectMonths=!0,O("injected").then(function(){T(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(f).then(R)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function w(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function D(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function P(e){ +e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(A).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function T(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function R(){E.selectedMonths=[n().month()]}function S(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([m(i.permissions.admin.administer),m(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=P,function(){S().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),w()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function m(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?f():p()}function f(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),m(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function m(e){return U[e]}function f(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",M)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function w(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function D(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function P(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function T(){return[P(u.statusNames.approved),P(u.statusNames.adminApproved),P(u.statusNames.awaitingApproval),P(u.statusNames.moreInformationRequired)]}function R(){return W.month.loading=!0,a.all([O(),S()]).then(g).then(L).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:T()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=m(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?w(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function L(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&R())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=D(e);t&&(h(t),-1!==T().indexOf(e.status_id)&&c(e))}function B(e){return a.all(A(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=f,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return L()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(A).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function w(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(A)}function A(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function D(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():w()}function P(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function T(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function R(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function L(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(A).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,f(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=A,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),T(),te.initChildController().then(function(){return s.all([L(),E()])}).then(!te.isMode("create")&&P).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(R).then(V).then(D).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(A).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function m(){return S.getFilesAmount()0?P.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(P.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){R[e.label]=t})})).catch(function(){R=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){P=e})}function w(e){return!e.attachment_id||S.canManage}function A(){e.forEach(T,function(e){e()})}function D(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var P=[],T=[],R={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=A,S.canRemoveAttachment=w,S.canSubmit=d,S.canUploadMore=m,S.formatDateTime=f,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,r,o,s,i,u,c,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){k(e),H.sections.other.open&&f(e,H.sections.other)}function h(){Object.values(H.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):H.refresh()}function g(t){t.dataIndex=e.indexBy(t.data,"id")}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function y(){return o.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.selectedPeriod=e.find(H.absencePeriods,function(e){return!0===e.current})})}function _(){return s.all().then(s.loadCalculationUnits).then(function(t){H.absenceTypes=t,H.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return P("approved",{status_id:F(m.statusNames.approved)})}function $(){return n.all([u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,null,!0),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.approved)]),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){H.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function C(){return i.all({contact_id:H.contactId,period_id:H.selectedPeriod.id},!0).then(function(e){H.entitlements=e}).then(function(){H.absenceTypesFiltered=H.absenceTypes.filter(function(t){var n=e.find(H.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function w(){return i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id},H.entitlements).then(function(){return E(H.entitlements)}).then(function(e){H.sections.entitlements.data=e})}function A(){return n.all([i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id,expired:!0}),D({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:E(e[0]),expiredTOILS:L(e[1].list)})}).then(function(t){ +H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function D(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function P(e,t){return D(t).then(function(t){H.sections[e].data=t.list})}function T(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(I))}function R(){return P("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function S(){return P("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function O(){return P("holidays",{public_holiday:!0})}function I(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function x(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function E(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function L(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){k(e)})}function k(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([C(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([T(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&I(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:k,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([x(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([C(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return D(n,e),e})):r.reject([])}function f(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),R(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(w)).then(function(){["from","to"].forEach(function(e){b(e),T(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(R)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&T(e,!0))})}function $(e,t){return m(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return w(e).then(function(){T(e,!0)})})}function w(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function A(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function D(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function P(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),w("from").then(function(){T("from",!0)})):r.resolve()}function T(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function R(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?w("from").then(function(){T("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=A,s.setDaysSelectionModeExtended=P}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function m(){return!!u.request.toil_to_accrue}function f(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=B.from_date!==u.request.from_date||B.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&F.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&F.hasExpirationFromAdminSettings,t=F.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return F.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){F.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(T)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function w(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function A(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function D(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),k(),l(),I())})})}function P(){u.isMode("view")||(C(),w(),D())}function T(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function R(){return l(),I(),k()}function S(){return E(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),N?N=!1:I(),k()}function O(e){u.uiOptions.times[e].time=""}function I(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function x(){B=e.cloneDeep(u.request.attributes())}function E(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function L(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){T(!1)})}function M(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function k(){return f()?d().catch(a.resolve):a.resolve()}function j(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var B,N=!u.isMode("create"),F={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=m,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=A,u.initWatchersExtended=P,u.onDateChangeExtended=R,u.openToilInDaysAccrualOptionsEditor=L,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=j,function(){x(),E(),M(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,m,f,p,h,v,g,b,y,_,q,$,C){function w(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function A(){["from","to"].forEach(w)}function D(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Re.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=P();return Le.isMode("edit")&&(e=e&&(V()||T())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function O(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function I(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==F())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){fe("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(Pe[e],function(e){return Le.requestStatuses[e]})}function F(){return Le.request?Le.request.request_type:Le.leaveType||null}function U(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Re,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Pe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Pe.awaiting_approval=e,Pe.more_information_required=e,Pe.rejected=e,Pe.approved=e,Pe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?f.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Te++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=F(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){De={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:De.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Le.selectedContactId?f.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?f.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):f.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){D(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Re[e+"_date"]})}function he(e){if(Le.absenceTypes=me(De.types,e),!Le.absenceTypes.length)return r.reject(Ie)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Re=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,O(),A(),Le.request.isValid().then(ee()&&I).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?Ae():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Te&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Te>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function we(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?fe("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var De,Pe={},Te=0,Re={},Se=[],Oe="",Ie="No entitlement",xe="",Ee=[],Le=n.assign(this,m);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=R,Le.canSubmit=S,Le.closeAlert=x,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=U,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=we,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM), define("leave-absences/my-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/models/option-group","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/my-leave/components/my-leave-container.component","leave-absences/my-leave/modules/config"],function(e){return e.module("my-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.mocks","common.models","common.services","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","my-leave.components","my-leave.config"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/my-leave":n+"/my-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/my-leave/app"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-my-leave]"),["my-leave"])})})}(CRM,require),define("my-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.js.map \ No newline at end of file From 853f8a1800f2bee9d275706db327868c4b9bbeb0 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Mon, 9 Apr 2018 16:22:32 +0100 Subject: [PATCH 122/203] PCHR-3525: PR Feedback --- .../time-amount-picker.directive.spec.js | 15 +++++++---- ...uest-modal-details-toil.controller.spec.js | 26 ++++++++++++------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/org.civicrm.reqangular/test/directives/time-amount-picker.directive.spec.js b/org.civicrm.reqangular/test/directives/time-amount-picker.directive.spec.js index eee13b32f69..9d53db1a659 100644 --- a/org.civicrm.reqangular/test/directives/time-amount-picker.directive.spec.js +++ b/org.civicrm.reqangular/test/directives/time-amount-picker.directive.spec.js @@ -9,7 +9,7 @@ define([ 'use strict'; describe('timeAmountPicker directive', function () { - var vm, $compile, $scope, $rootScope; + var element, vm, $compile, $scope, $rootScope; beforeEach(module('common.directives')); beforeEach(inject(function (_$rootScope_, _$compile_) { @@ -90,6 +90,7 @@ define([ describe('when hours value is changed and it is same as the maximum specified', function () { beforeEach(function () { vm.selectedHours = 7; + vm.buildMinutesOptions(); }); @@ -130,6 +131,10 @@ define([ expect(vm.selectedMinutes).toBe('30'); }); + it('sets value', function () { + expect(element.isolateScope().value).toBe(6.5); + }); + describe('when selected values are changed', function () { beforeEach(function () { vm.selectedHours = 8; @@ -139,7 +144,7 @@ define([ }); it('sets the result value back', function () { - expect($scope.$$childTail.value).toBe(8.75); + expect(element.isolateScope().value).toBe(8.75); }); }); @@ -147,14 +152,14 @@ define([ var newValue = '7'; beforeEach(function () { - $scope.$$childTail.maxAmount = newValue; + element.isolateScope().maxAmount = newValue; $scope.$digest(); }); describe('when the maximum possible value is set', function () { beforeEach(function () { - $scope.$$childTail.value = newValue; + element.isolateScope().value = newValue; $scope.$digest(); }); @@ -187,8 +192,8 @@ define([ */ function buildDirective (options) { var attrWrapper = ''; - var element = angular.element(''); + element = angular.element(''); $scope = $rootScope.$new(); options = options || []; diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js index c669a167cfb..7b58ff41874 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js @@ -102,15 +102,6 @@ define([ expect(retreiveCachedTOILOptions).not.toBe(false); }); - it('sorts TOIL accrual options by weight', function () { - expect(_.pluck(controller.toilAmounts, function (amount) { - return +amount.weight; - })).toEqual( - _.pluck(controller.toilAmounts, function (amount) { - return +amount.weight; - }).sort()); - }); - it('defaults to a multiple day selection', function () { expect(controller.uiOptions.multipleDays).toBe(true); }); @@ -120,6 +111,23 @@ define([ expect(controller.uiOptions.times.from.max).toBe('23:45'); }); + describe('after TOIL accrual options are loaded', function () { + var toilAmounts, toilAmountsSortedByWeight; + + beforeEach(function () { + toilAmountsSortedByWeight = _.pluck(controller.toilAmounts, function (amount) { + return +amount.weight; + }).sort(); + toilAmounts = _.pluck(controller.toilAmounts, function (amount) { + return +amount.weight; + }); + }); + + it('sorts TOIL accrual options by weight', function () { + expect(toilAmounts).toEqual(toilAmountsSortedByWeight); + }); + }); + describe('when multiple/single days mode changes', function () { describe('when the balance can but fails to be calculated', function () { beforeEach(function () { From 37890adfed803af61506fc50ae5215a4afb11974 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Tue, 10 Apr 2018 10:40:58 +0100 Subject: [PATCH 123/203] PCHR-3464: Hide link to edit locked option groups in forms This is achieved by removing the "data-option-edit-path", which is required to show the edit link --- .../Hook/BuildForm/OptionEditPathFilter.php | 72 +++++++++++++++++++ uk.co.compucorp.civicrm.hrcore/hrcore.php | 3 +- .../BuildForm/OptionEditPathFilterTest.php | 55 ++++++++++++++ 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Hook/BuildForm/OptionEditPathFilter.php create mode 100644 uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Hook/BuildForm/OptionEditPathFilterTest.php diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Hook/BuildForm/OptionEditPathFilter.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Hook/BuildForm/OptionEditPathFilter.php new file mode 100644 index 00000000000..cdd0cb2db04 --- /dev/null +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Hook/BuildForm/OptionEditPathFilter.php @@ -0,0 +1,72 @@ +filterOptionEditPaths($form); + } + + /** + * Loop through the form, removing the 'data-option-edit-path' from form + * elements that reference locked option groups. If this attribute is not set + * then the icon to provide a shortcut to edit this group will not be shown. + * + * @see \CRM_Core_Form_Renderer::addOptionsEditLink + * + * @param CRM_Core_Form $form + */ + private function filterOptionEditPaths($form) { + /** @var HTML_QuickForm_element $element */ + foreach ($form->_elements as &$element) { + $optionEditPath = $element->getAttribute('data-option-edit-path'); + if (!$optionEditPath) { + continue; + } + + $prefix = 'civicrm/admin/options/'; + if (strpos($optionEditPath, $prefix) !== 0) { + // this is not an option group edit link + continue; + } + + $optionGroupName = str_replace($prefix, '', $optionEditPath); + + if ($this->isLockedOptionGroup($optionGroupName)) { + $element->removeAttribute('data-option-edit-path'); + } + } + } + + /** + * Check whether a given option group is locked + * + * @param string $optionGroupName + * + * @return bool + */ + private function isLockedOptionGroup($optionGroupName) { + if (!isset($this->optionGroupLockedStatuses[$optionGroupName])) { + $params = ['return' => 'is_locked', 'name' => $optionGroupName]; + $result = civicrm_api3('OptionGroup', 'get', $params); + $result = array_shift($result['values']); + $isLocked = CRM_Utils_Array::value('is_locked', $result, FALSE); + $this->optionGroupLockedStatuses[$optionGroupName] = (bool) $isLocked; + } + + return $this->optionGroupLockedStatuses[$optionGroupName]; + } + +} diff --git a/uk.co.compucorp.civicrm.hrcore/hrcore.php b/uk.co.compucorp.civicrm.hrcore/hrcore.php index dd874808ba1..34dccfffc9e 100644 --- a/uk.co.compucorp.civicrm.hrcore/hrcore.php +++ b/uk.co.compucorp.civicrm.hrcore/hrcore.php @@ -107,7 +107,7 @@ function hrcore_civicrm_container($container) { } /** - * Implements hook_civicrm_buildForm + * Implements hook_civicrm_buildForm(). * * @param string $formName * @param CRM_Core_Form $form @@ -117,6 +117,7 @@ function hrcore_civicrm_buildForm($formName, &$form) { new CRM_HRCore_Hook_BuildForm_ActivityFilterSelectFieldsModifier(), new CRM_HRCore_Hook_BuildForm_ActivityLinksFilter(), new CRM_HRCore_Hook_BuildForm_LocalisationPageFilter(), + new CRM_HRCore_Hook_BuildForm_OptionEditPathFilter(), ]; foreach ($listeners as $currentListener) { diff --git a/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Hook/BuildForm/OptionEditPathFilterTest.php b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Hook/BuildForm/OptionEditPathFilterTest.php new file mode 100644 index 00000000000..da1c11900ec --- /dev/null +++ b/uk.co.compucorp.civicrm.hrcore/tests/phpunit/CRM/HRCore/Hook/BuildForm/OptionEditPathFilterTest.php @@ -0,0 +1,55 @@ +add('text', 'bar'); + $cloneElement = clone $element; + $original->addElement($cloneElement); + + $filter->handle('TestForm', $form); + + $this->assertEquals($original, $form); + } + + public function testOptionEditPathWillNotBeRemovedIfNotLocked() { + civicrm_api3('OptionGroup', 'create', ['name' => 'foo']); + + $filter = new OptionEditPathFilter(); + $form = new CRM_Contact_Form_Contact(); + + $element = $form->add('text', 'bar'); + $editPath = 'civicrm/admin/options/foo'; + $attrKey = 'data-option-edit-path'; + $element->setAttribute($attrKey, $editPath); + + $filter->handle('TestForm', $form); + + $this->assertEquals($editPath, $element->getAttribute($attrKey)); + } + + public function testOptionEditPathWillBeRemovedIfLocked() { + civicrm_api3('OptionGroup', 'create', ['name' => 'bar', 'is_locked' => 1]); + + $filter = new OptionEditPathFilter(); + $form = new CRM_Contact_Form_Contact(); + $element = $form->add('text', 'bar'); + $attrKey = 'data-option-edit-path'; + $element->setAttribute($attrKey, 'civicrm/admin/options/bar'); + + $filter->handle('TestForm', $form); + + $this->assertNull($element->getAttribute($attrKey)); + } + +} From 1b619898be1f6a794937728122f54478c4a00dd1 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Tue, 10 Apr 2018 14:06:46 +0100 Subject: [PATCH 124/203] PHCR-3526: Workaround for PHP warnings The real problem is the civicrm_api3_relationship_type_create function, but as a fix for now we include all data in the update request --- .../CRM/HRCore/Upgrader/Steps/1008.php | 12 ++++++++++-- .../CRM/HRLeaveAndAbsences/Upgrader/Step/1019.php | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1008.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1008.php index ea061c7e4fe..d1229dc0946 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1008.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1008.php @@ -8,13 +8,21 @@ trait CRM_HRCore_Upgrader_Steps_1008 { * @return bool */ public function upgrade_1008() { - civicrm_api3('RelationshipType', 'get', [ + $type = civicrm_api3('RelationshipType', 'get', [ 'sequential' => 1, 'name_a_b' => 'Line Manager is', 'name_b_a' => 'Line Manager', - 'api.RelationshipType.create' => ['id' => '$value.id', 'is_reserved' => 1], ]); + if ($type['count'] != 1) { + return TRUE; + } + + $type = array_shift($type['values']); + $type['is_reserved'] = 1; + + civicrm_api3('RelationshipType', 'create', $type); + return TRUE; } } diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1019.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1019.php index 0df83381d9b..9d5292b2e46 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1019.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1019.php @@ -9,13 +9,21 @@ trait CRM_HRLeaveAndAbsences_Upgrader_Step_1019 { * @return bool */ public function upgrade_1019() { - civicrm_api3('RelationshipType', 'get', [ + $type = civicrm_api3('RelationshipType', 'get', [ 'sequential' => 1, 'name_a_b' => 'has Leave Approved by', 'name_b_a' => 'is Leave Approver of', - 'api.RelationshipType.create' => ['id' => '$value.id', 'is_reserved' => 1], ]); + if ($type['count'] != 1) { + return TRUE; + } + + $type = array_shift($type['values']); + $type['is_reserved'] = 1; + + civicrm_api3('RelationshipType', 'create', $type); + return TRUE; } } From 88def9410b717d9891a004588793d2f84ef4b781 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Tue, 10 Apr 2018 12:59:12 +0100 Subject: [PATCH 125/203] PCHR-3464: Avoid multiple API calls by fetching all locked groups --- .../Hook/BuildForm/OptionEditPathFilter.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Hook/BuildForm/OptionEditPathFilter.php b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Hook/BuildForm/OptionEditPathFilter.php index cdd0cb2db04..1ac33de29ee 100644 --- a/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Hook/BuildForm/OptionEditPathFilter.php +++ b/uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Hook/BuildForm/OptionEditPathFilter.php @@ -3,10 +3,10 @@ class CRM_HRCore_Hook_BuildForm_OptionEditPathFilter { /** - * @var bool[] - * A mapping of option group name to its "is_locked" status + * @var string[] + * An array of locked option group names, indexed by group ID */ - private $optionGroupLockedStatuses = []; + private $lockedOptionGroups = []; /** * Handle the form. Any form that can contain elements referencing an @@ -58,15 +58,13 @@ private function filterOptionEditPaths($form) { * @return bool */ private function isLockedOptionGroup($optionGroupName) { - if (!isset($this->optionGroupLockedStatuses[$optionGroupName])) { - $params = ['return' => 'is_locked', 'name' => $optionGroupName]; - $result = civicrm_api3('OptionGroup', 'get', $params); - $result = array_shift($result['values']); - $isLocked = CRM_Utils_Array::value('is_locked', $result, FALSE); - $this->optionGroupLockedStatuses[$optionGroupName] = (bool) $isLocked; + if (empty($this->lockedOptionGroups)) { + $params = ['return' => 'name', 'is_locked' => 1]; + $result = civicrm_api3('OptionGroup', 'get', $params)['values']; + $this->lockedOptionGroups = array_column($result, 'name', 'id'); } - return $this->optionGroupLockedStatuses[$optionGroupName]; + return in_array($optionGroupName, $this->lockedOptionGroups); } } From b909cd902bed74c58d4f693c67dc5ece11666ff9 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Tue, 10 Apr 2018 18:05:31 +0100 Subject: [PATCH 126/203] PCHR-3162: Resolve merge conflict After an upgrader was added we need to shift the epic upgrader steps up to avoid a conflict. The 1020 upgrader was copied from Tunbola's commit 0dbab999255c051cfcd040036263bc47757140e0 --- .../CRM/HRLeaveAndAbsences/Upgrader.php | 1 + .../HRLeaveAndAbsences/Upgrader/Step/1020.php | 136 +++--------------- .../HRLeaveAndAbsences/Upgrader/Step/1021.php | 127 ++++++++++++++-- .../HRLeaveAndAbsences/Upgrader/Step/1022.php | 22 ++- .../HRLeaveAndAbsences/Upgrader/Step/1023.php | 29 ++-- .../HRLeaveAndAbsences/Upgrader/Step/1024.php | 133 ++--------------- .../HRLeaveAndAbsences/Upgrader/Step/1025.php | 132 +++++++++++++++++ 7 files changed, 304 insertions(+), 276 deletions(-) create mode 100644 uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1025.php diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php index b56f3bb9a64..832872bc809 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php @@ -30,6 +30,7 @@ class CRM_HRLeaveAndAbsences_Upgrader extends CRM_HRLeaveAndAbsences_Upgrader_Ba use CRM_HRLeaveAndAbsences_Upgrader_Step_1022; use CRM_HRLeaveAndAbsences_Upgrader_Step_1023; use CRM_HRLeaveAndAbsences_Upgrader_Step_1024; + use CRM_HRLeaveAndAbsences_Upgrader_Step_1025; /** * A list of directories to be scanned for XML installation files diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php index 681a8c7c034..fabc4e51a89 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1020.php @@ -1,131 +1,27 @@ 'id', 'name' => 'leave_and_absences']; - $parentId = (int) civicrm_api3('Navigation', 'getvalue', $params); - civicrm_api3('Navigation', 'create', ['id' => $parentId, 'weight' => -96]); - - $this->up1020_createNewLinks($parentId); - // we need to flush for new items to be recognized - CRM_Core_PseudoConstant::flush(); - $this->up1020_relabelExistingLinks($parentId); - $this->up1020_addSeparators($parentId); - $this->up1020_updateWeight($parentId); - - return TRUE; - } - - /** - * Creates new entries in the leave submenu - * - * @param int $parentId - */ - private function up1020_createNewLinks($parentId) { - $permission = 'administer leave and absences'; - $optionGroupLinks = [ - 'Sickness Reasons' => 'hrleaveandabsences_sickness_reason', - 'TOIL to be Accrued' => 'hrleaveandabsences_toil_amounts', - 'Work Pattern Change Reasons' => 'hrleaveandabsences_work_pattern_change_reason', - 'Work Pattern Day Equivalents' => 'hrleaveandabsences_leave_days_amounts' - ]; - - foreach ($optionGroupLinks as $itemName => $optionGroup) { - $link = 'civicrm/admin/options/' . $optionGroup . '?reset=1'; - $params = ['url' => $link]; - $this->up1020_createNavItem($itemName, $permission, $parentId, $params); - } - } - - /** - * Relabels some of the existing leave items - * - * @param int $parentId - */ - private function up1020_relabelExistingLinks($parentId) { - $nameToLabelMapping = [ - 'leave_and_absence_types' => ts('Leave Types'), - 'leave_and_absence_periods' => ts('Leave Periods'), - 'leave_and_absence_manage_work_patterns' => ts('Work Patterns'), - 'leave_and_absence_general_settings' => ts('Leave Settings'), - 'leave_and_absences_import' => ts('Import Leave Requests'), - ]; - - foreach ($nameToLabelMapping as $name => $label) { - $params = ['parent_id' => $parentId, 'name' => $name, 'return' => 'id']; - $id = (int) civicrm_api3('Navigation', 'getvalue', $params); - civicrm_api3('Navigation', 'create', ['id' => $id, 'label' => $label]); - } - } - - /** - * Adds separators after certain items in the leave submenu - * - * @param int $parentId - */ - private function up1020_addSeparators($parentId) { - $itemsWithSeparators = [ - 'leave_and_absence_general_settings', - 'Work Pattern Day Equivalents', - ]; - - foreach ($itemsWithSeparators as $name) { - $params = ['parent_id' => $parentId, 'name' => $name, 'return' => 'id']; - $id = (int) civicrm_api3('Navigation', 'getvalue', $params); - civicrm_api3('Navigation', 'create', ['id' => $id, 'has_separator' => 1]); - } - } - - /** - * Sets the weight for the "Import" item so it will appear last - * - * @param int $parentId - */ - private function up1020_updateWeight($parentId) { - $name = 'leave_and_absences_import'; - $params = ['parent_id' => $parentId, 'name' => $name, 'return' => 'id']; - $id = (int) civicrm_api3('Navigation', 'getvalue', $params); - $maxWeight = CRM_Core_BAO_Navigation::calculateWeight($parentId); - civicrm_api3('Navigation', 'create', ['id' => $id, 'weight' => $maxWeight]); - } - - /** - * Creates a navigation menu item using the API - * - * @param string $name - * @param string $permission - * @param int $parentID - * @param array $params - * - * @return array - */ - private function up1020_createNavItem( - $name, - $permission, - $parentID, - $params = [] - ) { - $params = array_merge([ - 'name' => $name, - 'label' => ts($name), - 'permission' => $permission, - 'parent_id' => $parentID, - 'is_active' => 1, - ], $params); - - $existing = civicrm_api3('Navigation', 'get', $params); - - if ($existing['count'] > 0) { - return array_shift($existing['values']); + $result = civicrm_api3('OptionValue', 'get', [ + 'option_group_id' => 'hrleaveandabsences_toil_amounts', + 'name' => 'zero_days', + ]); + + if (empty($result['id'])) { + return TRUE; } - - return civicrm_api3('Navigation', 'create', $params); + + civicrm_api3('OptionValue', 'delete', [ + 'id' => $result['id'] + ]); + + return TRUE; } } - diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php index ab6deb84992..ba6e2d1eb99 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1021.php @@ -3,18 +3,129 @@ trait CRM_HRLeaveAndAbsences_Upgrader_Step_1021 { /** - * Create new option group hrleaveandabsences_work_pattern_change_reason - * with values As per contract, Change in contractual hours and - * Change in contract type. + * Adds links to edit option groups related to leave and absence * * @return bool */ public function upgrade_1021() { - $import = new CRM_Utils_Migrate_Import(); - $extension = 'uk.co.compucorp.civicrm.hrleaveandabsences'; - $file = 'xml/option_groups/work_pattern_change_reason_install.xml'; - - $import->run(CRM_Core_Resources::singleton()->getPath($extension, $file)); + $params = ['return' => 'id', 'name' => 'leave_and_absences']; + $parentId = (int) civicrm_api3('Navigation', 'getvalue', $params); + civicrm_api3('Navigation', 'create', ['id' => $parentId, 'weight' => -96]); + + $this->up1021_createNewLinks($parentId); + // we need to flush for new items to be recognized + CRM_Core_PseudoConstant::flush(); + $this->up1021_relabelExistingLinks($parentId); + $this->up1021_addSeparators($parentId); + $this->up1021_updateWeight($parentId); + return TRUE; } + + /** + * Creates new entries in the leave submenu + * + * @param int $parentId + */ + private function up1021_createNewLinks($parentId) { + $permission = 'administer leave and absences'; + $optionGroupLinks = [ + 'Sickness Reasons' => 'hrleaveandabsences_sickness_reason', + 'TOIL to be Accrued' => 'hrleaveandabsences_toil_amounts', + 'Work Pattern Change Reasons' => 'hrleaveandabsences_work_pattern_change_reason', + 'Work Pattern Day Equivalents' => 'hrleaveandabsences_leave_days_amounts' + ]; + + foreach ($optionGroupLinks as $itemName => $optionGroup) { + $link = 'civicrm/admin/options/' . $optionGroup . '?reset=1'; + $params = ['url' => $link]; + $this->up1021_createNavItem($itemName, $permission, $parentId, $params); + } + } + + /** + * Relabels some of the existing leave items + * + * @param int $parentId + */ + private function up1021_relabelExistingLinks($parentId) { + $nameToLabelMapping = [ + 'leave_and_absence_types' => ts('Leave Types'), + 'leave_and_absence_periods' => ts('Leave Periods'), + 'leave_and_absence_manage_work_patterns' => ts('Work Patterns'), + 'leave_and_absence_general_settings' => ts('Leave Settings'), + 'leave_and_absences_import' => ts('Import Leave Requests'), + ]; + + foreach ($nameToLabelMapping as $name => $label) { + $params = ['parent_id' => $parentId, 'name' => $name, 'return' => 'id']; + $id = (int) civicrm_api3('Navigation', 'getvalue', $params); + civicrm_api3('Navigation', 'create', ['id' => $id, 'label' => $label]); + } + } + + /** + * Adds separators after certain items in the leave submenu + * + * @param int $parentId + */ + private function up1021_addSeparators($parentId) { + $itemsWithSeparators = [ + 'leave_and_absence_general_settings', + 'Work Pattern Day Equivalents', + ]; + + foreach ($itemsWithSeparators as $name) { + $params = ['parent_id' => $parentId, 'name' => $name, 'return' => 'id']; + $id = (int) civicrm_api3('Navigation', 'getvalue', $params); + civicrm_api3('Navigation', 'create', ['id' => $id, 'has_separator' => 1]); + } + } + + /** + * Sets the weight for the "Import" item so it will appear last + * + * @param int $parentId + */ + private function up1021_updateWeight($parentId) { + $name = 'leave_and_absences_import'; + $params = ['parent_id' => $parentId, 'name' => $name, 'return' => 'id']; + $id = (int) civicrm_api3('Navigation', 'getvalue', $params); + $maxWeight = CRM_Core_BAO_Navigation::calculateWeight($parentId); + civicrm_api3('Navigation', 'create', ['id' => $id, 'weight' => $maxWeight]); + } + + /** + * Creates a navigation menu item using the API + * + * @param string $name + * @param string $permission + * @param int $parentID + * @param array $params + * + * @return array + */ + private function up1021_createNavItem( + $name, + $permission, + $parentID, + $params = [] + ) { + $params = array_merge([ + 'name' => $name, + 'label' => ts($name), + 'permission' => $permission, + 'parent_id' => $parentID, + 'is_active' => 1, + ], $params); + + $existing = civicrm_api3('Navigation', 'get', $params); + + if ($existing['count'] > 0) { + return array_shift($existing['values']); + } + + return civicrm_api3('Navigation', 'create', $params); + } } + diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php index d48ecf45232..b71850c1a3f 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php @@ -3,22 +3,18 @@ trait CRM_HRLeaveAndAbsences_Upgrader_Step_1022 { /** - * Default existing work pattern to As per contract (new default) + * Create new option group hrleaveandabsences_work_pattern_change_reason + * with values As per contract, Change in contractual hours and + * Change in contract type. * * @return bool */ - public function upgrade_1022() - { - $query = 'UPDATE civicrm_hrleaveandabsences_contact_work_pattern SET change_reason = - ( - SELECT cov.value FROM civicrm_option_value cov LEFT JOIN civicrm_option_group cog - ON (cog.id = cov.option_group_id) - WHERE cog.name = "hrleaveandabsences_work_pattern_change_reason" - AND cov.is_default = 1 - )'; - - CRM_Core_DAO::executeQuery($query); - + public function upgrade_1022() { + $import = new CRM_Utils_Migrate_Import(); + $extension = 'uk.co.compucorp.civicrm.hrleaveandabsences'; + $file = 'xml/option_groups/work_pattern_change_reason_install.xml'; + + $import->run(CRM_Core_Resources::singleton()->getPath($extension, $file)); return TRUE; } } diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1023.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1023.php index ed00193f50f..3ed180d83b4 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1023.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1023.php @@ -3,25 +3,22 @@ trait CRM_HRLeaveAndAbsences_Upgrader_Step_1023 { /** - * Deletes the 'zero_days' option value of the toil amounts - * option group. + * Default existing work pattern to As per contract (new default) * * @return bool */ - public function upgrade_1023() { - $result = civicrm_api3('OptionValue', 'get', [ - 'option_group_id' => 'hrleaveandabsences_toil_amounts', - 'name' => 'zero_days', - ]); - - if (empty($result['id'])) { - return TRUE; - } - - civicrm_api3('OptionValue', 'delete', [ - 'id' => $result['id'] - ]); - + public function upgrade_1023() + { + $query = 'UPDATE civicrm_hrleaveandabsences_contact_work_pattern SET change_reason = + ( + SELECT cov.value FROM civicrm_option_value cov LEFT JOIN civicrm_option_group cog + ON (cog.id = cov.option_group_id) + WHERE cog.name = "hrleaveandabsences_work_pattern_change_reason" + AND cov.is_default = 1 + )'; + + CRM_Core_DAO::executeQuery($query); + return TRUE; } } diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1024.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1024.php index d66e4832e16..43d72bad06a 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1024.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1024.php @@ -1,132 +1,27 @@ up1024_createLeaveWorkflowOptionGroup($templateName); - - if ($result['count'] > 0) { - $this->up1024_createLeaveWorkflowOptionValue($templateName); - } - - return TRUE; - } - - /** - * Create Leave Message Template Workflow Option Group. - * - * @param string $templateName - * - * @return array - */ - public function up1024_createLeaveWorkflowOptionGroup($templateName) { - $workflow = 'Message Template Workflow for Leave'; - - $result = civicrm_api3('OptionGroup', 'create', [ - 'name' => $templateName, - 'title' => $workflow, - 'description' => $workflow, - 'is_locked' => 1, - 'is_reserved' => 1 + $result = civicrm_api3('OptionValue', 'get', [ + 'option_group_id' => 'hrleaveandabsences_toil_amounts', + 'name' => 'zero_days', ]); - - // Flush constant because the option group id is cached and will not be - // available for linking newly created option group value - CRM_Core_PseudoConstant::flush(); - - return $result; - } - - /** - * Create Leave Message Template Workflow Option Values. - * - * @param string $templateName - */ - public function up1024_createLeaveWorkflowOptionValue($templateName) { - $optionValues = [ - [ - 'option_group_id' => $templateName, - 'label' => 'CiviHR Leave Request Notification', - 'name' => 'civihr_leave_request_notification', - ], - [ - 'option_group_id' => $templateName, - 'label' => 'CiviHR TOIL Request Notification', - 'name' => 'civihr_toil_request_notification', - ], - [ - 'option_group_id' => $templateName, - 'label' => 'CiviHR Sickness Record Notification', - 'name' => 'civihr_sickness_record_notification', - ] - ]; - - foreach ($optionValues as $optionValue) { - $result = civicrm_api3('OptionValue', 'create', $optionValue); - if ($result['count'] > 0) { - $this->up1024_updateLeaveMsgTemplate( - $result['id'], - $optionValue['label'] - ); - } + + if (empty($result['id'])) { + return TRUE; } - } - - /** - * Update message template workflow id for option group msg_tpl_workflow_leave - * - * @param int $workflowId - * @param string $msgLabel - */ - public function up1024_updateLeaveMsgTemplate($workflowId, $msgLabel) { - $result = civicrm_api3('MessageTemplate', 'get', [ - 'sequential' => 1, - 'return' => ['id', 'msg_title', 'msg_subject', 'msg_text', 'msg_html'], - 'msg_title' => $msgLabel, + + civicrm_api3('OptionValue', 'delete', [ + 'id' => $result['id'] ]); - if ($result['count'] == 1) { - // update existing record as default with new workflow id - civicrm_api3('MessageTemplate', 'create', [ - 'workflow_id' => $workflowId, - 'is_default' => 1, - 'is_reserved' => 0, - 'id' => $result['id'], - ]); - - // create the reserved version of template - $this->duplicateTemplateAsReserved($result['values'][0], $workflowId); - } else { - foreach ($result['values'] as $value) { - civicrm_api3('MessageTemplate', 'create', [ - 'workflow_id' => $workflowId, - 'id' => $value['id'], - ]); - } - } - } - - /** - * Duplicate an existing template and set is_reserved true - * - * @param array $template - * @param int $workflowId - */ - public function duplicateTemplateAsReserved($template, $workflowId) { - $newTemplate = [ - 'msg_title' => $template['msg_title'], - 'msg_subject' => $template['msg_subject'], - 'msg_text' => $template['msg_text'], - 'msg_html' => $template['msg_html'], - 'workflow_id' => $workflowId, - 'is_default' => 0, - 'is_reserved' => 1 - ]; - - civicrm_api3('MessageTemplate', 'create', $newTemplate); + + return TRUE; } } diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1025.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1025.php new file mode 100644 index 00000000000..97d1dc0a70a --- /dev/null +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1025.php @@ -0,0 +1,132 @@ +up1025_createLeaveWorkflowOptionGroup($templateName); + + if ($result['count'] > 0) { + $this->up1025_createLeaveWorkflowOptionValue($templateName); + } + + return TRUE; + } + + /** + * Create Leave Message Template Workflow Option Group. + * + * @param string $templateName + * + * @return array + */ + public function up1025_createLeaveWorkflowOptionGroup($templateName) { + $workflow = 'Message Template Workflow for Leave'; + + $result = civicrm_api3('OptionGroup', 'create', [ + 'name' => $templateName, + 'title' => $workflow, + 'description' => $workflow, + 'is_locked' => 1, + 'is_reserved' => 1 + ]); + + // Flush constant because the option group id is cached and will not be + // available for linking newly created option group value + CRM_Core_PseudoConstant::flush(); + + return $result; + } + + /** + * Create Leave Message Template Workflow Option Values. + * + * @param string $templateName + */ + public function up1025_createLeaveWorkflowOptionValue($templateName) { + $optionValues = [ + [ + 'option_group_id' => $templateName, + 'label' => 'CiviHR Leave Request Notification', + 'name' => 'civihr_leave_request_notification', + ], + [ + 'option_group_id' => $templateName, + 'label' => 'CiviHR TOIL Request Notification', + 'name' => 'civihr_toil_request_notification', + ], + [ + 'option_group_id' => $templateName, + 'label' => 'CiviHR Sickness Record Notification', + 'name' => 'civihr_sickness_record_notification', + ] + ]; + + foreach ($optionValues as $optionValue) { + $result = civicrm_api3('OptionValue', 'create', $optionValue); + if ($result['count'] > 0) { + $this->up1025_updateLeaveMsgTemplate( + $result['id'], + $optionValue['label'] + ); + } + } + } + + /** + * Update message template workflow id for option group msg_tpl_workflow_leave + * + * @param int $workflowId + * @param string $msgLabel + */ + public function up1025_updateLeaveMsgTemplate($workflowId, $msgLabel) { + $result = civicrm_api3('MessageTemplate', 'get', [ + 'sequential' => 1, + 'return' => ['id', 'msg_title', 'msg_subject', 'msg_text', 'msg_html'], + 'msg_title' => $msgLabel, + ]); + if ($result['count'] == 1) { + // update existing record as default with new workflow id + civicrm_api3('MessageTemplate', 'create', [ + 'workflow_id' => $workflowId, + 'is_default' => 1, + 'is_reserved' => 0, + 'id' => $result['id'], + ]); + + // create the reserved version of template + $this->duplicateTemplateAsReserved($result['values'][0], $workflowId); + } else { + foreach ($result['values'] as $value) { + civicrm_api3('MessageTemplate', 'create', [ + 'workflow_id' => $workflowId, + 'id' => $value['id'], + ]); + } + } + } + + /** + * Duplicate an existing template and set is_reserved true + * + * @param array $template + * @param int $workflowId + */ + public function duplicateTemplateAsReserved($template, $workflowId) { + $newTemplate = [ + 'msg_title' => $template['msg_title'], + 'msg_subject' => $template['msg_subject'], + 'msg_text' => $template['msg_text'], + 'msg_html' => $template['msg_html'], + 'workflow_id' => $workflowId, + 'is_default' => 0, + 'is_reserved' => 1 + ]; + + civicrm_api3('MessageTemplate', 'create', $newTemplate); + } +} From 6c5a43903bc3a936dd9b0bded74d3c2228ffbb23 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Wed, 11 Apr 2018 15:11:25 +0100 Subject: [PATCH 127/203] PCHR-3525: Update TOIL duration on absence type change --- .../js/angular/dist/absence-tab.min.js | 8 +-- .../js/angular/dist/admin-dashboard.min.js | 10 ++-- .../js/angular/dist/manager-leave.min.js | 10 ++-- .../js/angular/dist/my-leave.min.js | 8 +-- .../request-modal-details-toil.controller.js | 30 +++++++++- ...uest-modal-details-toil.controller.spec.js | 59 +++++++++++++++++-- 6 files changed, 100 insertions(+), 25 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js index d6b36fe1374..a2ae44384c7 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js @@ -1,5 +1,5 @@ -!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,o){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:t(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,o,s,i){return t.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return s.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,o,s){return t.debug("WorkPatternAPI.getCalendar",n,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,o){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,o,s,i){function r(t,n){return u().then(function(a){var o=this.days[c(t).valueOf()];return!!o&&e.find(a,function(e){return e.name===n}).value===o.type}.bind(this))}function c(e){return t(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[c(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,o){return t.debug("Calendar"),n.extend({get:function(n,s,i,r){return t.debug("Calendar.get"),a.getCalendar(n,s,i,r).then(function(t){var a=t.values.map(function(e){return o.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function o(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,o,s){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return o.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",t,n,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t,n,o,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var i=a.defer();t&&n||i.reject("contact_id and period_id are mandatory");var r={contact_id:t,period_id:n,statuses:o?{IN:o}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",r,!1).then(function(e){i.resolve(e.values)}),i.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?o.reject(t(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(t){return s.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,o&&(i.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return r.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),n.all(t)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(s.permissions.admin.administer).then(function(t){return t?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,o,s,i){return n.all(this.processFilters(e),t,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,o){return n.balanceChangeByAbsenceType(e,t,a,o)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/instances/work-pattern.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("WorkPatternInstance",["$log","ModelInstance",function(e,t){return e.debug("WorkPatternInstance"),t.extend({})}])}),define("leave-absences/shared/models/work-pattern.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/work-pattern.instance"],function(e,t){"use strict";t.factory("WorkPattern",["$log","Model","WorkPatternAPI","WorkPatternInstance",function(t,n,a,o){return t.debug("WorkPattern"),n.extend({assignWorkPattern:function(e,t,n,o,s,i){return a.assignWorkPattern(e,t,n,o,s,i)},default:function(){return a.get({is_default:!0}).then(function(t){return o.init(e.first(t),!0)})},unassignWorkPattern:function(e){return a.unassignWorkPattern(e)},workPatternsOf:function(e,t,n){return a.workPatternsOf(e,t,n).then(function(e){return e.map(function(e){return o.init(e,!0)})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function u(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?c():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return o.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):i.all()}function m(e){return"me"===e?o.leaveManagees(v.contactId):"unassigned"===e?o.leaveManagees(void 0,{unassigned:!0}):o.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){r.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,u()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:i.contactId}).leaveManagees().then(function(e){i.lookupContacts=e}).then(o)}}}function o(){return t.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:i.filters.userSettings.department?i.filters.userSettings.department.value:null,level_type:i.filters.userSettings.level_type?i.filters.userSettings.level_type.value:null,location:i.filters.userSettings.location?i.filters.userSettings.location.value:null,region:i.filters.userSettings.region?i.filters.userSettings.region.value:null,id:{IN:i.filters.userSettings.contact?[i.filters.userSettings.contact.id]:i.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var i;return{init:function(e){return i=e,i.showContactName=!0,i.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function o(a,o,s,i,r,c,u,l,d,m){function f(){for(var e=[],t=n(M.selectedPeriod.start_date).clone().startOf("month"),a=n(M.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(R(t)),t.add(1,"month");M.months=e}function p(){i.$new().$watch(function(){return M.selectedMonths},function(t,n){null===n||e.equals(t,n)||I()})}function h(e){M.injectMonths=!0,S("injected").then(function(){I(e)}).then(function(){M.loading.calendar=!1})}function v(){L=a("LeaveCalendar"+t.capitalize(k)+"Controller").init(M)}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function g(){return c.all().then(function(e){M.absencePeriods=t.sortBy(e,"start_date"),M.selectedPeriod=t.find(M.absencePeriods,function(e){return!!e.current})}).then(f).then(w)}function _(){return u.all().then(u.loadCalculationUnits)}function y(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return L.loadContacts().then(function(e){M.contacts=e})}function C(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){M.filters.optionValues.regions=e.hrjc_region,M.filters.optionValues.locations=e.hrjc_location,M.filters.optionValues.levelTypes=e.hrjc_level_type,M.filters.optionValues.departments=e.hrjc_department})}function D(){return l.all()}function T(){return o.all([_(),D(),y()]).then(function(e){M.supportData.absenceTypes=e[0],M.supportData.publicHolidays=e[1],M.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,M.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,M.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,M.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function P(){var e=o.resolve();return M.injectMonths&&(e=S("destroyed"),M.injectMonths=!1),e}function R(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function A(e){e=t.includes(["contacts","period"],e)?e:"period",o.resolve().then(function(){M.loading.calendar=!0}).then(P).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function I(e){var n=M.selectedMonths.length?M.months.filter(function(e){return t.includes(M.selectedMonths,e.index)}):M.months;i.$emit("LeaveCalendar::showMonths",n,!!e)}function w(){M.selectedMonths=[n().month()]}function O(){return M.roleOverride?o.resolve().then(function(){k=M.roleOverride}):o.all([m(r.permissions.admin.administer),m(r.permissions.ssp.manage)]).then(function(e){k=e[0]?"admin":e[1]?"manager":"staff"})}function S(e){return o(function(n){var a=0,o=i.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===M.months.length&&(o(),n())})})}s.debug("Component: leave-calendar");var L,k,M=this;M.absencePeriods=[],M.contacts=[],M.contactIdsToReduceTo=null,M.injectMonths=!1,M.months=[],M.selectedMonths=null,M.selectedPeriod=null,M.showContactName=!1,M.showFilters=!1,M.supportData={},M.loading={calendar:!0,page:!0},M.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},M.labelPeriod=b,M.refresh=A,function(){O().then(p).then(v).then(P).then(g).then(function(){return o.all([q(),T()])}).then(function(){return M.showFilters?C():t.noop}).then(function(){h()}).then(function(){M.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",o]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,o){"use strict";function s(){y.calculationUnit=i(y.supportData.calculationUnits,"value",b.calculation_unit)}function i(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function r(){var e,n;return n=t(y.contactData.leaveRequest.from_date).isSame(y.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+y.calculationUnit.name+"-on-"+e+"-tooltip"}function c(){b=i(y.supportData.absenceTypes,"id",y.contactData.leaveRequest.type_id),y.contactData.leaveRequest["type_id.title"]=b.title}function u(){"days"===y.calculationUnit.name&&(g=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.from_date_type),_=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.to_date_type),y.contactData.leaveRequest["from_date_type.label"]=g.label,y.contactData.leaveRequest["to_date_type.label"]=_.label)}function l(e,t,n,a,s){e.stopPropagation(),o.openModal(t,n,a,s)}function d(){y.dates.from=new Date(y.contactData.leaveRequest.from_date),y.dates.to=new Date(y.contactData.leaveRequest.to_date)}function m(){y.contactData.isAccruedTOIL?y.label="AT":"days"===y.calculationUnit.name?f():p()}function f(){y.label=y.contactData.isAM?"AM":y.contactData.isPM?"PM":""}function p(){var e=t(y.contactData.leaveRequest.from_date).isSame(y.date,"day"),n=t(y.contactData.leaveRequest.to_date).isSame(y.date,"day");y.label=e?t(y.contactData.leaveRequest.from_date).format("HH:mm"):n?t(y.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){y.tooltipTemplate=y.contactData.isAccruedTOIL?"accrued-toil-tooltip":r()}function v(){a.$watch("day.contactData.leaveRequest",function(){y.contactData&&y.contactData.leaveRequest&&(c(),s(),u(),m(),d(),h()) -})}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(e){_([e]),U(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return j[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){L(e),U(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=P(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){F.push(o.$on("LeaveCalendar::showMonths",$)),F.push(r.subscribe("LeaveRequest::new",u)),F.push(r.subscribe("LeaveRequest::edit",B)),F.push(r.subscribe("LeaveRequest::updatedByManager",B)),F.push(r.subscribe("LeaveRequest::delete",h)),F.push(r.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function D(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function T(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function P(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function R(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function A(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function I(){return[A(c.statusNames.approved),A(c.statusNames.adminApproved),A(c.statusNames.awaitingApproval),A(c.statusNames.moreInformationRequired)]}function w(){return H.month.loading=!0,a.all([S(),O()]).then(b).then(x).then(function(){N=!0}).then(function(){H.month.loading=!1})}function O(){return i.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:I()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function S(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){j=e.indexBy(t,"contact_id")})}function L(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function k(){o.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function M(t,n,o){var s,i;return t.contactsData[n]=t.contactsData[n]||{},i=m(n),s=!0===o?a.resolve():a.all([i.isWeekend(p(t.date)),i.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:D(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?T(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function x(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return M(e,t.id)}))}))}function $(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!N)&&w())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=R(e);t&&(h(t),-1!==I().indexOf(e.status_id)&&u(e))}function U(e){return a.all(P(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],j={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=k,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,i,r,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(i.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=D[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&r.publish("ManagerBadge:: Update Count"),r.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(D,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:D[e].label,isDirectAction:D[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,D={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return r.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,c.serverDateFormat).toDate()}function h(e){return t(e).format(c.serverDateFormat)}function v(e){var t;return i.resolve().then(function(){F(e),"from"===e&&N(),S("hours")&&(_(e),"from"!==e||te.uiOptions.multipleDays||_("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return i.reject("Please change date as it is not in any absence period")}).then(W).then(function(){if(t)return x()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(V(),!t)return E();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(P).finally(y)}function b(){return V(),E()}function g(){return te.uiOptions.toDate=null,F("to"),i.resolve().then(V).then(te.setDaysSelectionModeExtended).then(y).then(!te.uiOptions.multipleDays&&E)}function _(e){te.uiOptions.times[e].loading=!0}function y(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,S("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function C(){return te.request?te.request.request_type:te.leaveType||null}function D(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(j).catch(P)}function P(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function R(){return te.isMode("create")||te.forceRecalculateBalanceChange?E():T()}function A(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():i.resolve()}function I(){ee.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){Q()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){J(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",E))}function w(){te.isMode("edit")&&(te.isLeaveStatus(c.statusNames.approved)||te.isLeaveStatus(c.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function O(){o.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(K(e),V()))})}function S(e){return te.selectedAbsenceType.calculation_unit_name===e}function L(e){return te.request.request_type===e}function k(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function M(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function x(){return u.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function $(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function E(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(j).catch(P).finally(function(){te.loading.balanceChange=!1})):i.resolve()}function B(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function U(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),V(),z()}function j(e){te.balance.change=e,te.request.balance_change=e.amount,f(),B(),te.loading.balanceChange=!1}function W(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function H(){return!te.isMode("create")&&U()||te.isMode("create")&&(L("sickness")||S("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,i.resolve().then(te.setDaysSelectionModeExtended)}function G(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function Y(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function V(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(S("hours")||L("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function X(){e.forEach(ee,function(e){e()})}function Q(){var e,t=te.selectedAbsenceType.calculation_unit_name;return Y(),e=t!==te.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&H).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&V).then(y).then(E)}function J(e){return te.absenceTypes=e,Y(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),G(),E()}function K(e){var t=D(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(D(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(D(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=c.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:$},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:r.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=b,te.daysSelectionModeChangeHandler=g,te.disableAndShowLoadingTimeInput=_,te.getMomentDateWithGivenTime=D,te.handleError=P,te.isCalculationUnit=S,te.isLeaveType=L,te.isNotWorkingDay=k,te.performBalanceChangeCalculation=E,te.setRequestDateTimesAndDateTypes=V,te.updateEndTimeInputMinTime=K,te.$onDestroy=X,function(){n("RequestModalDetails"+e.capitalize(C(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",te),I(),te.initChildController().then(function(){return i.all([x(),M()])}).then(!te.isMode("create")&&A).then(H).then(function(){if(!te.isMode("create"))return i.resolve().then(te.initTimesExtended).then(V)}).then(!te.isMode("create")&&W).then(w).then(G).then(R).then(O).then(!te.isMode("view")&&te.initWatchersExtended).catch(P).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l){function d(){return O.fileUploader&&O.fileUploader.queue.length>0}function m(){return O.getFilesAmount()0?A.map(function(e){return e.label}).join(", "):""}function q(){return O.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(A.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){w[e.label]=t})})).catch(function(){w=null})}function D(){return c.valuesOf("safe_file_extension").then(function(e){A=e})}function T(e){return!e.attachment_id||O.canManage}function P(){e.forEach(I,function(e){e()})}function R(e,t){O.fileUploader.queue&&O.fileUploader.queue.length>0?O.fileUploader.uploadAll({entityID:O.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var A=[],I=[],w={},O=Object.create(this);return O.filesLoaded=!1,O.fileUploader=null,O.today=Date.now(),O.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",O.userDateFormat=i.DATE_FORMAT,O.$onDestroy=P,O.canRemoveAttachment=T,O.canSubmit=d,O.canUploadMore=m,O.formatDateTime=f,O.getAuthorName=p,O.getFilesAmount=h,O.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",O),g(),a.all([D(),q()]).then(_).finally(function(){O.filesLoaded=!0})}(),O}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,o){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],s.openLeavePopup=a,function(){o=n.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,o,s,i,r,c,u,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var t=j[e.status];t?t(e.leaveRequest):W.refresh()}function b(t){t.dataIndex=e.indexBy(t.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return i.all().then(i.loadCalculationUnits).then(function(t){W.absenceTypes=t,W.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return A("approved",{status_id:F(m.statusNames.approved)})}function C(){return n.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function D(){return r.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(t){var n=e.find(W.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function T(){return r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return M(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function P(){return n.all([r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),R({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:M(e[0]),expiredTOILS:x(e[1].list)})}).then(function(t){W.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function R(t){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function A(e,t){return R(t).then(function(t){W.sections[e].data=t.list})}function I(){return n.all(Object.values(W.sections).filter(function(e){return e.open}).map(L))}function w(){return A("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function O(){return A("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function S(){return A("holidays",{public_holiday:!0})}function L(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function k(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){W.leaveRequestStatuses=e.indexBy(t,"value")})}function M(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(W.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function x(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function $(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(W.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],B(t,a))})}function B(e,t){var n=W.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function U(){W.loading.content=!0,n.all([D(),C()]).then(function(){W.loading.content=!1}).then(function(){return n.all([I(),h()])})}function N(e){var t=W.sections[e];t.open=!t.open,t.open&&!t.data.length&&L(t)}function F(t){return e.find(W.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var j={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:T},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:P},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w}},W.labelPeriod=g,W.refresh=U,W.toggleSection=N,function(){n.all([k(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return n.all([D(),C()])}).then(function(){W.loading.content=!1}),$()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report", -controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function u(){var e=i.request,t=!!e.from_date&&!!e.to_date,n=i.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return i.canCalculateChange()}function d(t,n){var a=i.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);i.uiOptions.multipleDays||("from"===t&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=i.convertDateToServerFormat(t),r.isPublicHoliday(t).then(function(n){return n?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,i.requestDayTypes).then(function(t){return t.length?t:i.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return R(n,e),e})):o.reject([])}function f(e,n){return e=t(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return o.resolve()}function v(){return C(i.uiOptions.fromDate,"from").then(function(){return C(i.uiOptions.toDate,"to")})}function b(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,t){i.isCalculationUnit("days")||+e==+t||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function g(e){var n=t(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),i.uiOptions.times[e].time=n}function _(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],t=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(T)).then(function(){["from","to"].forEach(function(e){g(e),I(e),t[e].amount=Math.min(i.request[e+"_date_amount"],t[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function y(){["from","to"].forEach(function(e){b(e),q(e)})}function q(e){s.$watch(function(){return i.uiOptions.times[e].time},function(t,n){i.isCalculationUnit("days")||t===n||(i.setRequestDateTimesAndDateTypes(),t&&I(e,!0))})}function C(e,t){return m(e,t).then(function(){i.loading[t+"DayTypes"]=!1})}function D(e){return C(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return T(e).then(function(){I(e,!0)})})}function T(e){var t=i.uiOptions[e+"Date"],n=!i.uiOptions.multipleDays;return t?i.request.getWorkDayForDate(i.convertDateToServerFormat(t)).then(function(t){S[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return S[e]={},i.handleError(t)}).finally(function(){n&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(t){var n=i.uiOptions.times[t];i["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function R(t,n){var a="request"+e.startCase(t)+"DayTypes";i[a]=n,i.isMode("create")&&(i.request[t+"_date_type"]=i[a][0].value)}function A(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),T("from").then(function(){I("from",!0)})):o.resolve()}function I(e,t){var n=i.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,c=S[a].number_of_hours?p(s,r).toString():"0";o.maxAmount=c,t&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function O(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?T("from").then(function(){I("from",!0)}):o.resolve()}var S={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=c,i.canCalculateChange=u,i.canSubmit=l,i.initChildController=h,i.initDayTypesExtended=v,i.initTimesExtended=_,i.initWatchersExtended=y,i.onAbsenceTypeUpdateExtended=O,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=A}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function i(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function r(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=i,s.initChildController=r,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=t.duration(t(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,t=!c.uiOptions.multipleDays&&!!c.request.from_date,n=t||e,a=U.from_date!==c.request.from_date||U.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&n&&F.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,t=c.request;return b({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function b(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&F.hasExpirationFromAdminSettings,t=F.hasPreviousExpirationDate,n=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=n&&(a||e||t)}function _(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function y(){return F.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){F.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",y().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function D(){o.$watch(function(){return c.request.toil_to_accrue},function(e,t){+e!=+t&&c.performBalanceChangeCalculation()})}function T(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,t){c.isCalculationUnit("hours")&&e!==t&&(c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function P(){var e=c.uiOptions.times;e.from.time=t(c.request.from_date).format("HH:mm"),e.to.time=t(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,t){e!==t&&(c.setRequestDateTimesAndDateTypes(),E(),l(),L())})})}function A(){c.isMode("view")||(D(),T(),R())}function I(t){return i.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){c.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function w(){return l(),L(),E()}function O(){return M(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),N?N=!1:L(),E()}function S(e){c.uiOptions.times[e].time=""}function L(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function k(){U=e.cloneDeep(c.request.attributes())}function M(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function x(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){I(!1)})}function $(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function E(){return f()?d().catch(a.resolve):a.resolve()}function B(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var U,N=!c.isMode("create"),F={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=P,c.initWatchersExtended=A,c.onDateChangeExtended=w,c.openToilInDaysAccrualOptionsEditor=x,c.resetUIInputsExtended=S,c.setDaysSelectionModeExtended=O,c.updateExpiryDate=B,function(){k(),M(),$(),!c.isMode("create")&&_()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,D){function T(e){"days"===xe.selectedAbsenceType.calculation_unit_name?delete xe.request[e+"_date_amount"]:delete xe.request[e+"_date_type"]}function P(){["from","to"].forEach(T)}function R(){var e=xe.requestStatuses[y.statusNames.awaitingApproval].value;we.status_id===e&&e!==xe.request.status_id&&d.publish("ManagerBadge:: Update Count")}function A(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!xe.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function O(){var e=A();return xe.isMode("edit")&&(e=e&&(G()||I())),xe.canManage&&xe.requestStatuses&&(e=e&&!!xe.getStatusFromValue(xe.newStatusOnSave)),(e=e&&!!xe.period.id)&&!xe.isMode("view")}function S(){xe.isSelfRecord?xe.request.status_id=xe.requestStatuses[y.statusNames.awaitingApproval].value:xe.canManage&&(xe.request.status_id=xe.newStatusOnSave||xe.request.status_id)}function L(){if(xe.isMode("edit")&&!xe.isRole("staff")&&"toil"!==F())return xe.request.calculateBalanceChange(xe.selectedAbsenceType.calculation_unit_name).then(function(e){if(+xe.balance.change.amount!=+e.amount)return D.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function k(){xe.errors=[]}function M(){return xe.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function x(){ee()&&!xe.isRole("staff")&&(xe.request.change_balance=!0)}function $(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return xe.request.delete().then(function(){xe.dismissModal(),d.publish("LeaveRequest::delete",xe.request)})}})}function E(){r.dismiss({$value:"cancel"})}function B(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return N(xe.getStatusFromValue(xe.request.status_id).name)}function N(e){return n.map(Ae[e],function(e){return xe.requestStatuses[e]})}function F(){return xe.request?xe.request.request_type:xe.leaveType||null}function j(){return!xe.request||e.equals({},xe.requestStatuses)?[]:xe.request.status_id?U():N("none")}function W(e){return n.find(xe.requestStatuses,function(t){return t.value===e})}function H(e){xe.errors=n.isArray(e)?e:[e],xe.loading.absenceTypes=!1,xe.submitting=!1}function G(){return!e.equals(we,xe.request.attributes())||xe.canManage&&xe.newStatusOnSave}function Y(){return xe.postContactSelection=!0,xe.staffMemberSelectionComplete=!1,xe.request.contact_id?o.resolve().then(re).then(ce).then(he).then(be).then(Z).then(z).then(xe.isMode("edit")?ge:n.noop).then(function(){xe.postContactSelection=!1,xe.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Le)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Ae.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Ae.awaiting_approval=e,Ae.more_information_required=e,Ae.rejected=e,Ae.approved=e,Ae.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return xe.canManage?f.find(xe.request.contact_id).then(function(e){xe.contactName=e.display_name}):o.resolve()}function X(){Oe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",xe.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Ie++})),i.$on("$destroy",De),i.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function Q(){var e,t;xe.request=xe.leaveRequest||null,e=F(),t=xe.initRequestAttributes(),"leave"===e?xe.request=_.init(t):"sickness"===e?xe.request=q.init(t):"toil"===e&&(xe.request=C.init(t))}function J(){var e={};return xe.request?e=xe.request.attributes():xe.canManage||(e={contact_id:Se}),e}function K(){if(ke="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(ke="admin")}).then(function(){return"staff"===ke&&c(y.permissions.ssp.manage).then(function(e){e&&(ke="manager")})}).finally(function(){xe.canManage=xe.isRole("manager")||xe.isRole("admin")})}function Z(){(xe.isRole("admin")||xe.isMode("create")&&xe.isRole("manager"))&&(xe.newStatusOnSave=xe.requestStatuses[y.statusNames.approved].value)}function ee(){return!xe.request.status_id||!n.includes(["cancelled","rejected"],W(xe.request.status_id).name)}function te(e){var t=xe.getStatusFromValue(xe.request.status_id);return!!t&&t.name===e}function ne(e){return xe.request&&xe.request.request_type===e}function ae(e){return xe.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return ke===e}function ie(){return h.all().then(function(e){xe.absencePeriods=e})}function re(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Re={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return xe.loading.entitlements=!0,b.all({contact_id:xe.request.contact_id,period_id:xe.period.id,type_id:{IN:Re.ids}},!0).finally(function(){xe.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Se=e.contactId})}function le(){return xe.selectedContactId?f.find(xe.selectedContactId).then(function(e){xe.managedContacts=[e]}):xe.isRole("admin")?f.all().then(function(e){xe.managedContacts=n.remove(e.list,function(e){return e.id!==Se})}):f.find(Se).then(function(e){return e.leaveManagees()}).then(function(e){xe.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){xe.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){R(),d.publish(e,xe.request),xe.errors=[],xe.dismissModal()}function pe(){["from","to"].forEach(function(e){xe.request[e+"_date"]=we[e+"_date"]})}function he(e){if(xe.absenceTypes=me(Re.types,e),!xe.absenceTypes.length)return o.reject(Le)}function ve(){xe.period=n.find(xe.absencePeriods,function(e){return xe.isMode("create")?e.current:oe(xe.request,e)})}function be(){xe.isMode("create")?(xe.selectedAbsenceType=xe.absenceTypes[0],xe.request.type_id=xe.selectedAbsenceType.id):xe.selectedAbsenceType=n.find(xe.absenceTypes,function(e){return e.id===xe.request.type_id})}function ge(){we=e.copy(xe.request.attributes())}function _e(){var e;xe.request.id?(e=[xe.requestStatuses[y.statusNames.approved].value,xe.requestStatuses[y.statusNames.adminApproved].value,xe.requestStatuses[y.statusNames.rejected].value,xe.requestStatuses[y.statusNames.cancelled].value],xe.mode="edit",xe.isRole("staff")&&e.indexOf(xe.request.status_id)>-1&&(xe.mode="view")):xe.mode="create"}function ye(){var e=xe.request.status_id;if(!xe.isMode("view")&&!xe.submitting)return xe.submitting=!0,S(),P(),xe.request.isValid().then(ee()&&L).then(x).then(!xe.request.change_balance&&pe).then(qe).then(function(){return xe.isMode("edit")?Pe():M()}).catch(function(t){xe.request.status_id=e,t&&H(t)}).finally(function(){xe.submitting=!1})}function qe(){return o.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===Ie&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return Ie>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function De(){Oe.forEach(function(e){e()})}function Te(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Pe(){return xe.request.update().then(Ce).then(function(){xe.isRole("manager")?fe("LeaveRequest::updatedByManager"):(xe.isRole("staff")||xe.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Re,Ae={},Ie=0,we={},Oe=[],Se="",Le="No entitlement",ke="",Me=[],xe=n.assign(this,m);xe.absencePeriods=[],xe.absenceTypes=[],xe.canManage=!1,xe.contactName=null,xe.errors=[],xe.loading={absenceTypes:!0,entitlements:!0},xe.managedContacts=[],xe.mode="",xe.newStatusOnSave=null,xe.period={},xe.postContactSelection=!1,xe.requestStatuses={},xe.selectedAbsenceType={},xe.staffMemberSelectionComplete=!1,xe.submitting=!1,xe.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},xe.canChangeAbsenceType=w,xe.canSubmit=O,xe.closeAlert=k,xe.deleteLeaveRequest=$,xe.dismissModal=E,xe.getStatuses=j,xe.getStatusFromValue=W,xe.initAfterContactSelection=Y,xe.initRequestAttributes=J,xe.isLeaveStatus=te,xe.isLeaveType=ne,xe.isMode=ae,xe.isRole=se,xe.submit=ye,xe.updateAbsenceType=Te,function(){xe.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),ie(),de()]).then(Q).then(_e).then(ve).then(function(){return xe.canManage&&!xe.isMode("edit")&&le()}).then(function(){if(xe.selectedContactId&&(xe.request.contact_id=xe.selectedContactId),xe.request.contact_id)return xe.initAfterContactSelection()}).catch(H).finally(function(){xe.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,i,r,c){function u(e){return r.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,i,r){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:i,forceRecalculateBalanceChange:r}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,i){function r(e){l.errorMessage=e}function c(){return i.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrjc_revision_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,i.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(r).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrjc_revision_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){ -var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(),g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){r.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){i.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i){function r(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,i){n=o.entitlements.slice(0,i),a=e.entitlements.slice(i+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,i;return s=e.indexBy(n,"entitlement_id.type_id"),i=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:i}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t];e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,i){o.comment&&(t=s.concat(o).concat(i),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(r).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,i,r,c,u,l,d){function m(){D.absencePeriods=t.chain(D.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){D.absenceTypes=t.filter(D.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:D.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:D.contactId,returnUrl:n})}function h(){return c.all().then(function(e){D.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:D.contactId}).then(function(e){q=e})}function g(e){i.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=D.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){D.absencePeriods=t.map(D.absencePeriods,function(e){var n=t.map(D.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

    Last updated:
    By: "+e.author_name+"
    Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
    ";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],D=this;D.absencePeriods=[],D.loading={absencePeriods:!0},D.getEditEntitlementsPageURL=p,D.openAnnualEntitlementChangeLog=g,D.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){D.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i,r){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return i.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){r.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); +!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,o){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:t(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,o,s,i){return t.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return s.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,o,s){return t.debug("WorkPatternAPI.getCalendar",n,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,o){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,o,s,i){function r(t,n){return u().then(function(a){var o=this.days[c(t).valueOf()];return!!o&&e.find(a,function(e){return e.name===n}).value===o.type}.bind(this))}function c(e){return t(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[c(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,o){return t.debug("Calendar"),n.extend({get:function(n,s,i,r){return t.debug("Calendar.get"),a.getCalendar(n,s,i,r).then(function(t){var a=t.values.map(function(e){return o.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function o(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,o,s){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return o.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",t,n,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t,n,o,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var i=a.defer();t&&n||i.reject("contact_id and period_id are mandatory");var r={contact_id:t,period_id:n,statuses:o?{IN:o}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",r,!1).then(function(e){i.resolve(e.values)}),i.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?o.reject(t(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(t){return s.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,o&&(i.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return r.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),n.all(t)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(s.permissions.admin.administer).then(function(t){return t?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,o,s,i){return n.all(this.processFilters(e),t,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,o){return n.balanceChangeByAbsenceType(e,t,a,o)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/instances/work-pattern.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("WorkPatternInstance",["$log","ModelInstance",function(e,t){return e.debug("WorkPatternInstance"),t.extend({})}])}),define("leave-absences/shared/models/work-pattern.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/work-pattern.instance"],function(e,t){"use strict";t.factory("WorkPattern",["$log","Model","WorkPatternAPI","WorkPatternInstance",function(t,n,a,o){return t.debug("WorkPattern"),n.extend({assignWorkPattern:function(e,t,n,o,s,i){return a.assignWorkPattern(e,t,n,o,s,i)},default:function(){return a.get({is_default:!0}).then(function(t){return o.init(e.first(t),!0)})},unassignWorkPattern:function(e){return a.unassignWorkPattern(e)},workPatternsOf:function(e,t,n){return a.workPatternsOf(e,t,n).then(function(e){return e.map(function(e){return o.init(e,!0)})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function u(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?c():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return o.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):i.all()}function m(e){return"me"===e?o.leaveManagees(v.contactId):"unassigned"===e?o.leaveManagees(void 0,{unassigned:!0}):o.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){r.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,u()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:i.contactId}).leaveManagees().then(function(e){i.lookupContacts=e}).then(o)}}}function o(){return t.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:i.filters.userSettings.department?i.filters.userSettings.department.value:null,level_type:i.filters.userSettings.level_type?i.filters.userSettings.level_type.value:null,location:i.filters.userSettings.location?i.filters.userSettings.location.value:null,region:i.filters.userSettings.region?i.filters.userSettings.region.value:null,id:{IN:i.filters.userSettings.contact?[i.filters.userSettings.contact.id]:i.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var i;return{init:function(e){return i=e,i.showContactName=!0,i.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function o(a,o,s,i,r,c,u,l,d,m){function f(){for(var e=[],t=n(M.selectedPeriod.start_date).clone().startOf("month"),a=n(M.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(A(t)),t.add(1,"month");M.months=e}function p(){i.$new().$watch(function(){return M.selectedMonths},function(t,n){null===n||e.equals(t,n)||I()})}function h(e){M.injectMonths=!0,S("injected").then(function(){I(e)}).then(function(){M.loading.calendar=!1})}function v(){L=a("LeaveCalendar"+t.capitalize(k)+"Controller").init(M)}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function g(){return c.all().then(function(e){M.absencePeriods=t.sortBy(e,"start_date"),M.selectedPeriod=t.find(M.absencePeriods,function(e){return!!e.current})}).then(f).then(w)}function _(){return u.all().then(u.loadCalculationUnits)}function y(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return L.loadContacts().then(function(e){M.contacts=e})}function C(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){M.filters.optionValues.regions=e.hrjc_region,M.filters.optionValues.locations=e.hrjc_location,M.filters.optionValues.levelTypes=e.hrjc_level_type,M.filters.optionValues.departments=e.hrjc_department})}function D(){return l.all()}function T(){return o.all([_(),D(),y()]).then(function(e){M.supportData.absenceTypes=e[0],M.supportData.publicHolidays=e[1],M.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,M.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,M.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,M.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function P(){var e=o.resolve();return M.injectMonths&&(e=S("destroyed"),M.injectMonths=!1),e}function A(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function R(e){e=t.includes(["contacts","period"],e)?e:"period",o.resolve().then(function(){M.loading.calendar=!0}).then(P).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function I(e){var n=M.selectedMonths.length?M.months.filter(function(e){return t.includes(M.selectedMonths,e.index)}):M.months;i.$emit("LeaveCalendar::showMonths",n,!!e)}function w(){M.selectedMonths=[n().month()]}function O(){return M.roleOverride?o.resolve().then(function(){k=M.roleOverride}):o.all([m(r.permissions.admin.administer),m(r.permissions.ssp.manage)]).then(function(e){k=e[0]?"admin":e[1]?"manager":"staff"})}function S(e){return o(function(n){var a=0,o=i.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===M.months.length&&(o(),n())})})}s.debug("Component: leave-calendar");var L,k,M=this;M.absencePeriods=[],M.contacts=[],M.contactIdsToReduceTo=null,M.injectMonths=!1,M.months=[],M.selectedMonths=null,M.selectedPeriod=null,M.showContactName=!1,M.showFilters=!1,M.supportData={},M.loading={calendar:!0,page:!0},M.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},M.labelPeriod=b,M.refresh=R,function(){O().then(p).then(v).then(P).then(g).then(function(){return o.all([q(),T()])}).then(function(){return M.showFilters?C():t.noop}).then(function(){h()}).then(function(){M.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",o]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,o){"use strict";function s(){y.calculationUnit=i(y.supportData.calculationUnits,"value",b.calculation_unit)}function i(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function r(){var e,n;return n=t(y.contactData.leaveRequest.from_date).isSame(y.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+y.calculationUnit.name+"-on-"+e+"-tooltip"}function c(){b=i(y.supportData.absenceTypes,"id",y.contactData.leaveRequest.type_id),y.contactData.leaveRequest["type_id.title"]=b.title}function u(){"days"===y.calculationUnit.name&&(g=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.from_date_type),_=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.to_date_type),y.contactData.leaveRequest["from_date_type.label"]=g.label,y.contactData.leaveRequest["to_date_type.label"]=_.label)}function l(e,t,n,a,s){e.stopPropagation(),o.openModal(t,n,a,s)}function d(){y.dates.from=new Date(y.contactData.leaveRequest.from_date),y.dates.to=new Date(y.contactData.leaveRequest.to_date)}function m(){y.contactData.isAccruedTOIL?y.label="AT":"days"===y.calculationUnit.name?f():p()}function f(){y.label=y.contactData.isAM?"AM":y.contactData.isPM?"PM":""}function p(){var e=t(y.contactData.leaveRequest.from_date).isSame(y.date,"day"),n=t(y.contactData.leaveRequest.to_date).isSame(y.date,"day");y.label=e?t(y.contactData.leaveRequest.from_date).format("HH:mm"):n?t(y.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){y.tooltipTemplate=y.contactData.isAccruedTOIL?"accrued-toil-tooltip":r()}function v(){a.$watch("day.contactData.leaveRequest",function(){y.contactData&&y.contactData.leaveRequest&&(c(),s(),u(),m(),d(),h()) +})}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(e){_([e]),U(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return j[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){L(e),U(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=P(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){F.push(o.$on("LeaveCalendar::showMonths",$)),F.push(r.subscribe("LeaveRequest::new",u)),F.push(r.subscribe("LeaveRequest::edit",B)),F.push(r.subscribe("LeaveRequest::updatedByManager",B)),F.push(r.subscribe("LeaveRequest::delete",h)),F.push(r.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function D(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function T(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function P(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function A(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function R(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function I(){return[R(c.statusNames.approved),R(c.statusNames.adminApproved),R(c.statusNames.awaitingApproval),R(c.statusNames.moreInformationRequired)]}function w(){return H.month.loading=!0,a.all([S(),O()]).then(b).then(x).then(function(){N=!0}).then(function(){H.month.loading=!1})}function O(){return i.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:I()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function S(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){j=e.indexBy(t,"contact_id")})}function L(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function k(){o.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function M(t,n,o){var s,i;return t.contactsData[n]=t.contactsData[n]||{},i=m(n),s=!0===o?a.resolve():a.all([i.isWeekend(p(t.date)),i.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:D(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?T(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function x(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return M(e,t.id)}))}))}function $(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!N)&&w())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=A(e);t&&(h(t),-1!==I().indexOf(e.status_id)&&u(e))}function U(e){return a.all(P(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],j={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=k,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,i,r,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(i.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=D[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&r.publish("ManagerBadge:: Update Count"),r.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(D,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:D[e].label,isDirectAction:D[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,D={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return r.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,c.serverDateFormat).toDate()}function h(e){return t(e).format(c.serverDateFormat)}function v(e){var t;return i.resolve().then(function(){F(e),"from"===e&&N(),S("hours")&&(_(e),"from"!==e||te.uiOptions.multipleDays||_("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return i.reject("Please change date as it is not in any absence period")}).then(W).then(function(){if(t)return x()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(V(),!t)return E();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(P).finally(y)}function b(){return V(),E()}function g(){return te.uiOptions.toDate=null,F("to"),i.resolve().then(V).then(te.setDaysSelectionModeExtended).then(y).then(!te.uiOptions.multipleDays&&E)}function _(e){te.uiOptions.times[e].loading=!0}function y(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,S("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function C(){return te.request?te.request.request_type:te.leaveType||null}function D(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(j).catch(P)}function P(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function A(){return te.isMode("create")||te.forceRecalculateBalanceChange?E():T()}function R(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():i.resolve()}function I(){ee.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){Q()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){J(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",E))}function w(){te.isMode("edit")&&(te.isLeaveStatus(c.statusNames.approved)||te.isLeaveStatus(c.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function O(){o.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(K(e),V()))})}function S(e){return te.selectedAbsenceType.calculation_unit_name===e}function L(e){return te.request.request_type===e}function k(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function M(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function x(){return u.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function $(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function E(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(j).catch(P).finally(function(){te.loading.balanceChange=!1})):i.resolve()}function B(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function U(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),V(),z()}function j(e){te.balance.change=e,te.request.balance_change=e.amount,f(),B(),te.loading.balanceChange=!1}function W(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function H(){return!te.isMode("create")&&U()||te.isMode("create")&&(L("sickness")||S("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,i.resolve().then(te.setDaysSelectionModeExtended)}function G(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function Y(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function V(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(S("hours")||L("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function X(){e.forEach(ee,function(e){e()})}function Q(){var e,t=te.selectedAbsenceType.calculation_unit_name;return Y(),e=t!==te.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&H).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&V).then(y).then(E)}function J(e){return te.absenceTypes=e,Y(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),G(),E()}function K(e){var t=D(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(D(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(D(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=c.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:$},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:r.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=b,te.daysSelectionModeChangeHandler=g,te.disableAndShowLoadingTimeInput=_,te.getMomentDateWithGivenTime=D,te.handleError=P,te.isCalculationUnit=S,te.isLeaveType=L,te.isNotWorkingDay=k,te.performBalanceChangeCalculation=E,te.setRequestDateTimesAndDateTypes=V,te.updateEndTimeInputMinTime=K,te.$onDestroy=X,function(){n("RequestModalDetails"+e.capitalize(C(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",te),I(),te.initChildController().then(function(){return i.all([x(),M()])}).then(!te.isMode("create")&&R).then(H).then(function(){if(!te.isMode("create"))return i.resolve().then(te.initTimesExtended).then(V)}).then(!te.isMode("create")&&W).then(w).then(G).then(A).then(O).then(!te.isMode("view")&&te.initWatchersExtended).catch(P).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l){function d(){return O.fileUploader&&O.fileUploader.queue.length>0}function m(){return O.getFilesAmount()0?R.map(function(e){return e.label}).join(", "):""}function q(){return O.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(R.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){w[e.label]=t})})).catch(function(){w=null})}function D(){return c.valuesOf("safe_file_extension").then(function(e){R=e})}function T(e){return!e.attachment_id||O.canManage}function P(){e.forEach(I,function(e){e()})}function A(e,t){O.fileUploader.queue&&O.fileUploader.queue.length>0?O.fileUploader.uploadAll({entityID:O.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var R=[],I=[],w={},O=Object.create(this);return O.filesLoaded=!1,O.fileUploader=null,O.today=Date.now(),O.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",O.userDateFormat=i.DATE_FORMAT,O.$onDestroy=P,O.canRemoveAttachment=T,O.canSubmit=d,O.canUploadMore=m,O.formatDateTime=f,O.getAuthorName=p,O.getFilesAmount=h,O.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",O),g(),a.all([D(),q()]).then(_).finally(function(){O.filesLoaded=!0})}(),O}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,o){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],s.openLeavePopup=a,function(){o=n.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,o,s,i,r,c,u,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var t=j[e.status];t?t(e.leaveRequest):W.refresh()}function b(t){t.dataIndex=e.indexBy(t.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return i.all().then(i.loadCalculationUnits).then(function(t){W.absenceTypes=t,W.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return R("approved",{status_id:F(m.statusNames.approved)})}function C(){return n.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function D(){return r.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(t){var n=e.find(W.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function T(){return r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return M(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function P(){return n.all([r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),A({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:M(e[0]),expiredTOILS:x(e[1].list)})}).then(function(t){W.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function A(t){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function R(e,t){return A(t).then(function(t){W.sections[e].data=t.list})}function I(){return n.all(Object.values(W.sections).filter(function(e){return e.open}).map(L))}function w(){return R("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function O(){return R("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function S(){return R("holidays",{public_holiday:!0})}function L(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function k(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){W.leaveRequestStatuses=e.indexBy(t,"value")})}function M(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(W.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function x(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function $(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(W.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],B(t,a))})}function B(e,t){var n=W.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function U(){W.loading.content=!0,n.all([D(),C()]).then(function(){W.loading.content=!1}).then(function(){return n.all([I(),h()])})}function N(e){var t=W.sections[e];t.open=!t.open,t.open&&!t.data.length&&L(t)}function F(t){return e.find(W.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var j={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:T},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:P},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w}},W.labelPeriod=g,W.refresh=U,W.toggleSection=N,function(){n.all([k(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return n.all([D(),C()])}).then(function(){W.loading.content=!1}),$()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report", +controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function u(){var e=i.request,t=!!e.from_date&&!!e.to_date,n=i.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return i.canCalculateChange()}function d(t,n){var a=i.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);i.uiOptions.multipleDays||("from"===t&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=i.convertDateToServerFormat(t),r.isPublicHoliday(t).then(function(n){return n?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,i.requestDayTypes).then(function(t){return t.length?t:i.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return A(n,e),e})):o.reject([])}function f(e,n){return e=t(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return o.resolve()}function v(){return C(i.uiOptions.fromDate,"from").then(function(){return C(i.uiOptions.toDate,"to")})}function b(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,t){i.isCalculationUnit("days")||+e==+t||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function g(e){var n=t(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),i.uiOptions.times[e].time=n}function _(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],t=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(T)).then(function(){["from","to"].forEach(function(e){g(e),I(e),t[e].amount=Math.min(i.request[e+"_date_amount"],t[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function y(){["from","to"].forEach(function(e){b(e),q(e)})}function q(e){s.$watch(function(){return i.uiOptions.times[e].time},function(t,n){i.isCalculationUnit("days")||t===n||(i.setRequestDateTimesAndDateTypes(),t&&I(e,!0))})}function C(e,t){return m(e,t).then(function(){i.loading[t+"DayTypes"]=!1})}function D(e){return C(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return T(e).then(function(){I(e,!0)})})}function T(e){var t=i.uiOptions[e+"Date"],n=!i.uiOptions.multipleDays;return t?i.request.getWorkDayForDate(i.convertDateToServerFormat(t)).then(function(t){S[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return S[e]={},i.handleError(t)}).finally(function(){n&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(t){var n=i.uiOptions.times[t];i["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function A(t,n){var a="request"+e.startCase(t)+"DayTypes";i[a]=n,i.isMode("create")&&(i.request[t+"_date_type"]=i[a][0].value)}function R(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),T("from").then(function(){I("from",!0)})):o.resolve()}function I(e,t){var n=i.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,c=S[a].number_of_hours?p(s,r).toString():"0";o.maxAmount=c,t&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function O(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?T("from").then(function(){I("from",!0)}):o.resolve()}var S={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=c,i.canCalculateChange=u,i.canSubmit=l,i.initChildController=h,i.initDayTypesExtended=v,i.initTimesExtended=_,i.initWatchersExtended=y,i.onAbsenceTypeUpdateExtended=O,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=R}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function i(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function r(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=i,s.initChildController=r,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=t.duration(t(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,t=!c.uiOptions.multipleDays&&!!c.request.from_date,n=t||e,a=F.from_date!==c.request.from_date||F.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&n&&W.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,t=c.request;return b({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function b(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&W.hasExpirationFromAdminSettings,t=W.hasPreviousExpirationDate,n=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=n&&(a||e||t)}function _(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function y(){return W.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){W.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",y().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function D(){o.$watch(function(){return c.request.toil_to_accrue},function(e,t){+e!=+t&&c.performBalanceChangeCalculation()})}function T(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&c.isCalculationUnit("hours")&&L(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function P(){var e=c.uiOptions.times;e.from.time=t(c.request.from_date).format("HH:mm"),e.to.time=t(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function A(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,t){e!==t&&(c.setRequestDateTimesAndDateTypes(),U(),l(),k())})})}function R(){c.isMode("view")||(D(),T(),A())}function I(t){return i.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){c.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function w(){return l(),k(),U()}function O(){return x(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),j?j=!1:k(),U()}function S(e){c.uiOptions.times[e].time=""}function L(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function k(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function M(){F=e.cloneDeep(c.request.attributes())}function x(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function $(){c.setRequestDateTimesAndDateTypes(),l(),k(),c.isCalculationUnit("hours")?L():c.request.toil_to_accrue=null}function E(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){I(!1)})}function B(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function U(){return f()?d().catch(a.resolve):a.resolve()}function N(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var F,j=!c.isMode("create"),W={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=P,c.initWatchersExtended=R,c.onAbsenceTypeUpdateExtended=$,c.onDateChangeExtended=w,c.openToilInDaysAccrualOptionsEditor=E,c.resetUIInputsExtended=S,c.setDaysSelectionModeExtended=O,c.updateExpiryDate=N,function(){M(),x(),B(),!c.isMode("create")&&_()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,D){function T(e){"days"===xe.selectedAbsenceType.calculation_unit_name?delete xe.request[e+"_date_amount"]:delete xe.request[e+"_date_type"]}function P(){["from","to"].forEach(T)}function A(){var e=xe.requestStatuses[y.statusNames.awaitingApproval].value;we.status_id===e&&e!==xe.request.status_id&&d.publish("ManagerBadge:: Update Count")}function R(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!xe.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function O(){var e=R();return xe.isMode("edit")&&(e=e&&(G()||I())),xe.canManage&&xe.requestStatuses&&(e=e&&!!xe.getStatusFromValue(xe.newStatusOnSave)),(e=e&&!!xe.period.id)&&!xe.isMode("view")}function S(){xe.isSelfRecord?xe.request.status_id=xe.requestStatuses[y.statusNames.awaitingApproval].value:xe.canManage&&(xe.request.status_id=xe.newStatusOnSave||xe.request.status_id)}function L(){if(xe.isMode("edit")&&!xe.isRole("staff")&&"toil"!==F())return xe.request.calculateBalanceChange(xe.selectedAbsenceType.calculation_unit_name).then(function(e){if(+xe.balance.change.amount!=+e.amount)return D.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function k(){xe.errors=[]}function M(){return xe.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function x(){ee()&&!xe.isRole("staff")&&(xe.request.change_balance=!0)}function $(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return xe.request.delete().then(function(){xe.dismissModal(),d.publish("LeaveRequest::delete",xe.request)})}})}function E(){r.dismiss({$value:"cancel"})}function B(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return N(xe.getStatusFromValue(xe.request.status_id).name)}function N(e){return n.map(Re[e],function(e){return xe.requestStatuses[e]})}function F(){return xe.request?xe.request.request_type:xe.leaveType||null}function j(){return!xe.request||e.equals({},xe.requestStatuses)?[]:xe.request.status_id?U():N("none")}function W(e){return n.find(xe.requestStatuses,function(t){return t.value===e})}function H(e){xe.errors=n.isArray(e)?e:[e],xe.loading.absenceTypes=!1,xe.submitting=!1}function G(){return!e.equals(we,xe.request.attributes())||xe.canManage&&xe.newStatusOnSave}function Y(){return xe.postContactSelection=!0,xe.staffMemberSelectionComplete=!1,xe.request.contact_id?o.resolve().then(re).then(ce).then(he).then(be).then(Z).then(z).then(xe.isMode("edit")?ge:n.noop).then(function(){xe.postContactSelection=!1,xe.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Le)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Re.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Re.awaiting_approval=e,Re.more_information_required=e,Re.rejected=e,Re.approved=e,Re.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return xe.canManage?f.find(xe.request.contact_id).then(function(e){xe.contactName=e.display_name}):o.resolve()}function X(){Oe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",xe.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Ie++})),i.$on("$destroy",De),i.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function Q(){var e,t;xe.request=xe.leaveRequest||null,e=F(),t=xe.initRequestAttributes(),"leave"===e?xe.request=_.init(t):"sickness"===e?xe.request=q.init(t):"toil"===e&&(xe.request=C.init(t))}function J(){var e={};return xe.request?e=xe.request.attributes():xe.canManage||(e={contact_id:Se}),e}function K(){if(ke="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(ke="admin")}).then(function(){return"staff"===ke&&c(y.permissions.ssp.manage).then(function(e){e&&(ke="manager")})}).finally(function(){xe.canManage=xe.isRole("manager")||xe.isRole("admin")})}function Z(){(xe.isRole("admin")||xe.isMode("create")&&xe.isRole("manager"))&&(xe.newStatusOnSave=xe.requestStatuses[y.statusNames.approved].value)}function ee(){return!xe.request.status_id||!n.includes(["cancelled","rejected"],W(xe.request.status_id).name)}function te(e){var t=xe.getStatusFromValue(xe.request.status_id);return!!t&&t.name===e}function ne(e){return xe.request&&xe.request.request_type===e}function ae(e){return xe.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return ke===e}function ie(){return h.all().then(function(e){xe.absencePeriods=e})}function re(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Ae={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return xe.loading.entitlements=!0,b.all({contact_id:xe.request.contact_id,period_id:xe.period.id,type_id:{IN:Ae.ids}},!0).finally(function(){xe.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Se=e.contactId})}function le(){return xe.selectedContactId?f.find(xe.selectedContactId).then(function(e){xe.managedContacts=[e]}):xe.isRole("admin")?f.all().then(function(e){xe.managedContacts=n.remove(e.list,function(e){return e.id!==Se})}):f.find(Se).then(function(e){return e.leaveManagees()}).then(function(e){xe.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){xe.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){A(),d.publish(e,xe.request),xe.errors=[],xe.dismissModal()}function pe(){["from","to"].forEach(function(e){xe.request[e+"_date"]=we[e+"_date"]})}function he(e){if(xe.absenceTypes=me(Ae.types,e),!xe.absenceTypes.length)return o.reject(Le)}function ve(){xe.period=n.find(xe.absencePeriods,function(e){return xe.isMode("create")?e.current:oe(xe.request,e)})}function be(){xe.isMode("create")?(xe.selectedAbsenceType=xe.absenceTypes[0],xe.request.type_id=xe.selectedAbsenceType.id):xe.selectedAbsenceType=n.find(xe.absenceTypes,function(e){return e.id===xe.request.type_id})}function ge(){we=e.copy(xe.request.attributes())}function _e(){var e;xe.request.id?(e=[xe.requestStatuses[y.statusNames.approved].value,xe.requestStatuses[y.statusNames.adminApproved].value,xe.requestStatuses[y.statusNames.rejected].value,xe.requestStatuses[y.statusNames.cancelled].value],xe.mode="edit",xe.isRole("staff")&&e.indexOf(xe.request.status_id)>-1&&(xe.mode="view")):xe.mode="create"}function ye(){var e=xe.request.status_id;if(!xe.isMode("view")&&!xe.submitting)return xe.submitting=!0,S(),P(),xe.request.isValid().then(ee()&&L).then(x).then(!xe.request.change_balance&&pe).then(qe).then(function(){return xe.isMode("edit")?Pe():M()}).catch(function(t){xe.request.status_id=e,t&&H(t)}).finally(function(){xe.submitting=!1})}function qe(){return o.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===Ie&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return Ie>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function De(){Oe.forEach(function(e){e()})}function Te(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Pe(){return xe.request.update().then(Ce).then(function(){xe.isRole("manager")?fe("LeaveRequest::updatedByManager"):(xe.isRole("staff")||xe.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Ae,Re={},Ie=0,we={},Oe=[],Se="",Le="No entitlement",ke="",Me=[],xe=n.assign(this,m);xe.absencePeriods=[],xe.absenceTypes=[],xe.canManage=!1,xe.contactName=null,xe.errors=[],xe.loading={absenceTypes:!0,entitlements:!0},xe.managedContacts=[],xe.mode="",xe.newStatusOnSave=null,xe.period={},xe.postContactSelection=!1,xe.requestStatuses={},xe.selectedAbsenceType={},xe.staffMemberSelectionComplete=!1,xe.submitting=!1,xe.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},xe.canChangeAbsenceType=w,xe.canSubmit=O,xe.closeAlert=k,xe.deleteLeaveRequest=$,xe.dismissModal=E,xe.getStatuses=j,xe.getStatusFromValue=W,xe.initAfterContactSelection=Y,xe.initRequestAttributes=J,xe.isLeaveStatus=te,xe.isLeaveType=ne,xe.isMode=ae,xe.isRole=se,xe.submit=ye,xe.updateAbsenceType=Te,function(){xe.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),ie(),de()]).then(Q).then(_e).then(ve).then(function(){return xe.canManage&&!xe.isMode("edit")&&le()}).then(function(){if(xe.selectedContactId&&(xe.request.contact_id=xe.selectedContactId),xe.request.contact_id)return xe.initAfterContactSelection()}).catch(H).finally(function(){xe.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,i,r,c){function u(e){return r.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,i,r){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:i,forceRecalculateBalanceChange:r}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,i){function r(e){l.errorMessage=e}function c(){return i.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrjc_revision_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,i.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(r).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrjc_revision_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()} +n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(),g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){r.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){i.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i){function r(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,i){n=o.entitlements.slice(0,i),a=e.entitlements.slice(i+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,i;return s=e.indexBy(n,"entitlement_id.type_id"),i=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:i}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t];e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,i){o.comment&&(t=s.concat(o).concat(i),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(r).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,i,r,c,u,l,d){function m(){D.absencePeriods=t.chain(D.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){D.absenceTypes=t.filter(D.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:D.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:D.contactId,returnUrl:n})}function h(){return c.all().then(function(e){D.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:D.contactId}).then(function(e){q=e})}function g(e){i.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=D.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){D.absencePeriods=t.map(D.absencePeriods,function(e){var n=t.map(D.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

    Last updated:
    By: "+e.author_name+"
    Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
    ";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],D=this;D.absencePeriods=[],D.loading={absencePeriods:!0},D.getEditEntitlementsPageURL=p,D.openAnnualEntitlementChangeLog=g,D.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){D.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i,r){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return i.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){r.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js index 9566e9617f1..3f798dbed1e 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js @@ -6,9 +6,9 @@ */ -!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return U(e)&&e.then&&e.$$promises}if(!U(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!U(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},U(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||F(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!U(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=U(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=F(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:U(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in T)B(T[o])&&(t[o]=T[o](t,T.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),w.current)}).then(null,function(a){return a===D?T:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function T(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:T(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function M(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,T(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return U(n)?e+G(n):(n=t.$eval(n),U(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function L(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,U=t.isObject,F=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;aWhen All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){E.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(m).then(T)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function T(){E.selectedMonths=[n().month()]}function S(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=D,function(){S().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return F[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){U.push(r.$on("LeaveCalendar::showMonths",L)),U.push(i.subscribe("LeaveRequest::new",c)),U.push(i.subscribe("LeaveRequest::edit",j)),U.push(i.subscribe("LeaveRequest::updatedByManager",j)),U.push(i.subscribe("LeaveRequest::delete",h)),U.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function T(){return W.month.loading=!0,a.all([O(),S()]).then(g).then(M).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){F=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),U.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function M(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function L(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&T())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,U=[],F={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}), -define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){U(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,U("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(F).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function T(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function L(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(F).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,U("to"))}function U(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function F(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,U("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:L},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),E()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(T).then(V).then(P).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function f(){return S.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){T[e.label]=t})})).catch(function(){T=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||S.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],T={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=w,S.canRemoveAttachment=A,S.canSubmit=d,S.canUploadMore=f,S.formatDateTime=m,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){F.filters.leaveRequest.contact_id=null,F.refresh()}function p(){var e=F.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?F.leaveRequests.filter.list.length:F.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(F.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(F.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(F.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(F.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){F.absencePeriods=e.sortBy(t,"start_date"),F.filters.leaveRequest.selectedPeriod=e.find(F.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){F.absenceTypes=e})}function w(e){return(F.isAdmin?r.all(p()):r.leaveManagees(F.contactId,p())).then(function(t){return F.filteredUsers=F.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){F.filters.leaveRequest.leaveStatus!==H&&0===F.leaveRequests.table.list.length&&F.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){F.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:F.pagination,r="filter"===e?{return:["status_id"]}:{};return F.loading[n]=!0,l.all(S(t),a,"from_date DESC",r,!1).then(function(t){F.leaveRequests[e]=t}).catch(function(){F.leaveRequests[e].list=[]}).finally(function(){F.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){F.levelTypes=e})}function T(){return s.valuesOf("hrjc_location").then(function(e){F.locations=e})}function S(t){var n=F.filters.leaveRequest;return{contact_id:E(),managed_by:F.isAdmin&&"me"!==n.assignedTo.type?void 0:F.contactId,status_id:L(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(F.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){F.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){F.leaveRequestStatuses=e.concat(F.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function E(){return F.filteredUsers.length>0&&F.filters.leaveRequest.contact_id?F.filters.leaveRequest.contact_id:{IN:F.filteredUsers.map(function(e){return e.id})}}function M(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function L(e){var t=F.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=M(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(F.filters.leaveRequest.leaveStatus=H),(e<=F.totalNoOfPages()||0===F.totalNoOfPages())&&(F.pagination.page=e,w(n))}function j(e){F.filters.leaveRequest.leaveStatus=e,F.refresh(1,!1,"table")}function B(e){F.filters.leaveRequest.assignedTo=e,F.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){F.refresh()}),f.subscribe("LeaveRequest::new",function(){F.refresh()}),f.subscribe("LeaveRequest::edit",function(){F.refresh()}),f.subscribe("LeaveRequest::delete",function(){F.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){F.refresh()})}function U(){return Math.ceil(F.leaveRequests.table.total/F.pagination.size)}t.debug("Component: manage-leave-requests");var F=this,H={name:"all",label:"All"};F.absencePeriods=[],F.absenceTypes=[],F.filteredUsers=[],F.isFilterExpanded=!1,F.isAdmin=!1,F.leaveRequests={table:{list:[]},filter:{list:[]}},F.leaveRequestStatuses=[H],F.loading={content:!0,page:!0,table:!0},F.pagination={page:1,size:7},F.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],F.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:F.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:F.filtersByAssignee[0]}},F.clearStaffSelection=m,F.countLeaveRequestByStatus=h,F.getAbsenceTypeByID=v,F.getArrayOfSize=g,F.getLeaveStatusByValue=b,F.getNavBadge=y,F.getUserNameByID=q,F.labelPeriod=$,F.openLeavePopup=x,F.refresh=k,F.refreshWithFilter=j,F.refreshWithFilterByAssignee=B,F.totalNoOfPages=U,function(){o(i.permissions.admin.administer).then(function(e){F.isAdmin=e,n.all([C(),A(),O(),P(),T(),R(),I()]).then(function(){F.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),T(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(T)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function T(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=B.from_date!==u.request.from_date||B.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&U.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&U.hasExpirationFromAdminSettings,t=U.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return U.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){U.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),k(),l(),I())})})}function D(){u.isMode("view")||(C(), -A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function T(){return l(),I(),k()}function S(){return E(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),N?N=!1:I(),k()}function O(e){u.uiOptions.times[e].time=""}function I(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function x(){B=e.cloneDeep(u.request.attributes())}function E(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function M(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){R(!1)})}function L(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function k(){return m()?d().catch(a.resolve):a.resolve()}function j(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var B,N=!u.isMode("create"),U={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=T,u.openToilInDaysAccrualOptionsEditor=M,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=j,function(){x(),E(),L(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,r,o){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(o.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Te.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==U())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function E(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function L(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=U();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function U(){return Me.request?Me.request.request_type:Me.leaveType||null}function F(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Te,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=U(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Me.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Te[e+"_date"]})}function he(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function ve(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Te=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():E()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Te={},Se=[],Oe="",Ie="No entitlement",xe="",Ee=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=T,Me.canSubmit=S,Me.closeAlert=x,Me.deleteLeaveRequest=L,Me.dismissModal=k,Me.getStatuses=F,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(t){return t.module("admin-dashboard.settings",[]).constant("settings",{ -contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM),define("leave-absences/admin-dashboard/modules/config",["common/angular","leave-absences/admin-dashboard/modules/settings"],function(e){return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(e,t,n,a,r,o){var s={format:["DateFormat",function(e){return e.getDateFormat()}]};r.debugEnabled(o.debug),t.defaults.stripTrailingSlashes=!1,a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:s}).state("calendar",{url:"/calendar",template:'',resolve:s}).state("leave-balances",{url:"/leave-balances",template:"",resolve:s})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function t(e,t){e.debug("Component: admin-dashboard-container"),t.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",t]})}),define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/admin-dashboard":n+"/admin-dashboard"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); +!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return U(e)&&e.then&&e.$$promises}if(!U(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!U(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},U(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||F(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!U(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=U(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=F(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(D.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:U(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!D[r])return m(r,t.self);for(var o in T)B(T[o])&&(t[o]=T[o](t,T.$delegates[o]));return D[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=D;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=D;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),w.current)}).then(null,function(a){return a===P?T:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=P(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function D(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=P(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function P(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function T(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:T(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function M(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,T(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return U(n)?e+G(n):(n=t.$eval(n),U(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function L(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,U=t.isObject,F=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;aWhen All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(D(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){E.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(m).then(T)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function D(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function P(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function T(){E.selectedMonths=[n().month()]}function S(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=P,function(){S().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return F[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){U.push(r.$on("LeaveCalendar::showMonths",L)),U.push(i.subscribe("LeaveRequest::new",c)),U.push(i.subscribe("LeaveRequest::edit",j)),U.push(i.subscribe("LeaveRequest::updatedByManager",j)),U.push(i.subscribe("LeaveRequest::delete",h)),U.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function D(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function P(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[P(u.statusNames.approved),P(u.statusNames.adminApproved),P(u.statusNames.awaitingApproval),P(u.statusNames.moreInformationRequired)]}function T(){return W.month.loading=!0,a.all([O(),S()]).then(g).then(M).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){F=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),U.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function M(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function L(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&T())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=D(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,U=[],F={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}), +define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){U(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,U("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(F).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function D(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function P(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function T(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function L(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(F).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,U("to"))}function U(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function F(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,U("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:L},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),E()])}).then(!te.isMode("create")&&P).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(T).then(V).then(D).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function f(){return S.getFilesAmount()0?P.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(P.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){T[e.label]=t})})).catch(function(){T=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){P=e})}function A(e){return!e.attachment_id||S.canManage}function w(){e.forEach(R,function(e){e()})}function D(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var P=[],R=[],T={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=w,S.canRemoveAttachment=A,S.canSubmit=d,S.canUploadMore=f,S.formatDateTime=m,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){F.filters.leaveRequest.contact_id=null,F.refresh()}function p(){var e=F.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?F.leaveRequests.filter.list.length:F.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(F.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(F.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(F.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(F.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){F.absencePeriods=e.sortBy(t,"start_date"),F.filters.leaveRequest.selectedPeriod=e.find(F.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){F.absenceTypes=e})}function w(e){return(F.isAdmin?r.all(p()):r.leaveManagees(F.contactId,p())).then(function(t){return F.filteredUsers=F.isAdmin?t.list:t,e?P(e):n.all([P("table"),P("filter")])}).then(function(){F.filters.leaveRequest.leaveStatus!==H&&0===F.leaveRequests.table.list.length&&F.refresh(1,!0)})}function D(){return s.valuesOf("hrjc_department").then(function(e){F.departments=e})}function P(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:F.pagination,r="filter"===e?{return:["status_id"]}:{};return F.loading[n]=!0,l.all(S(t),a,"from_date DESC",r,!1).then(function(t){F.leaveRequests[e]=t}).catch(function(){F.leaveRequests[e].list=[]}).finally(function(){F.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){F.levelTypes=e})}function T(){return s.valuesOf("hrjc_location").then(function(e){F.locations=e})}function S(t){var n=F.filters.leaveRequest;return{contact_id:E(),managed_by:F.isAdmin&&"me"!==n.assignedTo.type?void 0:F.contactId,status_id:L(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(F.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){F.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){F.leaveRequestStatuses=e.concat(F.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function E(){return F.filteredUsers.length>0&&F.filters.leaveRequest.contact_id?F.filters.leaveRequest.contact_id:{IN:F.filteredUsers.map(function(e){return e.id})}}function M(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function L(e){var t=F.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=M(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(F.filters.leaveRequest.leaveStatus=H),(e<=F.totalNoOfPages()||0===F.totalNoOfPages())&&(F.pagination.page=e,w(n))}function j(e){F.filters.leaveRequest.leaveStatus=e,F.refresh(1,!1,"table")}function B(e){F.filters.leaveRequest.assignedTo=e,F.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){F.refresh()}),f.subscribe("LeaveRequest::new",function(){F.refresh()}),f.subscribe("LeaveRequest::edit",function(){F.refresh()}),f.subscribe("LeaveRequest::delete",function(){F.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){F.refresh()})}function U(){return Math.ceil(F.leaveRequests.table.total/F.pagination.size)}t.debug("Component: manage-leave-requests");var F=this,H={name:"all",label:"All"};F.absencePeriods=[],F.absenceTypes=[],F.filteredUsers=[],F.isFilterExpanded=!1,F.isAdmin=!1,F.leaveRequests={table:{list:[]},filter:{list:[]}},F.leaveRequestStatuses=[H],F.loading={content:!0,page:!0,table:!0},F.pagination={page:1,size:7},F.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],F.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:F.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:F.filtersByAssignee[0]}},F.clearStaffSelection=m,F.countLeaveRequestByStatus=h,F.getAbsenceTypeByID=v,F.getArrayOfSize=g,F.getLeaveStatusByValue=b,F.getNavBadge=y,F.getUserNameByID=q,F.labelPeriod=$,F.openLeavePopup=x,F.refresh=k,F.refreshWithFilter=j,F.refreshWithFilterByAssignee=B,F.totalNoOfPages=U,function(){o(i.permissions.admin.administer).then(function(e){F.isAdmin=e,n.all([C(),A(),O(),D(),T(),R(),I()]).then(function(){F.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return D(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),T(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(T)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function D(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function P(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function T(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=P}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=U.from_date!==u.request.from_date||U.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&H.hasExpirationFromAdminSettings,t=H.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&u.isCalculationUnit("hours")&&I(),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function D(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),B(),l(),x())})})}function P(){u.isMode("view")||(C(),A(),D())}function R(t){ +return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function T(){return l(),x(),B()}function S(){return M(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),F?F=!1:x(),B()}function O(e){u.uiOptions.times[e].time=""}function I(){u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours}function x(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function E(){U=e.cloneDeep(u.request.attributes())}function M(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function L(){u.setRequestDateTimesAndDateTypes(),l(),x(),u.isCalculationUnit("hours")?I():u.request.toil_to_accrue=null}function k(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){R(!1)})}function j(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function B(){return m()?d().catch(a.resolve):a.resolve()}function N(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var U,F=!u.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=P,u.onAbsenceTypeUpdateExtended=L,u.onDateChangeExtended=T,u.openToilInDaysAccrualOptionsEditor=k,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=N,function(){E(),M(),j(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,r,o){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(o.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function D(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Te.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=P();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==U())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function E(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function L(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=U();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(Pe[e],function(e){return Me.requestStatuses[e]})}function U(){return Me.request?Me.request.request_type:Me.leaveType||null}function F(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Te,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Pe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Pe.awaiting_approval=e,Pe.more_information_required=e,Pe.rejected=e,Pe.approved=e,Pe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=U(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Me.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){De={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:De.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){D(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Te[e+"_date"]})}function he(e){if(Me.absenceTypes=fe(De.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function ve(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Te=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():E()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var De,Pe={},Re=0,Te={},Se=[],Oe="",Ie="No entitlement",xe="",Ee=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=T,Me.canSubmit=S,Me.closeAlert=x,Me.deleteLeaveRequest=L,Me.dismissModal=k,Me.getStatuses=F,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}), +function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(t){return t.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM),define("leave-absences/admin-dashboard/modules/config",["common/angular","leave-absences/admin-dashboard/modules/settings"],function(e){return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(e,t,n,a,r,o){var s={format:["DateFormat",function(e){return e.getDateFormat()}]};r.debugEnabled(o.debug),t.defaults.stripTrailingSlashes=!1,a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:s}).state("calendar",{url:"/calendar",template:'',resolve:s}).state("leave-balances",{url:"/leave-balances",template:"",resolve:s})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function t(e,t){e.debug("Component: admin-dashboard-container"),t.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",t]})}),define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/admin-dashboard":n+"/admin-dashboard"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js index cfb12653f3d..1ae61867433 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js @@ -6,9 +6,9 @@ */ -!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in T)B(T[o])&&(t[o]=T[o](t,T.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=L[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),w.current)}).then(null,function(a){return a===D?T:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function T(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:T(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function L(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function E(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,T(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n){function a(e){e.absencePeriods&&c.absencePeriods.length&&(c.filters.period_id=o().id),e.absenceTypes&&c.absenceTypes.length&&(c.filters.type_id=s().id),(e.loggedInContactId||e.userRole)&&(c.filters.managed_by="manager"===c.userRole?c.loggedInContactId:void 0),r()&&c.submitFilters()}function r(){return e.every(c.filters,function(e){return null!==e})}function o(){return e.find(c.absencePeriods,function(e){return e.current})||c.absencePeriods.reduce(function(e,n){return t(e.end_date).isAfter(n.end_date)?e:n})}function s(){return c.absenceTypes.reduce(function(e,t){return e.title.localeCompare(t.title)?e:t})}function i(e){return e.current?"Current Period ("+e.title+")":e.title}function u(){n.$emit("LeaveBalanceFilters::update",c.filters)}var c=this;c.filters={period_id:null,type_id:null,managed_by:null},c.$onChanges=a,c.labelPeriod=i,c.submitFilters=u}n.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,t){return e.extend({all:function(e,n,a,r,o){return t.getLeaveBalances(this.processFilters(e),n,a,r,o)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){return r.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function p(){return o.all().then(o.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function h(){return s.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function v(){return n.all([m(),p(),h(),g(),q()]).catch(function(e){u.error("Error",e)})}function g(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function b(){return P.loading.report=!0,i.all(w,P.pagination,void 0,void 0,!1).then(function(e){P.report=y(e.list),P.reportCount=e.total}).catch(function(e){u.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function y(n){return n.map(function(n){return n=e.copy(n),n.absence_types=t.indexBy(n.absence_types,function(e){return e.id}),n})}function _(){a.$on("LeaveBalanceFilters::update",C),c.subscribe("LeaveRequest::new",$)}function q(){return f(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function $(e){C(e,w)}function C(e,t){w=t,P.pagination.page=1,A(),P.loadReportCurrentPage()}function A(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+w.type_id})}var w={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.loadReportCurrentPage=b,function(){_(),v().then(function(){P.loading.component=!1})}()}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return f(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(m(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function f(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function m(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(L.selectedPeriod.start_date).clone().startOf("month"),a=n(L.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");L.months=e}function p(){s.$new().$watch(function(){return L.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){L.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){L.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(L)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){L.absencePeriods=t.sortBy(e,"start_date"),L.selectedPeriod=t.find(L.absencePeriods,function(e){return!!e.current})}).then(m).then(T)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){L.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){L.filters.optionValues.regions=e.hrjc_region,L.filters.optionValues.locations=e.hrjc_location,L.filters.optionValues.levelTypes=e.hrjc_level_type,L.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){L.supportData.absenceTypes=e[0],L.supportData.publicHolidays=e[1],L.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,L.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,L.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,L.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return L.injectMonths&&(e=O("destroyed"),L.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){L.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=L.selectedMonths.length?L.months.filter(function(e){return t.includes(L.selectedMonths,e.index)}):L.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function T(){L.selectedMonths=[n().month()]}function S(){return L.roleOverride?r.resolve().then(function(){x=L.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===L.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,L=this;L.absencePeriods=[],L.contacts=[],L.contactIdsToReduceTo=null,L.injectMonths=!1,L.months=[],L.selectedMonths=null,L.selectedPeriod=null,L.showContactName=!1,L.showFilters=!1,L.supportData={},L.loading={calendar:!0,page:!0},L.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},L.labelPeriod=g,L.refresh=D,function(){S().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return L.showFilters?$():t.noop}).then(function(){h()}).then(function(){L.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",M)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function T(){return W.month.loading=!0,a.all([O(),S()]).then(g).then(E).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function L(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function E(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return L(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&T())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return L(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}), -define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return E()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function T(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function L(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function E(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([E(),L()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(T).then(V).then(P).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function f(){return S.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){T[e.label]=t})})).catch(function(){T=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||S.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],T={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=w,S.canRemoveAttachment=A,S.canSubmit=d,S.canUploadMore=f,S.formatDateTime=m,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(S(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function T(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function S(t){var n=U.filters.leaveRequest;return{contact_id:L(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:M(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function L(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function E(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function M(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=E(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=h,U.getAbsenceTypeByID=v,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=x,U.refresh=k,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),O(),P(),T(),R(),I()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),T(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(T)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function T(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){ -function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=B.from_date!==u.request.from_date||B.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&F.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&F.hasExpirationFromAdminSettings,t=F.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return F.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){F.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),k(),l(),I())})})}function D(){u.isMode("view")||(C(),A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function T(){return l(),I(),k()}function S(){return L(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),N?N=!1:I(),k()}function O(e){u.uiOptions.times[e].time=""}function I(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function x(){B=e.cloneDeep(u.request.attributes())}function L(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function E(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){R(!1)})}function M(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function k(){return m()?d().catch(a.resolve):a.resolve()}function j(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var B,N=!u.isMode("create"),F={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onDateChangeExtended=T,u.openToilInDaysAccrualOptionsEditor=E,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=j,function(){x(),L(),M(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Ee.selectedAbsenceType.calculation_unit_name?delete Ee.request[e+"_date_amount"]:delete Ee.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Ee.requestStatuses[_.statusNames.awaitingApproval].value;Te.status_id===e&&e!==Ee.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Le.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Le.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return!Ee.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=D();return Ee.isMode("edit")&&(e=e&&(V()||R())),Ee.canManage&&Ee.requestStatuses&&(e=e&&!!Ee.getStatusFromValue(Ee.newStatusOnSave)),(e=e&&!!Ee.period.id)&&!Ee.isMode("view")}function O(){Ee.isSelfRecord?Ee.request.status_id=Ee.requestStatuses[_.statusNames.awaitingApproval].value:Ee.canManage&&(Ee.request.status_id=Ee.newStatusOnSave||Ee.request.status_id)}function I(){if(Ee.isMode("edit")&&!Ee.isRole("staff")&&"toil"!==F())return Ee.request.calculateBalanceChange(Ee.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ee.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Ee.errors=[]}function L(){return Ee.request.create().then($e).then(function(){me("LeaveRequest::new")})}function E(){ee()&&!Ee.isRole("staff")&&(Ee.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ee.request.delete().then(function(){Ee.dismissModal(),d.publish("LeaveRequest::delete",Ee.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Ee.getStatusFromValue(Ee.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Ee.requestStatuses[e]})}function F(){return Ee.request?Ee.request.request_type:Ee.leaveType||null}function U(){return!Ee.request||e.equals({},Ee.requestStatuses)?[]:Ee.request.status_id?B():N("none")}function H(e){return n.find(Ee.requestStatuses,function(t){return t.value===e})}function W(e){Ee.errors=n.isArray(e)?e:[e],Ee.loading.absenceTypes=!1,Ee.submitting=!1}function V(){return!e.equals(Te,Ee.request.attributes())||Ee.canManage&&Ee.newStatusOnSave}function G(){return Ee.postContactSelection=!0,Ee.staffMemberSelectionComplete=!1,Ee.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Ee.isMode("edit")?be:n.noop).then(function(){Ee.postContactSelection=!1,Ee.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Ee.canManage?m.find(Ee.request.contact_id).then(function(e){Ee.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ee.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Le.push(t)})}function K(){var e,t;Ee.request=Ee.leaveRequest||null,e=F(),t=Ee.initRequestAttributes(),"leave"===e?Ee.request=y.init(t):"sickness"===e?Ee.request=q.init(t):"toil"===e&&(Ee.request=$.init(t))}function X(){var e={};return Ee.request?e=Ee.request.attributes():Ee.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Ee.canManage=Ee.isRole("manager")||Ee.isRole("admin")})}function Z(){(Ee.isRole("admin")||Ee.isMode("create")&&Ee.isRole("manager"))&&(Ee.newStatusOnSave=Ee.requestStatuses[_.statusNames.approved].value)}function ee(){return!Ee.request.status_id||!n.includes(["cancelled","rejected"],H(Ee.request.status_id).name)}function te(e){var t=Ee.getStatusFromValue(Ee.request.status_id);return!!t&&t.name===e}function ne(e){return Ee.request&&Ee.request.request_type===e}function ae(e){return Ee.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Ee.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Ee.loading.entitlements=!0,g.all({contact_id:Ee.request.contact_id,period_id:Ee.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Ee.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Ee.selectedContactId?m.find(Ee.selectedContactId).then(function(e){Ee.managedContacts=[e]}):Ee.isRole("admin")?m.all().then(function(e){Ee.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Ee.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ee.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Ee.request),Ee.errors=[],Ee.dismissModal()}function pe(){["from","to"].forEach(function(e){Ee.request[e+"_date"]=Te[e+"_date"]})}function he(e){if(Ee.absenceTypes=fe(Pe.types,e),!Ee.absenceTypes.length)return r.reject(Ie)}function ve(){Ee.period=n.find(Ee.absencePeriods,function(e){return Ee.isMode("create")?e.current:re(Ee.request,e)})}function ge(){Ee.isMode("create")?(Ee.selectedAbsenceType=Ee.absenceTypes[0],Ee.request.type_id=Ee.selectedAbsenceType.id):Ee.selectedAbsenceType=n.find(Ee.absenceTypes,function(e){return e.id===Ee.request.type_id})}function be(){Te=e.copy(Ee.request.attributes())}function ye(){var e;Ee.request.id?(e=[Ee.requestStatuses[_.statusNames.approved].value,Ee.requestStatuses[_.statusNames.adminApproved].value,Ee.requestStatuses[_.statusNames.rejected].value,Ee.requestStatuses[_.statusNames.cancelled].value],Ee.mode="edit",Ee.isRole("staff")&&e.indexOf(Ee.request.status_id)>-1&&(Ee.mode="view")):Ee.mode="create"}function _e(){var e=Ee.request.status_id;if(!Ee.isMode("view")&&!Ee.submitting)return Ee.submitting=!0,O(),w(),Ee.request.isValid().then(ee()&&I).then(E).then(!Ee.request.change_balance&&pe).then(qe).then(function(){return Ee.isMode("edit")?we():L()}).catch(function(t){Ee.request.status_id=e,t&&W(t)}).finally(function(){Ee.submitting=!1})}function qe(){return r.all(Le.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Ee.request.update().then($e).then(function(){Ee.isRole("manager")?me("LeaveRequest::updatedByManager"):(Ee.isRole("staff")||Ee.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Te={},Se=[],Oe="",Ie="No entitlement",xe="",Le=[],Ee=n.assign(this,f);Ee.absencePeriods=[],Ee.absenceTypes=[],Ee.canManage=!1,Ee.contactName=null,Ee.errors=[],Ee.loading={absenceTypes:!0,entitlements:!0},Ee.managedContacts=[],Ee.mode="",Ee.newStatusOnSave=null,Ee.period={},Ee.postContactSelection=!1,Ee.requestStatuses={},Ee.selectedAbsenceType={},Ee.staffMemberSelectionComplete=!1,Ee.submitting=!1,Ee.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ee.canChangeAbsenceType=T,Ee.canSubmit=S,Ee.closeAlert=x,Ee.deleteLeaveRequest=M,Ee.dismissModal=k,Ee.getStatuses=U,Ee.getStatusFromValue=H,Ee.initAfterContactSelection=G,Ee.initRequestAttributes=X,Ee.isLeaveStatus=te,Ee.isLeaveType=ne,Ee.isMode=ae,Ee.isRole=oe,Ee.submit=_e,Ee.updateAbsenceType=Ae,function(){Ee.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Ee.canManage&&!Ee.isMode("edit")&&le()}).then(function(){if(Ee.selectedContactId&&(Ee.request.contact_id=Ee.selectedContactId),Ee.request.contact_id)return Ee.initAfterContactSelection()}).catch(W).finally(function(){Ee.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}), -define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e){define("leave-absences/manager-leave/modules/config",["common/angular","leave-absences/manager-leave/modules/settings"],function(t){return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/manager-leave/requests"),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","common/services/crm-ang.service","leave-absences/shared/ui-router","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); +!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return U(e)&&e.then&&e.$$promises}if(!U(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!U(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},U(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||F(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!U(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=U(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=F(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:U(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in T)B(T[o])&&(t[o]=T[o](t,T.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=L[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),w.current)}).then(null,function(a){return a===D?T:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function T(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:T(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function L(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function E(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,T(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return U(n)?e+G(n):(n=t.$eval(n),U(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,U=t.isObject,F=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n){function a(e){e.absencePeriods&&c.absencePeriods.length&&(c.filters.period_id=o().id),e.absenceTypes&&c.absenceTypes.length&&(c.filters.type_id=s().id),(e.loggedInContactId||e.userRole)&&(c.filters.managed_by="manager"===c.userRole?c.loggedInContactId:void 0),r()&&c.submitFilters()}function r(){return e.every(c.filters,function(e){return null!==e})}function o(){return e.find(c.absencePeriods,function(e){return e.current})||c.absencePeriods.reduce(function(e,n){return t(e.end_date).isAfter(n.end_date)?e:n})}function s(){return c.absenceTypes.reduce(function(e,t){return e.title.localeCompare(t.title)?e:t})}function i(e){return e.current?"Current Period ("+e.title+")":e.title}function u(){n.$emit("LeaveBalanceFilters::update",c.filters)}var c=this;c.filters={period_id:null,type_id:null,managed_by:null},c.$onChanges=a,c.labelPeriod=i,c.submitFilters=u}n.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,t){return e.extend({all:function(e,n,a,r,o){return t.getLeaveBalances(this.processFilters(e),n,a,r,o)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){return r.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function p(){return o.all().then(o.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function h(){return s.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function v(){return n.all([m(),p(),h(),g(),q()]).catch(function(e){u.error("Error",e)})}function g(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function b(){return P.loading.report=!0,i.all(w,P.pagination,void 0,void 0,!1).then(function(e){P.report=y(e.list),P.reportCount=e.total}).catch(function(e){u.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function y(n){return n.map(function(n){return n=e.copy(n),n.absence_types=t.indexBy(n.absence_types,function(e){return e.id}),n})}function _(){a.$on("LeaveBalanceFilters::update",C),c.subscribe("LeaveRequest::new",$)}function q(){return f(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function $(e){C(e,w)}function C(e,t){w=t,P.pagination.page=1,A(),P.loadReportCurrentPage()}function A(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+w.type_id})}var w={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.loadReportCurrentPage=b,function(){_(),v().then(function(){P.loading.component=!1})}()}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return f(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(m(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function f(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function m(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(L.selectedPeriod.start_date).clone().startOf("month"),a=n(L.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");L.months=e}function p(){s.$new().$watch(function(){return L.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){L.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){L.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(L)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){L.absencePeriods=t.sortBy(e,"start_date"),L.selectedPeriod=t.find(L.absencePeriods,function(e){return!!e.current})}).then(m).then(T)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){L.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){L.filters.optionValues.regions=e.hrjc_region,L.filters.optionValues.locations=e.hrjc_location,L.filters.optionValues.levelTypes=e.hrjc_level_type,L.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){L.supportData.absenceTypes=e[0],L.supportData.publicHolidays=e[1],L.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,L.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,L.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,L.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return L.injectMonths&&(e=O("destroyed"),L.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){L.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=L.selectedMonths.length?L.months.filter(function(e){return t.includes(L.selectedMonths,e.index)}):L.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function T(){L.selectedMonths=[n().month()]}function S(){return L.roleOverride?r.resolve().then(function(){x=L.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===L.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,L=this;L.absencePeriods=[],L.contacts=[],L.contactIdsToReduceTo=null,L.injectMonths=!1,L.months=[],L.selectedMonths=null,L.selectedPeriod=null,L.showContactName=!1,L.showFilters=!1,L.supportData={},L.loading={calendar:!0,page:!0},L.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},L.labelPeriod=g,L.refresh=D,function(){S().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return L.showFilters?$():t.noop}).then(function(){h()}).then(function(){L.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return F[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){U.push(r.$on("LeaveCalendar::showMonths",M)),U.push(i.subscribe("LeaveRequest::new",c)),U.push(i.subscribe("LeaveRequest::edit",j)),U.push(i.subscribe("LeaveRequest::updatedByManager",j)),U.push(i.subscribe("LeaveRequest::delete",h)),U.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function T(){return W.month.loading=!0,a.all([O(),S()]).then(g).then(E).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){F=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),U.map(function(e){e.remove?e.remove():e()})}function L(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function E(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return L(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&T())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return L(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,U=[],F={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}), +define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){U(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return E()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,U("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(F).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function T(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function L(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function E(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(F).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,U("to"))}function U(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function F(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,U("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([E(),L()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(T).then(V).then(P).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function f(){return S.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){T[e.label]=t})})).catch(function(){T=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||S.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],T={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=w,S.canRemoveAttachment=A,S.canSubmit=d,S.canUploadMore=f,S.formatDateTime=m,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){F.filters.leaveRequest.contact_id=null,F.refresh()}function p(){var e=F.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?F.leaveRequests.filter.list.length:F.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(F.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(F.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(F.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(F.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){F.absencePeriods=e.sortBy(t,"start_date"),F.filters.leaveRequest.selectedPeriod=e.find(F.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){F.absenceTypes=e})}function w(e){return(F.isAdmin?r.all(p()):r.leaveManagees(F.contactId,p())).then(function(t){return F.filteredUsers=F.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){F.filters.leaveRequest.leaveStatus!==H&&0===F.leaveRequests.table.list.length&&F.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){F.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:F.pagination,r="filter"===e?{return:["status_id"]}:{};return F.loading[n]=!0,l.all(S(t),a,"from_date DESC",r,!1).then(function(t){F.leaveRequests[e]=t}).catch(function(){F.leaveRequests[e].list=[]}).finally(function(){F.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){F.levelTypes=e})}function T(){return s.valuesOf("hrjc_location").then(function(e){F.locations=e})}function S(t){var n=F.filters.leaveRequest;return{contact_id:L(),managed_by:F.isAdmin&&"me"!==n.assignedTo.type?void 0:F.contactId,status_id:M(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(F.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){F.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){F.leaveRequestStatuses=e.concat(F.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function L(){return F.filteredUsers.length>0&&F.filters.leaveRequest.contact_id?F.filters.leaveRequest.contact_id:{IN:F.filteredUsers.map(function(e){return e.id})}}function E(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function M(e){var t=F.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=E(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(F.filters.leaveRequest.leaveStatus=H),(e<=F.totalNoOfPages()||0===F.totalNoOfPages())&&(F.pagination.page=e,w(n))}function j(e){F.filters.leaveRequest.leaveStatus=e,F.refresh(1,!1,"table")}function B(e){F.filters.leaveRequest.assignedTo=e,F.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){F.refresh()}),f.subscribe("LeaveRequest::new",function(){F.refresh()}),f.subscribe("LeaveRequest::edit",function(){F.refresh()}),f.subscribe("LeaveRequest::delete",function(){F.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){F.refresh()})}function U(){return Math.ceil(F.leaveRequests.table.total/F.pagination.size)}t.debug("Component: manage-leave-requests");var F=this,H={name:"all",label:"All"};F.absencePeriods=[],F.absenceTypes=[],F.filteredUsers=[],F.isFilterExpanded=!1,F.isAdmin=!1,F.leaveRequests={table:{list:[]},filter:{list:[]}},F.leaveRequestStatuses=[H],F.loading={content:!0,page:!0,table:!0},F.pagination={page:1,size:7},F.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],F.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:F.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:F.filtersByAssignee[0]}},F.clearStaffSelection=m,F.countLeaveRequestByStatus=h,F.getAbsenceTypeByID=v,F.getArrayOfSize=g,F.getLeaveStatusByValue=b,F.getNavBadge=y,F.getUserNameByID=q,F.labelPeriod=$,F.openLeavePopup=x,F.refresh=k,F.refreshWithFilter=j,F.refreshWithFilterByAssignee=B,F.totalNoOfPages=U,function(){o(i.permissions.admin.administer).then(function(e){F.isAdmin=e,n.all([C(),A(),O(),P(),T(),R(),I()]).then(function(){F.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),T(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(T)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function T(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){ +function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=U.from_date!==u.request.from_date||U.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&H.hasExpirationFromAdminSettings,t=H.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&u.isCalculationUnit("hours")&&I(),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),B(),l(),x())})})}function D(){u.isMode("view")||(C(),A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function T(){return l(),x(),B()}function S(){return E(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),F?F=!1:x(),B()}function O(e){u.uiOptions.times[e].time=""}function I(){u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours}function x(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function L(){U=e.cloneDeep(u.request.attributes())}function E(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function M(){u.setRequestDateTimesAndDateTypes(),l(),x(),u.isCalculationUnit("hours")?I():u.request.toil_to_accrue=null}function k(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){R(!1)})}function j(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function B(){return m()?d().catch(a.resolve):a.resolve()}function N(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var U,F=!u.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onAbsenceTypeUpdateExtended=M,u.onDateChangeExtended=T,u.openToilInDaysAccrualOptionsEditor=k,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=N,function(){L(),E(),j(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Ee.selectedAbsenceType.calculation_unit_name?delete Ee.request[e+"_date_amount"]:delete Ee.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Ee.requestStatuses[_.statusNames.awaitingApproval].value;Te.status_id===e&&e!==Ee.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Le.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Le.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return!Ee.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=D();return Ee.isMode("edit")&&(e=e&&(V()||R())),Ee.canManage&&Ee.requestStatuses&&(e=e&&!!Ee.getStatusFromValue(Ee.newStatusOnSave)),(e=e&&!!Ee.period.id)&&!Ee.isMode("view")}function O(){Ee.isSelfRecord?Ee.request.status_id=Ee.requestStatuses[_.statusNames.awaitingApproval].value:Ee.canManage&&(Ee.request.status_id=Ee.newStatusOnSave||Ee.request.status_id)}function I(){if(Ee.isMode("edit")&&!Ee.isRole("staff")&&"toil"!==U())return Ee.request.calculateBalanceChange(Ee.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ee.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Ee.errors=[]}function L(){return Ee.request.create().then($e).then(function(){me("LeaveRequest::new")})}function E(){ee()&&!Ee.isRole("staff")&&(Ee.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ee.request.delete().then(function(){Ee.dismissModal(),d.publish("LeaveRequest::delete",Ee.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=U();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Ee.getStatusFromValue(Ee.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Ee.requestStatuses[e]})}function U(){return Ee.request?Ee.request.request_type:Ee.leaveType||null}function F(){return!Ee.request||e.equals({},Ee.requestStatuses)?[]:Ee.request.status_id?B():N("none")}function H(e){return n.find(Ee.requestStatuses,function(t){return t.value===e})}function W(e){Ee.errors=n.isArray(e)?e:[e],Ee.loading.absenceTypes=!1,Ee.submitting=!1}function V(){return!e.equals(Te,Ee.request.attributes())||Ee.canManage&&Ee.newStatusOnSave}function G(){return Ee.postContactSelection=!0,Ee.staffMemberSelectionComplete=!1,Ee.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Ee.isMode("edit")?be:n.noop).then(function(){Ee.postContactSelection=!1,Ee.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Ee.canManage?m.find(Ee.request.contact_id).then(function(e){Ee.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ee.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Le.push(t)})}function K(){var e,t;Ee.request=Ee.leaveRequest||null,e=U(),t=Ee.initRequestAttributes(),"leave"===e?Ee.request=y.init(t):"sickness"===e?Ee.request=q.init(t):"toil"===e&&(Ee.request=$.init(t))}function X(){var e={};return Ee.request?e=Ee.request.attributes():Ee.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Ee.canManage=Ee.isRole("manager")||Ee.isRole("admin")})}function Z(){(Ee.isRole("admin")||Ee.isMode("create")&&Ee.isRole("manager"))&&(Ee.newStatusOnSave=Ee.requestStatuses[_.statusNames.approved].value)}function ee(){return!Ee.request.status_id||!n.includes(["cancelled","rejected"],H(Ee.request.status_id).name)}function te(e){var t=Ee.getStatusFromValue(Ee.request.status_id);return!!t&&t.name===e}function ne(e){return Ee.request&&Ee.request.request_type===e}function ae(e){return Ee.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Ee.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Ee.loading.entitlements=!0,g.all({contact_id:Ee.request.contact_id,period_id:Ee.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Ee.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Ee.selectedContactId?m.find(Ee.selectedContactId).then(function(e){Ee.managedContacts=[e]}):Ee.isRole("admin")?m.all().then(function(e){Ee.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Ee.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ee.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Ee.request),Ee.errors=[],Ee.dismissModal()}function pe(){["from","to"].forEach(function(e){Ee.request[e+"_date"]=Te[e+"_date"]})}function he(e){if(Ee.absenceTypes=fe(Pe.types,e),!Ee.absenceTypes.length)return r.reject(Ie)}function ve(){Ee.period=n.find(Ee.absencePeriods,function(e){return Ee.isMode("create")?e.current:re(Ee.request,e)})}function ge(){Ee.isMode("create")?(Ee.selectedAbsenceType=Ee.absenceTypes[0],Ee.request.type_id=Ee.selectedAbsenceType.id):Ee.selectedAbsenceType=n.find(Ee.absenceTypes,function(e){return e.id===Ee.request.type_id})}function be(){Te=e.copy(Ee.request.attributes())}function ye(){var e;Ee.request.id?(e=[Ee.requestStatuses[_.statusNames.approved].value,Ee.requestStatuses[_.statusNames.adminApproved].value,Ee.requestStatuses[_.statusNames.rejected].value,Ee.requestStatuses[_.statusNames.cancelled].value],Ee.mode="edit",Ee.isRole("staff")&&e.indexOf(Ee.request.status_id)>-1&&(Ee.mode="view")):Ee.mode="create"}function _e(){var e=Ee.request.status_id;if(!Ee.isMode("view")&&!Ee.submitting)return Ee.submitting=!0,O(),w(),Ee.request.isValid().then(ee()&&I).then(E).then(!Ee.request.change_balance&&pe).then(qe).then(function(){return Ee.isMode("edit")?we():L()}).catch(function(t){Ee.request.status_id=e,t&&W(t)}).finally(function(){Ee.submitting=!1})}function qe(){return r.all(Le.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Ee.request.update().then($e).then(function(){Ee.isRole("manager")?me("LeaveRequest::updatedByManager"):(Ee.isRole("staff")||Ee.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Te={},Se=[],Oe="",Ie="No entitlement",xe="",Le=[],Ee=n.assign(this,f);Ee.absencePeriods=[],Ee.absenceTypes=[],Ee.canManage=!1,Ee.contactName=null,Ee.errors=[],Ee.loading={absenceTypes:!0,entitlements:!0},Ee.managedContacts=[],Ee.mode="",Ee.newStatusOnSave=null,Ee.period={},Ee.postContactSelection=!1,Ee.requestStatuses={},Ee.selectedAbsenceType={},Ee.staffMemberSelectionComplete=!1,Ee.submitting=!1,Ee.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ee.canChangeAbsenceType=T,Ee.canSubmit=S,Ee.closeAlert=x,Ee.deleteLeaveRequest=M,Ee.dismissModal=k,Ee.getStatuses=F,Ee.getStatusFromValue=H,Ee.initAfterContactSelection=G,Ee.initRequestAttributes=X,Ee.isLeaveStatus=te,Ee.isLeaveType=ne,Ee.isMode=ae,Ee.isRole=oe,Ee.submit=_e,Ee.updateAbsenceType=Ae,function(){Ee.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Ee.canManage&&!Ee.isMode("edit")&&le()}).then(function(){if(Ee.selectedContactId&&(Ee.request.contact_id=Ee.selectedContactId),Ee.request.contact_id)return Ee.initAfterContactSelection()}).catch(W).finally(function(){Ee.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){ +return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e){define("leave-absences/manager-leave/modules/config",["common/angular","leave-absences/manager-leave/modules/settings"],function(t){return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/manager-leave/requests"),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","common/services/crm-ang.service","leave-absences/shared/ui-router","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js index 020ba2588d8..0228c260520 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js @@ -6,9 +6,9 @@ */ -!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[m]),c[r[m]]=e[r[m]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&f(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,f),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),f.$$values=b,f.$$promises=f.$$promises||!0,delete f.$$inheritedValues,c.resolve(b))}function u(e){f.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),f=c.promise,g=f.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),f;o.$$inheritedValues&&r(b,m(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,m(o.$$values,h)),f.$$inheritedValues=m(o.$$values,h),i()):(o.$$inheritedValues&&(f.$$inheritedValues=m(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(f.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),m=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(m++,g[e].then(function(t){b[e]=t,--m||l()},c))}),m||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return f}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(m,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",m=0,f=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),f.push(g.segment),m=c.lastIndex;y=e.substring(m);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,m+_),q.length>0)for(m=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),m=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",f.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=f[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:m}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,m=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(m=e),m},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(f(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function m(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),f(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:m})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(D.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!D[r])return f(r,t.self);for(var o in R)B(R[o])&&(t[o]=R[o](t,R.$delegates[o]));return D[n]=t,!t[T]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){A.$current.navigable==t&&c(e,n)||A.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=A.$current.name.split("."),a=0,r=t.length;a=D;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=D;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.$current=t,A.current=t.self,A.params=n,V(A.params,f),A.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),A.current)}).then(null,function(a){return a===P?R:A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},A.is=function(e,t,a){a=W({relative:A.$current},a||{});var r=m(e,a.relative);return j(r)?A.$current===r&&(!t||c(r.params.$$values(t),f)):n},A.includes=function(e,t,a){if(a=W({relative:A.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=A.$current.name}var r=m(e,a.relative);if(!j(r))return n;if(!j(A.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(m&&(m.remove(),m=null),p&&(p.$destroy(),p=null),f){var e=f.data("$uiViewAnim");b.leave(f,function(){e.$$animLeave.resolve(),m=null}),m=f,f=null}}function d(s){var d,m=P(n,c,i,r),y=m&&e.$current&&e.$current.locals[m];if(s||y!==h){d=n.$new(),h=e.$current.locals[m],d.$emit("$viewContentLoading",m);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});f=_,p=d,p.$emit("$viewContentLoaded",m),p.$eval(v)}}var m,f,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function D(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=P(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var m=t.extend({},d);o[d.$$resolveAs]=m;var f=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=m),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}f(o)}}}}}function P(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function T(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function R(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:R(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=T(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],m=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var f=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),m&&m(),d&&(m=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&f(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),f(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){m.state=t[0],m.params=t[1],m.options=t[2],m.href=e.href(m.state,m.params,m.options),f&&f(),c&&(f=c.$$addStateInfo(m.state,m.params)),m.href&&r.$set(u.attr,m.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",m={state:null,params:null,options:null,href:null},f=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return m}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function L(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,R(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function m(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,m){function f(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(D(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||T()})}function h(e){E.injectMonths=!0,O("injected").then(function(){T(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(f).then(R)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function w(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function D(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function P(e){ -e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(A).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function T(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function R(){E.selectedMonths=[n().month()]}function S(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([m(i.permissions.admin.administer),m(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=P,function(){S().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),w()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function m(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?f():p()}function f(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),m(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function m(e){return U[e]}function f(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",M)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function w(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function D(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function P(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function T(){return[P(u.statusNames.approved),P(u.statusNames.adminApproved),P(u.statusNames.awaitingApproval),P(u.statusNames.moreInformationRequired)]}function R(){return W.month.loading=!0,a.all([O(),S()]).then(g).then(L).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:T()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=m(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?w(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function L(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&R())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=D(e);t&&(h(t),-1!==T().indexOf(e.status_id)&&c(e))}function B(e){return a.all(A(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=f,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return L()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(A).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function w(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(A)}function A(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function D(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():w()}function P(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function T(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function R(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function L(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(A).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,f(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=A,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),T(),te.initChildController().then(function(){return s.all([L(),E()])}).then(!te.isMode("create")&&P).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(R).then(V).then(D).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(A).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function m(){return S.getFilesAmount()0?P.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(P.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){R[e.label]=t})})).catch(function(){R=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){P=e})}function w(e){return!e.attachment_id||S.canManage}function A(){e.forEach(T,function(e){e()})}function D(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var P=[],T=[],R={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=A,S.canRemoveAttachment=w,S.canSubmit=d,S.canUploadMore=m,S.formatDateTime=f,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,r,o,s,i,u,c,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){k(e),H.sections.other.open&&f(e,H.sections.other)}function h(){Object.values(H.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):H.refresh()}function g(t){t.dataIndex=e.indexBy(t.data,"id")}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function y(){return o.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.selectedPeriod=e.find(H.absencePeriods,function(e){return!0===e.current})})}function _(){return s.all().then(s.loadCalculationUnits).then(function(t){H.absenceTypes=t,H.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return P("approved",{status_id:F(m.statusNames.approved)})}function $(){return n.all([u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,null,!0),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.approved)]),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){H.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function C(){return i.all({contact_id:H.contactId,period_id:H.selectedPeriod.id},!0).then(function(e){H.entitlements=e}).then(function(){H.absenceTypesFiltered=H.absenceTypes.filter(function(t){var n=e.find(H.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function w(){return i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id},H.entitlements).then(function(){return E(H.entitlements)}).then(function(e){H.sections.entitlements.data=e})}function A(){return n.all([i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id,expired:!0}),D({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:E(e[0]),expiredTOILS:L(e[1].list)})}).then(function(t){ -H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function D(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function P(e,t){return D(t).then(function(t){H.sections[e].data=t.list})}function T(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(I))}function R(){return P("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function S(){return P("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function O(){return P("holidays",{public_holiday:!0})}function I(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function x(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function E(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function L(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){k(e)})}function k(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([C(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([T(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&I(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:k,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([x(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([C(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return D(n,e),e})):r.reject([])}function f(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),R(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(w)).then(function(){["from","to"].forEach(function(e){b(e),T(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(R)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&T(e,!0))})}function $(e,t){return m(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return w(e).then(function(){T(e,!0)})})}function w(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function A(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function D(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function P(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),w("from").then(function(){T("from",!0)})):r.resolve()}function T(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function R(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?w("from").then(function(){T("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=A,s.setDaysSelectionModeExtended=P}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function m(){return!!u.request.toil_to_accrue}function f(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=B.from_date!==u.request.from_date||B.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&F.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&F.hasExpirationFromAdminSettings,t=F.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return F.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){F.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(T)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function w(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){u.isCalculationUnit("hours")&&e!==t&&(u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function A(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function D(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),k(),l(),I())})})}function P(){u.isMode("view")||(C(),w(),D())}function T(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function R(){return l(),I(),k()}function S(){return E(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),N?N=!1:I(),k()}function O(e){u.uiOptions.times[e].time=""}function I(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function x(){B=e.cloneDeep(u.request.attributes())}function E(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function L(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){T(!1)})}function M(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function k(){return f()?d().catch(a.resolve):a.resolve()}function j(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var B,N=!u.isMode("create"),F={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=m,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=A,u.initWatchersExtended=P,u.onDateChangeExtended=R,u.openToilInDaysAccrualOptionsEditor=L,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=j,function(){x(),E(),M(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,m,f,p,h,v,g,b,y,_,q,$,C){function w(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function A(){["from","to"].forEach(w)}function D(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Re.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=P();return Le.isMode("edit")&&(e=e&&(V()||T())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function O(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function I(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==F())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){fe("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(Pe[e],function(e){return Le.requestStatuses[e]})}function F(){return Le.request?Le.request.request_type:Le.leaveType||null}function U(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Re,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Pe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Pe.awaiting_approval=e,Pe.more_information_required=e,Pe.rejected=e,Pe.approved=e,Pe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?f.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Te++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=F(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){De={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:De.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Le.selectedContactId?f.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?f.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):f.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){D(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Re[e+"_date"]})}function he(e){if(Le.absenceTypes=me(De.types,e),!Le.absenceTypes.length)return r.reject(Ie)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Re=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,O(),A(),Le.request.isValid().then(ee()&&I).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?Ae():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Te&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Te>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function we(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?fe("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var De,Pe={},Te=0,Re={},Se=[],Oe="",Ie="No entitlement",xe="",Ee=[],Le=n.assign(this,m);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=R,Le.canSubmit=S,Le.closeAlert=x,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=U,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=we,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM), +!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[m]),c[r[m]]=e[r[m]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&f(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,f),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),f.$$values=b,f.$$promises=f.$$promises||!0,delete f.$$inheritedValues,c.resolve(b))}function u(e){f.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),f=c.promise,g=f.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),f;o.$$inheritedValues&&r(b,m(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,m(o.$$values,h)),f.$$inheritedValues=m(o.$$values,h),i()):(o.$$inheritedValues&&(f.$$inheritedValues=m(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(f.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),m=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(m++,g[e].then(function(t){b[e]=t,--m||l()},c))}),m||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return f}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(m,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",m=0,f=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),f.push(g.segment),m=c.lastIndex;y=e.substring(m);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,m+_),q.length>0)for(m=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),m=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",f.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=f[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:m}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,m=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(m=e),m},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(f(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function m(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),f(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:m})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(D.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!D[r])return f(r,t.self);for(var o in R)B(R[o])&&(t[o]=R[o](t,R.$delegates[o]));return D[n]=t,!t[T]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){A.$current.navigable==t&&c(e,n)||A.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=A.$current.name.split("."),a=0,r=t.length;a=D;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=D;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.$current=t,A.current=t.self,A.params=n,V(A.params,f),A.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),A.current)}).then(null,function(a){return a===P?R:A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},A.is=function(e,t,a){a=W({relative:A.$current},a||{});var r=m(e,a.relative);return j(r)?A.$current===r&&(!t||c(r.params.$$values(t),f)):n},A.includes=function(e,t,a){if(a=W({relative:A.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=A.$current.name}var r=m(e,a.relative);if(!j(r))return n;if(!j(A.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(m&&(m.remove(),m=null),p&&(p.$destroy(),p=null),f){var e=f.data("$uiViewAnim");b.leave(f,function(){e.$$animLeave.resolve(),m=null}),m=f,f=null}}function d(s){var d,m=P(n,c,i,r),y=m&&e.$current&&e.$current.locals[m];if(s||y!==h){d=n.$new(),h=e.$current.locals[m],d.$emit("$viewContentLoading",m);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});f=_,p=d,p.$emit("$viewContentLoaded",m),p.$eval(v)}}var m,f,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function D(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=P(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var m=t.extend({},d);o[d.$$resolveAs]=m;var f=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=m),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}f(o)}}}}}function P(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function T(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function R(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function x(e,t){return{relative:R(e)||t.$current,inherit:!0}}function I(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=T(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],m=null;c.options=W(x(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var f=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),m&&m(),d&&(m=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&f(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),f(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){m.state=t[0],m.params=t[1],m.options=t[2],m.href=e.href(m.state,m.params,m.options),f&&f(),c&&(f=c.$$addStateInfo(m.state,m.params)),m.href&&r.$set(u.attr,m.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",m={state:null,params:null,options:null,href:null},f=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return m}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function L(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,R(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function m(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,m){function f(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(D(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||T()})}function h(e){E.injectMonths=!0,O("injected").then(function(){T(e)}).then(function(){E.loading.calendar=!1})}function v(){x=a("LeaveCalendar"+t.capitalize(I)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(f).then(R)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return x.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function w(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function D(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function P(e){ +e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(A).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function T(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function R(){E.selectedMonths=[n().month()]}function S(){return E.roleOverride?r.resolve().then(function(){I=E.roleOverride}):r.all([m(i.permissions.admin.administer),m(i.permissions.ssp.manage)]).then(function(e){I=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var x,I,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=P,function(){S().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),w()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function m(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?f():p()}function f(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),m(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function m(e){return U[e]}function f(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){x(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",M)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function w(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function D(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function P(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function T(){return[P(u.statusNames.approved),P(u.statusNames.adminApproved),P(u.statusNames.awaitingApproval),P(u.statusNames.moreInformationRequired)]}function R(){return W.month.loading=!0,a.all([O(),S()]).then(g).then(L).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:T()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function x(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function I(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=m(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?w(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function L(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&R())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=D(e);t&&(h(t),-1!==T().indexOf(e.status_id)&&c(e))}function B(e){return a.all(A(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=I,W.contactsList=f,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return L()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(A).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function w(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(A)}function A(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function D(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():w()}function P(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function T(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function R(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function x(e){return te.request.request_type===e}function I(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function L(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(A).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,f(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(x("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||x("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=A,te.isCalculationUnit=O,te.isLeaveType=x,te.isNotWorkingDay=I,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),T(),te.initChildController().then(function(){return s.all([L(),E()])}).then(!te.isMode("create")&&P).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(R).then(V).then(D).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(A).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function m(){return S.getFilesAmount()0?P.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(P.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){R[e.label]=t})})).catch(function(){R=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){P=e})}function w(e){return!e.attachment_id||S.canManage}function A(){e.forEach(T,function(e){e()})}function D(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var P=[],T=[],R={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=A,S.canRemoveAttachment=w,S.canSubmit=d,S.canUploadMore=m,S.formatDateTime=f,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,r,o,s,i,u,c,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){k(e),H.sections.other.open&&f(e,H.sections.other)}function h(){Object.values(H.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):H.refresh()}function g(t){t.dataIndex=e.indexBy(t.data,"id")}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function y(){return o.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.selectedPeriod=e.find(H.absencePeriods,function(e){return!0===e.current})})}function _(){return s.all().then(s.loadCalculationUnits).then(function(t){H.absenceTypes=t,H.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return P("approved",{status_id:F(m.statusNames.approved)})}function $(){return n.all([u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,null,!0),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.approved)]),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){H.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function C(){return i.all({contact_id:H.contactId,period_id:H.selectedPeriod.id},!0).then(function(e){H.entitlements=e}).then(function(){H.absenceTypesFiltered=H.absenceTypes.filter(function(t){var n=e.find(H.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function w(){return i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id},H.entitlements).then(function(){return E(H.entitlements)}).then(function(e){H.sections.entitlements.data=e})}function A(){return n.all([i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id,expired:!0}),D({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:E(e[0]),expiredTOILS:L(e[1].list)})}).then(function(t){ +H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function D(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function P(e,t){return D(t).then(function(t){H.sections[e].data=t.list})}function T(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(x))}function R(){return P("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function S(){return P("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function O(){return P("holidays",{public_holiday:!0})}function x(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function I(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function E(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function L(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){k(e)})}function k(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([C(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([T(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&x(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:k,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([I(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([C(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return D(n,e),e})):r.reject([])}function f(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),R(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(w)).then(function(){["from","to"].forEach(function(e){b(e),T(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(R)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&T(e,!0))})}function $(e,t){return m(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return w(e).then(function(){T(e,!0)})})}function w(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function A(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function D(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function P(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),w("from").then(function(){T("from",!0)})):r.resolve()}function T(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function R(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?w("from").then(function(){T("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=A,s.setDaysSelectionModeExtended=P}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function m(){return!!u.request.toil_to_accrue}function f(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=F.from_date!==u.request.from_date||F.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&H.hasExpirationFromAdminSettings,t=H.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(T)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function w(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&u.isCalculationUnit("hours")&&x(),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function A(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function D(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),B(),l(),I())})})}function P(){u.isMode("view")||(C(),w(),D())}function T(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function R(){return l(),I(),B()}function S(){return L(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),U?U=!1:I(),B()}function O(e){u.uiOptions.times[e].time=""}function x(){u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours}function I(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function E(){F=e.cloneDeep(u.request.attributes())}function L(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function M(){u.setRequestDateTimesAndDateTypes(),l(),I(),u.isCalculationUnit("hours")?x():u.request.toil_to_accrue=null}function k(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){T(!1)})}function j(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function B(){return f()?d().catch(a.resolve):a.resolve()}function N(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var F,U=!u.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=m,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=A,u.initWatchersExtended=P,u.onAbsenceTypeUpdateExtended=M,u.onDateChangeExtended=R,u.openToilInDaysAccrualOptionsEditor=k,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=N,function(){E(),L(),j(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,m,f,p,h,v,g,b,y,_,q,$,C){function w(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function A(){["from","to"].forEach(w)}function D(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Re.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=P();return Le.isMode("edit")&&(e=e&&(V()||T())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function O(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function x(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==F())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function I(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){fe("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(Pe[e],function(e){return Le.requestStatuses[e]})}function F(){return Le.request?Le.request.request_type:Le.leaveType||null}function U(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Re,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==xe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Pe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Pe.awaiting_approval=e,Pe.more_information_required=e,Pe.rejected=e,Pe.approved=e,Pe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?f.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Te++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=F(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:Oe}),e}function Q(){if(Ie="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Ie="admin")}).then(function(){return"staff"===Ie&&u(_.permissions.ssp.manage).then(function(e){e&&(Ie="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Ie===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){De={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:De.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Le.selectedContactId?f.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?f.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):f.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){D(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Re[e+"_date"]})}function he(e){if(Le.absenceTypes=me(De.types,e),!Le.absenceTypes.length)return r.reject(xe)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Re=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,O(),A(),Le.request.isValid().then(ee()&&x).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?Ae():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Te&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Te>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function we(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?fe("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var De,Pe={},Te=0,Re={},Se=[],Oe="",xe="No entitlement",Ie="",Ee=[],Le=n.assign(this,m);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=R,Le.canSubmit=S,Le.closeAlert=I,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=U,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=we,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM), define("leave-absences/my-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/models/option-group","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/my-leave/components/my-leave-container.component","leave-absences/my-leave/modules/config"],function(e){return e.module("my-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.mocks","common.models","common.services","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","my-leave.components","my-leave.config"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/my-leave":n+"/my-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/my-leave/app"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-my-leave]"),["my-leave"])})})}(CRM,require),define("my-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js index b16da45064c..f805af1e5af 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller.js @@ -29,6 +29,7 @@ define([ detailsController.initChildController = initChildController; detailsController.initTimesExtended = initTimes; detailsController.initWatchersExtended = initWatchers; + detailsController.onAbsenceTypeUpdateExtended = onAbsenceTypeUpdateHandler; detailsController.onDateChangeExtended = onDateChangeHandler; detailsController.openToilInDaysAccrualOptionsEditor = openToilInDaysAccrualOptionsEditor; detailsController.resetUIInputsExtended = resetTime; @@ -283,9 +284,8 @@ define([ return detailsController.uiOptions.toil_duration_in_hours; }, function (oldValue, newValue) { - if (detailsController.isCalculationUnit('hours') && oldValue !== newValue) { - detailsController.request.toil_to_accrue = - detailsController.uiOptions.toil_duration_in_hours; + if (oldValue !== newValue && detailsController.isCalculationUnit('hours')) { + setDefaultAccrualValue(); } detailsController.request.toil_duration = @@ -397,6 +397,14 @@ define([ detailsController.uiOptions.times[dateType].time = ''; } + /** + * Sets default accrual value based on the duration. + */ + function setDefaultAccrualValue () { + detailsController.request.toil_to_accrue = + detailsController.uiOptions.toil_duration_in_hours; + } + /** * Sets default duration as a maximum allowed duration value */ @@ -429,6 +437,22 @@ define([ } } + /** + * Handles absence type change. Calculates TOIL duration and sets its default value. + * Sets accrual value if unit is in hours, otherwise, flushes it. + */ + function onAbsenceTypeUpdateHandler () { + detailsController.setRequestDateTimesAndDateTypes(); + calculateDuration(); + setDefaultDuration(); + + if (detailsController.isCalculationUnit('hours')) { + setDefaultAccrualValue(); + } else { + detailsController.request.toil_to_accrue = null; + } + } + /** * Opens the CRM modal that allows to edit TOIL in days amounts options * and reloads these options in the Leave Request Modal diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js index 7b58ff41874..85b5be7bdb3 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-toil.controller.spec.js @@ -230,13 +230,31 @@ define([ }); }); - describe('when the request is in hours', function () { + describe('when the unit changes to "hours" because the absence type changed', function () { + var expectedTOILDurationAndAccrual; + beforeEach(function () { - controller.selectedAbsenceType.calculation_unit_name = 'hours'; + changeSelectedAbsenceTypeUnit('hours'); + + expectedTOILDurationAndAccrual = + moment.duration(moment(controller.request.to_date) + .diff(controller.request.from_date)).asHours(); + }); + + it('recalculates TOIL duration', function () { + expect(controller.uiOptions.max_toil_duration_and_accrual).toBe( + expectedTOILDurationAndAccrual); + }); + + it('recalculates TOIL accrual value', function () { + expect(controller.request.toil_to_accrue).toBe( + expectedTOILDurationAndAccrual); }); + }); - afterEach(function () { - controller.selectedAbsenceType.calculation_unit_name = 'days'; + describe('when the request is in hours', function () { + beforeEach(function () { + changeSelectedAbsenceTypeUnit('hours'); }); describe('when duration value has been customised', function () { @@ -250,6 +268,27 @@ define([ expect(controller.request.toil_to_accrue).toBe(controller.uiOptions.toil_duration_in_hours); }); }); + + describe('when the unit changes to "days" because the absence type changed', function () { + var expectedTOILDurationAndAccrual; + + beforeEach(function () { + changeSelectedAbsenceTypeUnit('days'); + + expectedTOILDurationAndAccrual = + moment.duration(moment(controller.request.to_date) + .diff(controller.request.from_date)).asHours(); + }); + + it('recalculates TOIL duration', function () { + expect(controller.uiOptions.max_toil_duration_and_accrual).toBe( + expectedTOILDurationAndAccrual); + }); + + it('flushes TOIL accrual value', function () { + expect(controller.request.toil_to_accrue).toBe(null); + }); + }); }); }); @@ -778,6 +817,18 @@ define([ }); }); + /** + * Changes selected absence type unit + * + * @param {String} unit days|hours + */ + function changeSelectedAbsenceTypeUnit (unit) { + controller.selectedAbsenceType.calculation_unit_name = unit; + + controller.onAbsenceTypeUpdateExtended(); + $rootScope.$digest(); + } + /** * Compiles and initializes the component's controller. It returns the * parameters used to initialize the controller plus default parameter From f8022d7f8d3a5454e65fb908954fca881099175d Mon Sep 17 00:00:00 2001 From: Alessandro Verdura Date: Fri, 13 Apr 2018 15:27:59 +0200 Subject: [PATCH 128/203] PCHR-3523: Add script --- bin/apply-fork-patch.sh | 179 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100755 bin/apply-fork-patch.sh diff --git a/bin/apply-fork-patch.sh b/bin/apply-fork-patch.sh new file mode 100755 index 00000000000..67db95bdc1f --- /dev/null +++ b/bin/apply-fork-patch.sh @@ -0,0 +1,179 @@ +#!/bin/bash + +API_URL_BASE="https://api.github.com/repos/compucorp/civicrm-core" +LAST_REMOTE_COMMIT_FILE="last-remote-commit.json" +META_FILE="fork-patch-meta.json" +PATCH_FILE="fork-patch.diff" + +civiRoot="" + +####################################### +# Applies the patch on the core files +# +# Globals: +# $civiRoot +# $PATCH_FILE +# Arguments: +# None +# Returns: +# None +####################################### +applyPatch () { + (cd "$civiRoot" && git apply --whitespace=nowarn "$PATCH_FILE") +} + +####################################### +# Creates a temporary file containing the info related to the last +# commit of the given branch, fetched via the GitHub api +# +# Globals: +# $API_URL_BASE +# $civiRoot +# $PATCH_FILE +# Arguments: +# $1 name of the branch +# Returns: +# None +####################################### +createLastRemoteCommitFile () { + curl "$API_URL_BASE/commits/$1" -s > "$civiRoot/$LAST_REMOTE_COMMIT_FILE" +} + +####################################### +# Creates a diff patch file by sending a request to the given GitHub API url +# +# Globals: +# $API_URL_BASE +# $civiRoot +# $PATCH_FILE +# Arguments: +# $1 base commit of the comparison +# $2 head commit of the comparison +# Returns: +# None +####################################### +createPatch () { + curl "$API_URL_BASE/compare/$1...$2" -s -H "Accept: application/vnd.github.v3.diff" > "$civiRoot/$PATCH_FILE" +} + +####################################### +# Reads or writes a property's value from a JSON file +# +# Globals: +# None +# Arguments: +# $1 JSON file +# $2 property name +# $3 new value of the property (optional) +# Returns: +# None/String +####################################### +JSONValue () { + if ! [ -z "$3" ]; then + JSONValueWrite "$1" "$2" "$3" + else + JSONValueRead "$1" "$2" + fi +} + +####################################### +# Uses Python to read the property's value of a JSON file +# +# Globals: +# None +# Arguments: +# $1 JSON file +# $2 property name +# Returns: +# String +## +JSONValueRead () { + python -c "import sys, json; print json.load(sys.stdin)['$2']" < "$1" +} + +####################################### +# Uses Python to update the property's value of a JSON file +# The resulting JSON then overwrites the old content of the file +# +# Globals: +# None +# Arguments: +# $1 JSON file +# $2 property name +# $3 new value of the property +# Returns: +# None +####################################### +JSONValueWrite () { + updatedJSON=$(python -c "import sys, json; \ + jsonFile = json.load(sys.stdin); \ + jsonFile['$2'] = '$3'; \ + print json.dumps(jsonFile, indent=2);" < "$1") + + echo "$updatedJSON" > "$1" +} + +####################################### +# Checks if the meta file exists or not +# +# Globals: +# $civiRoot +# $META_FILE +# Arguments: +# None +# Returns: +# Integer +####################################### +metaFileExists () { + if [ -e "$civiRoot/$META_FILE" ]; then return 0; else return 1; fi +} + +####################################### +# Returns the civicrm root path +# +# Globals: +# None +# Arguments: +# None +# Returns: +# String +####################################### +setCivicrmRootPath () { + civiRoot=$(drush eval "echo \\Civi::paths()->getPath('[civicrm.root]/.')") +} + +####################################### +# Updates the reference, in the META_FILE, to the last commit patched onto +# the core files +# +# Globals: +# $LAST_REMOTE_COMMIT_FILE +# $civiRoot +# $META_FILE +# Arguments: +# None +# Returns: +# None +####################################### +updateLastCommitPatched () { + sha=$(JSONValue "$civiRoot/$LAST_REMOTE_COMMIT_FILE" 'sha') + + JSONValue "$civiRoot/$META_FILE" "last-fork-commit-patched" "$sha" +} + +# --------------- + +setCivicrmRootPath +if ! metaFileExists; then exit 0; fi + +civiVersion=$(JSONValue "$civiRoot/$META_FILE" 'civi-version') +lastCommitPatched=$(JSONValue "$civiRoot/$META_FILE" "last-fork-commit-patched") + +patchesBranch="$civiVersion-patches" +[ ! -z "$lastCommitPatched" ] && baseHead=$lastCommitPatched || baseHead=$civiVersion + +createPatch "$baseHead" "$patchesBranch" +applyPatch && rm "$civiRoot/$PATCH_FILE" + +createLastRemoteCommitFile "$patchesBranch" +updateLastCommitPatched && rm "$civiRoot/$LAST_REMOTE_COMMIT_FILE" From a4c6e11ac0b13631454d25b44a4059d3991cafde Mon Sep 17 00:00:00 2001 From: Alessandro Verdura Date: Fri, 13 Apr 2018 15:45:44 +0200 Subject: [PATCH 129/203] PCHR-3523: Apply patch only if the file is not empty --- bin/apply-fork-patch.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bin/apply-fork-patch.sh b/bin/apply-fork-patch.sh index 67db95bdc1f..67410c7ca0e 100755 --- a/bin/apply-fork-patch.sh +++ b/bin/apply-fork-patch.sh @@ -156,7 +156,7 @@ setCivicrmRootPath () { # None ####################################### updateLastCommitPatched () { - sha=$(JSONValue "$civiRoot/$LAST_REMOTE_COMMIT_FILE" 'sha') + sha=$(JSONValue "$civiRoot/$LAST_REMOTE_COMMIT_FILE" "sha") JSONValue "$civiRoot/$META_FILE" "last-fork-commit-patched" "$sha" } @@ -166,14 +166,19 @@ updateLastCommitPatched () { setCivicrmRootPath if ! metaFileExists; then exit 0; fi -civiVersion=$(JSONValue "$civiRoot/$META_FILE" 'civi-version') +civiVersion=$(JSONValue "$civiRoot/$META_FILE" "civi-version") lastCommitPatched=$(JSONValue "$civiRoot/$META_FILE" "last-fork-commit-patched") patchesBranch="$civiVersion-patches" [ ! -z "$lastCommitPatched" ] && baseHead=$lastCommitPatched || baseHead=$civiVersion createPatch "$baseHead" "$patchesBranch" -applyPatch && rm "$civiRoot/$PATCH_FILE" -createLastRemoteCommitFile "$patchesBranch" -updateLastCommitPatched && rm "$civiRoot/$LAST_REMOTE_COMMIT_FILE" +if [ -s $civiRoot/$PATCH_FILE ]; then # if the patch is not empty... + applyPatch + + createLastRemoteCommitFile "$patchesBranch" + updateLastCommitPatched && rm "$civiRoot/$LAST_REMOTE_COMMIT_FILE" +fi + +rm "$civiRoot/$PATCH_FILE" From 0ba1cc9b0ce892de0570df0fdb5cef0b19fcd385 Mon Sep 17 00:00:00 2001 From: Alessandro Verdura Date: Fri, 13 Apr 2018 16:05:04 +0200 Subject: [PATCH 130/203] PCHR-3523: Add messages --- bin/apply-fork-patch.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/bin/apply-fork-patch.sh b/bin/apply-fork-patch.sh index 67410c7ca0e..dfb45d839d0 100755 --- a/bin/apply-fork-patch.sh +++ b/bin/apply-fork-patch.sh @@ -164,7 +164,11 @@ updateLastCommitPatched () { # --------------- setCivicrmRootPath -if ! metaFileExists; then exit 0; fi + +if ! metaFileExists; then + echo "No $META_FILE file found in $civiRoot, skipping compucorp:civicrm-core patch" + exit 0 +fi civiVersion=$(JSONValue "$civiRoot/$META_FILE" "civi-version") lastCommitPatched=$(JSONValue "$civiRoot/$META_FILE" "last-fork-commit-patched") @@ -172,13 +176,21 @@ lastCommitPatched=$(JSONValue "$civiRoot/$META_FILE" "last-fork-commit-patched") patchesBranch="$civiVersion-patches" [ ! -z "$lastCommitPatched" ] && baseHead=$lastCommitPatched || baseHead=$civiVersion + +echo "Fetching compucorp:civicrm-core patch..." createPatch "$baseHead" "$patchesBranch" -if [ -s $civiRoot/$PATCH_FILE ]; then # if the patch is not empty... +if [ -s $civiRoot/$PATCH_FILE ]; then + echo "Applying compucorp:civicrm-core patch..." applyPatch + echo "Updating reference to SHA of last commit patched..." createLastRemoteCommitFile "$patchesBranch" updateLastCommitPatched && rm "$civiRoot/$LAST_REMOTE_COMMIT_FILE" + + echo "Patch applied" +else + echo "Patch was empty, no diffs found" fi rm "$civiRoot/$PATCH_FILE" From ccd8005b11ee938e93c62a72efefcceac3b63f52 Mon Sep 17 00:00:00 2001 From: Alessandro Verdura Date: Fri, 13 Apr 2018 16:07:37 +0200 Subject: [PATCH 131/203] PCHR-3523: Minor fix --- bin/apply-fork-patch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/apply-fork-patch.sh b/bin/apply-fork-patch.sh index dfb45d839d0..c870d51de4b 100755 --- a/bin/apply-fork-patch.sh +++ b/bin/apply-fork-patch.sh @@ -180,7 +180,7 @@ patchesBranch="$civiVersion-patches" echo "Fetching compucorp:civicrm-core patch..." createPatch "$baseHead" "$patchesBranch" -if [ -s $civiRoot/$PATCH_FILE ]; then +if [ -s "$civiRoot/$PATCH_FILE" ]; then echo "Applying compucorp:civicrm-core patch..." applyPatch From 72b153d90505e26affd8bd3848f17d9bb2badff6 Mon Sep 17 00:00:00 2001 From: Alessandro Verdura Date: Fri, 13 Apr 2018 17:16:15 +0200 Subject: [PATCH 132/203] PCHR-3523: Use drush to get civi version and simplify meta file --- bin/apply-fork-patch.sh | 88 ++++++++++------------------------------- 1 file changed, 21 insertions(+), 67 deletions(-) diff --git a/bin/apply-fork-patch.sh b/bin/apply-fork-patch.sh index c870d51de4b..34616b4273f 100755 --- a/bin/apply-fork-patch.sh +++ b/bin/apply-fork-patch.sh @@ -1,8 +1,7 @@ #!/bin/bash API_URL_BASE="https://api.github.com/repos/compucorp/civicrm-core" -LAST_REMOTE_COMMIT_FILE="last-remote-commit.json" -META_FILE="fork-patch-meta.json" +LAST_COMMIT_PATCHED_FILE="core-fork-last-commit-patched.txt" PATCH_FILE="fork-patch.diff" civiRoot="" @@ -22,23 +21,6 @@ applyPatch () { (cd "$civiRoot" && git apply --whitespace=nowarn "$PATCH_FILE") } -####################################### -# Creates a temporary file containing the info related to the last -# commit of the given branch, fetched via the GitHub api -# -# Globals: -# $API_URL_BASE -# $civiRoot -# $PATCH_FILE -# Arguments: -# $1 name of the branch -# Returns: -# None -####################################### -createLastRemoteCommitFile () { - curl "$API_URL_BASE/commits/$1" -s > "$civiRoot/$LAST_REMOTE_COMMIT_FILE" -} - ####################################### # Creates a diff patch file by sending a request to the given GitHub API url # @@ -57,23 +39,17 @@ createPatch () { } ####################################### -# Reads or writes a property's value from a JSON file +# Programmatically gets the current CiviCRM version # # Globals: # None # Arguments: -# $1 JSON file -# $2 property name -# $3 new value of the property (optional) +# None # Returns: -# None/String +# String ####################################### -JSONValue () { - if ! [ -z "$3" ]; then - JSONValueWrite "$1" "$2" "$3" - else - JSONValueRead "$1" "$2" - fi +getCiviVersion () { + drush eval "echo CRM_Utils_System::version();" } ####################################### @@ -86,31 +62,9 @@ JSONValue () { # $2 property name # Returns: # String -## -JSONValueRead () { - python -c "import sys, json; print json.load(sys.stdin)['$2']" < "$1" -} - -####################################### -# Uses Python to update the property's value of a JSON file -# The resulting JSON then overwrites the old content of the file -# -# Globals: -# None -# Arguments: -# $1 JSON file -# $2 property name -# $3 new value of the property -# Returns: -# None ####################################### -JSONValueWrite () { - updatedJSON=$(python -c "import sys, json; \ - jsonFile = json.load(sys.stdin); \ - jsonFile['$2'] = '$3'; \ - print json.dumps(jsonFile, indent=2);" < "$1") - - echo "$updatedJSON" > "$1" +JSONValue () { + python -c "import sys, json; print json.load(sys.stdin)['$2']" < "$1" } ####################################### @@ -118,14 +72,14 @@ JSONValueWrite () { # # Globals: # $civiRoot -# $META_FILE +# $LAST_COMMIT_PATCHED_FILE # Arguments: # None # Returns: # Integer ####################################### metaFileExists () { - if [ -e "$civiRoot/$META_FILE" ]; then return 0; else return 1; fi + if [ -e "$civiRoot/$LAST_COMMIT_PATCHED_FILE" ]; then return 0; else return 1; fi } ####################################### @@ -143,22 +97,23 @@ setCivicrmRootPath () { } ####################################### -# Updates the reference, in the META_FILE, to the last commit patched onto -# the core files +# Updates the reference, in the LAST_COMMIT_PATCHED_FILE, to the last commit +# patched onto the core files # # Globals: -# $LAST_REMOTE_COMMIT_FILE # $civiRoot -# $META_FILE +# $LAST_COMMIT_PATCHED_FILE # Arguments: # None # Returns: # None ####################################### updateLastCommitPatched () { - sha=$(JSONValue "$civiRoot/$LAST_REMOTE_COMMIT_FILE" "sha") + # It uses the same file as temporary recipient of the full commit data + curl "$API_URL_BASE/commits/$1" -s > "$civiRoot/$LAST_COMMIT_PATCHED_FILE" + sha=$(JSONValue "$civiRoot/$LAST_COMMIT_PATCHED_FILE" "sha") - JSONValue "$civiRoot/$META_FILE" "last-fork-commit-patched" "$sha" + echo "$sha" > "$civiRoot/$LAST_COMMIT_PATCHED_FILE" } # --------------- @@ -166,12 +121,12 @@ updateLastCommitPatched () { setCivicrmRootPath if ! metaFileExists; then - echo "No $META_FILE file found in $civiRoot, skipping compucorp:civicrm-core patch" + echo "No $LAST_COMMIT_PATCHED_FILE file found in $civiRoot, skipping compucorp:civicrm-core patch" exit 0 fi -civiVersion=$(JSONValue "$civiRoot/$META_FILE" "civi-version") -lastCommitPatched=$(JSONValue "$civiRoot/$META_FILE" "last-fork-commit-patched") +civiVersion=$(getCiviVersion) +lastCommitPatched=$(cat "$civiRoot/$LAST_COMMIT_PATCHED_FILE") patchesBranch="$civiVersion-patches" [ ! -z "$lastCommitPatched" ] && baseHead=$lastCommitPatched || baseHead=$civiVersion @@ -185,8 +140,7 @@ if [ -s "$civiRoot/$PATCH_FILE" ]; then applyPatch echo "Updating reference to SHA of last commit patched..." - createLastRemoteCommitFile "$patchesBranch" - updateLastCommitPatched && rm "$civiRoot/$LAST_REMOTE_COMMIT_FILE" + updateLastCommitPatched "$patchesBranch" echo "Patch applied" else From cd5c9d49dd6f294d8924bb3a93a5d1d801c06e4f Mon Sep 17 00:00:00 2001 From: Alessandro Verdura Date: Fri, 13 Apr 2018 17:19:22 +0200 Subject: [PATCH 133/203] PCHR-3523: Change meta file location (now in civihr repo) --- .gitignore | 1 + bin/apply-fork-patch.sh | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 6a93dffa5f3..3de41031d36 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ hrjob/build bin/setup.conf hrabsence/build /nbproject/private/ +core-fork-last-commit-patched.txt # Exclude sass cache from all extension directories */.sass-cache/ diff --git a/bin/apply-fork-patch.sh b/bin/apply-fork-patch.sh index 34616b4273f..645c0b3bf4e 100755 --- a/bin/apply-fork-patch.sh +++ b/bin/apply-fork-patch.sh @@ -79,7 +79,7 @@ JSONValue () { # Integer ####################################### metaFileExists () { - if [ -e "$civiRoot/$LAST_COMMIT_PATCHED_FILE" ]; then return 0; else return 1; fi + if [ -e "$LAST_COMMIT_PATCHED_FILE" ]; then return 0; else return 1; fi } ####################################### @@ -110,10 +110,10 @@ setCivicrmRootPath () { ####################################### updateLastCommitPatched () { # It uses the same file as temporary recipient of the full commit data - curl "$API_URL_BASE/commits/$1" -s > "$civiRoot/$LAST_COMMIT_PATCHED_FILE" - sha=$(JSONValue "$civiRoot/$LAST_COMMIT_PATCHED_FILE" "sha") + curl "$API_URL_BASE/commits/$1" -s > "$LAST_COMMIT_PATCHED_FILE" + sha=$(JSONValue "$LAST_COMMIT_PATCHED_FILE" "sha") - echo "$sha" > "$civiRoot/$LAST_COMMIT_PATCHED_FILE" + echo "$sha" > "$LAST_COMMIT_PATCHED_FILE" } # --------------- @@ -126,7 +126,7 @@ if ! metaFileExists; then fi civiVersion=$(getCiviVersion) -lastCommitPatched=$(cat "$civiRoot/$LAST_COMMIT_PATCHED_FILE") +lastCommitPatched=$(cat "$LAST_COMMIT_PATCHED_FILE") patchesBranch="$civiVersion-patches" [ ! -z "$lastCommitPatched" ] && baseHead=$lastCommitPatched || baseHead=$civiVersion From f9ed7c13665b9b0fead031b4767ff522de6c3788 Mon Sep 17 00:00:00 2001 From: Alessandro Verdura Date: Fri, 13 Apr 2018 17:24:28 +0200 Subject: [PATCH 134/203] PCHR-3523: Touch meta file when script runs --- bin/apply-fork-patch.sh | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/bin/apply-fork-patch.sh b/bin/apply-fork-patch.sh index 645c0b3bf4e..db2df8835f3 100755 --- a/bin/apply-fork-patch.sh +++ b/bin/apply-fork-patch.sh @@ -67,21 +67,6 @@ JSONValue () { python -c "import sys, json; print json.load(sys.stdin)['$2']" < "$1" } -####################################### -# Checks if the meta file exists or not -# -# Globals: -# $civiRoot -# $LAST_COMMIT_PATCHED_FILE -# Arguments: -# None -# Returns: -# Integer -####################################### -metaFileExists () { - if [ -e "$LAST_COMMIT_PATCHED_FILE" ]; then return 0; else return 1; fi -} - ####################################### # Returns the civicrm root path # @@ -118,20 +103,14 @@ updateLastCommitPatched () { # --------------- +touch -a $LAST_COMMIT_PATCHED_FILE setCivicrmRootPath -if ! metaFileExists; then - echo "No $LAST_COMMIT_PATCHED_FILE file found in $civiRoot, skipping compucorp:civicrm-core patch" - exit 0 -fi - civiVersion=$(getCiviVersion) lastCommitPatched=$(cat "$LAST_COMMIT_PATCHED_FILE") - patchesBranch="$civiVersion-patches" [ ! -z "$lastCommitPatched" ] && baseHead=$lastCommitPatched || baseHead=$civiVersion - echo "Fetching compucorp:civicrm-core patch..." createPatch "$baseHead" "$patchesBranch" From 835195b16a1c5a6d2f8b4a751f93a85a174d6847 Mon Sep 17 00:00:00 2001 From: Alessandro Verdura Date: Fri, 13 Apr 2018 17:26:56 +0200 Subject: [PATCH 135/203] PCHR-3523: Rename script file --- bin/{apply-fork-patch.sh => apply-core-fork-patch.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename bin/{apply-fork-patch.sh => apply-core-fork-patch.sh} (100%) diff --git a/bin/apply-fork-patch.sh b/bin/apply-core-fork-patch.sh similarity index 100% rename from bin/apply-fork-patch.sh rename to bin/apply-core-fork-patch.sh From 667b4f8e5a35f66b759bfd87310376d78b85ef1e Mon Sep 17 00:00:00 2001 From: Tunbola Ogunwande Date: Mon, 16 Apr 2018 17:05:01 +0100 Subject: [PATCH 136/203] FAR-246: Create the LeaveBalanceChangeExpiryLog Entity. --- .../BAO/LeaveBalanceChangeExpiryLog.php | 95 ++++++ .../DAO/LeaveBalanceChangeExpiryLog.php | 302 ++++++++++++++++++ .../api/v3/LeaveBalanceChangeExpiryLog.php | 14 + .../hrleaveandabsences.php | 6 + ...LeaveBalanceChangeExpiryLog.entityType.php | 11 + .../LeaveBalanceChangeExpiryLog.xml | 96 ++++++ .../schema/CRM/HRLeaveAndAbsences/files.xml | 1 + 7 files changed, 525 insertions(+) create mode 100644 uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeExpiryLog.php create mode 100644 uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/LeaveBalanceChangeExpiryLog.php create mode 100644 uk.co.compucorp.civicrm.hrleaveandabsences/api/v3/LeaveBalanceChangeExpiryLog.php create mode 100644 uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/LeaveBalanceChangeExpiryLog.entityType.php create mode 100644 uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/LeaveBalanceChangeExpiryLog.xml diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeExpiryLog.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeExpiryLog.php new file mode 100644 index 00000000000..8c805ec6b84 --- /dev/null +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeExpiryLog.php @@ -0,0 +1,95 @@ +copyValues($params); + $instance->save(); + CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance); + + return $instance; + } + + + /** + * A method for validating the params passed to the + * LeaveBalanceChangeExpiryLog create method + * + * @param array $params + * The params array received by the create method + * + * @throws InvalidLeaveBalanceChangeExpiryLogException + */ + public static function validateParams($params) { + self::validateUpdatesNotAllowed($params); + self::validateMandatory($params); + } + + /** + * A method for validating the mandatory fields in the params + * passed to the LeaveBalanceChangeExpiryLog create method + * + * @param array $params + * The params array received by the create method + * + * @throws InvalidLeaveBalanceChangeExpiryLogException + */ + private static function validateMandatory($params) { + $mandatoryFields = [ + 'balance_change_id', + 'source_id', + 'source_type', + 'expiry_date', + 'balance_type_id' + ]; + + foreach($mandatoryFields as $field) { + if (empty($params[$field])) { + throw new InvalidLeaveBalanceChangeExpiryLogException( + "The {$field} field should not be empty" + ); + } + } + + if(!isset($params['amount'])) { + throw new InvalidLeaveBalanceChangeExpiryLogException( + 'The amount field should not be empty' + ); + } + } + + /** + * A method for validating that updates are not allowed + * for the LeaveBalanceChangeExpiryLog Entity. Since it is + * for logging purposes, we don't want the records to be + * manipulated or updated + * + * @param array $params + * The params array received by the create method + * + * @throws InvalidLeaveBalanceChangeExpiryLogException + */ + private static function validateUpdatesNotAllowed($params) { + if(!empty($params['id'])) { + throw new InvalidLeaveBalanceChangeExpiryLogException( + 'Updates not allowed for the LeaveBalanceChange Expiry Log entity' + ); + } + } +} diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/LeaveBalanceChangeExpiryLog.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/LeaveBalanceChangeExpiryLog.php new file mode 100644 index 00000000000..ef923e1f590 --- /dev/null +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/LeaveBalanceChangeExpiryLog.php @@ -0,0 +1,302 @@ +__table = 'civicrm_hrleaveandabsences_leave_balance_change_expiry_log'; + parent::__construct(); + } + /** + * Returns all the column names of this table + * + * @return array + */ + static function &fields() { + if (!isset(Civi::$statics[__CLASS__]['fields'])) { + Civi::$statics[__CLASS__]['fields'] = array( + 'id' => array( + 'name' => 'id', + 'type' => CRM_Utils_Type::T_INT, + 'description' => 'Unique LeaveBalanceChangeExpiryLog ID', + 'required' => true, + 'table_name' => 'civicrm_hrleaveandabsences_leave_balance_change_expiry_log', + 'entity' => 'LeaveBalanceChangeExpiryLog', + 'bao' => 'CRM_HRLeaveAndAbsences_DAO_LeaveBalanceChangeExpiryLog', + 'localizable' => 0, + ) , + 'balance_change_id' => array( + 'name' => 'balance_change_id', + 'type' => CRM_Utils_Type::T_INT, + 'description' => 'The expired balance change ID', + 'required' => true, + 'table_name' => 'civicrm_hrleaveandabsences_leave_balance_change_expiry_log', + 'entity' => 'LeaveBalanceChangeExpiryLog', + 'bao' => 'CRM_HRLeaveAndAbsences_DAO_LeaveBalanceChangeExpiryLog', + 'localizable' => 0, + ) , + 'amount' => array( + 'name' => 'amount', + 'type' => CRM_Utils_Type::T_MONEY, + 'title' => ts('Amount') , + 'description' => 'The expired balance amount', + 'required' => true, + 'precision' => array( + 20, + 2 + ) , + 'table_name' => 'civicrm_hrleaveandabsences_leave_balance_change_expiry_log', + 'entity' => 'LeaveBalanceChangeExpiryLog', + 'bao' => 'CRM_HRLeaveAndAbsences_DAO_LeaveBalanceChangeExpiryLog', + 'localizable' => 0, + ) , + 'source_id' => array( + 'name' => 'source_id', + 'type' => CRM_Utils_Type::T_INT, + 'description' => 'Expired Balance change source ID', + 'required' => true, + 'table_name' => 'civicrm_hrleaveandabsences_leave_balance_change_expiry_log', + 'entity' => 'LeaveBalanceChangeExpiryLog', + 'bao' => 'CRM_HRLeaveAndAbsences_DAO_LeaveBalanceChangeExpiryLog', + 'localizable' => 0, + ) , + 'source_type' => array( + 'name' => 'source_type', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Source Type') , + 'description' => 'Expired Balance change source type', + 'required' => true, + 'maxlength' => 20, + 'size' => CRM_Utils_Type::MEDIUM, + 'table_name' => 'civicrm_hrleaveandabsences_leave_balance_change_expiry_log', + 'entity' => 'LeaveBalanceChangeExpiryLog', + 'bao' => 'CRM_HRLeaveAndAbsences_DAO_LeaveBalanceChangeExpiryLog', + 'localizable' => 0, + ) , + 'expiry_date' => array( + 'name' => 'expiry_date', + 'type' => CRM_Utils_Type::T_DATE, + 'title' => ts('Expiry Date') , + 'description' => 'The balance change expiry date', + 'required' => true, + 'table_name' => 'civicrm_hrleaveandabsences_leave_balance_change_expiry_log', + 'entity' => 'LeaveBalanceChangeExpiryLog', + 'bao' => 'CRM_HRLeaveAndAbsences_DAO_LeaveBalanceChangeExpiryLog', + 'localizable' => 0, + ) , + 'balance_type_id' => array( + 'name' => 'balance_type_id', + 'type' => CRM_Utils_Type::T_INT, + 'description' => 'One of the values of the Leave Balance Type option group', + 'required' => true, + 'table_name' => 'civicrm_hrleaveandabsences_leave_balance_change_expiry_log', + 'entity' => 'LeaveBalanceChangeExpiryLog', + 'bao' => 'CRM_HRLeaveAndAbsences_DAO_LeaveBalanceChangeExpiryLog', + 'localizable' => 0, + 'pseudoconstant' => array( + 'optionGroupName' => 'hrleaveandabsences_leave_balance_change_type', + 'optionEditPath' => 'civicrm/admin/options/hrleaveandabsences_leave_balance_change_type', + ) + ) , + 'leave_date' => array( + 'name' => 'leave_date', + 'type' => CRM_Utils_Type::T_DATE, + 'title' => ts('Leave Date') , + 'description' => 'The Leave date of the expired balance change(i.e If it is a leave request balance change)', + 'table_name' => 'civicrm_hrleaveandabsences_leave_balance_change_expiry_log', + 'entity' => 'LeaveBalanceChangeExpiryLog', + 'bao' => 'CRM_HRLeaveAndAbsences_DAO_LeaveBalanceChangeExpiryLog', + 'localizable' => 0, + ) , + 'leave_request_id' => array( + 'name' => 'leave_request_id', + 'type' => CRM_Utils_Type::T_INT, + 'description' => 'The Leave Request ID linked to the expired balance change(i.e If it is a leave request balance change)', + 'table_name' => 'civicrm_hrleaveandabsences_leave_balance_change_expiry_log', + 'entity' => 'LeaveBalanceChangeExpiryLog', + 'bao' => 'CRM_HRLeaveAndAbsences_DAO_LeaveBalanceChangeExpiryLog', + 'localizable' => 0, + ) , + 'created_date' => array( + 'name' => 'created_date', + 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, + 'title' => ts('Created Date') , + 'description' => 'The date and time this log was created', + 'table_name' => 'civicrm_hrleaveandabsences_leave_balance_change_expiry_log', + 'entity' => 'LeaveBalanceChangeExpiryLog', + 'bao' => 'CRM_HRLeaveAndAbsences_DAO_LeaveBalanceChangeExpiryLog', + 'localizable' => 0, + ) , + ); + CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); + } + return Civi::$statics[__CLASS__]['fields']; + } + /** + * Return a mapping from field-name to the corresponding key (as used in fields()). + * + * @return array + * Array(string $name => string $uniqueName). + */ + static function &fieldKeys() { + if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) { + Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields())); + } + return Civi::$statics[__CLASS__]['fieldKeys']; + } + /** + * Returns the names of this table + * + * @return string + */ + static function getTableName() { + return self::$_tableName; + } + /** + * Returns if this table needs to be logged + * + * @return boolean + */ + function getLog() { + return self::$_log; + } + /** + * Returns the list of fields that can be imported + * + * @param bool $prefix + * + * @return array + */ + static function &import($prefix = false) { + $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'hrleaveandabsences_leave_balance_change_expiry_log', $prefix, array()); + return $r; + } + /** + * Returns the list of fields that can be exported + * + * @param bool $prefix + * + * @return array + */ + static function &export($prefix = false) { + $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'hrleaveandabsences_leave_balance_change_expiry_log', $prefix, array()); + return $r; + } + /** + * Returns the list of indices + */ + public static function indices($localize = TRUE) { + $indices = array(); + return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices; + } +} diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/api/v3/LeaveBalanceChangeExpiryLog.php b/uk.co.compucorp.civicrm.hrleaveandabsences/api/v3/LeaveBalanceChangeExpiryLog.php new file mode 100644 index 00000000000..47d53a00a7a --- /dev/null +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/api/v3/LeaveBalanceChangeExpiryLog.php @@ -0,0 +1,14 @@ + 'CRM_HRLeaveAndAbsences_DAO_LeavePeriodEntitlementLog', 'table' => 'civicrm_hrleaveandabsences_leave_period_entitlement_log', ]; + + $entityTypes[] = [ + 'name' => 'LeaveBalanceChangeExpiryLog', + 'class' => 'CRM_HRLeaveAndAbsences_DAO_LeaveBalanceChangeExpiryLog', + 'table' => 'civicrm_hrleaveandabsences_leave_balance_change_expiry_log', + ]; } /** diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/LeaveBalanceChangeExpiryLog.entityType.php b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/LeaveBalanceChangeExpiryLog.entityType.php new file mode 100644 index 00000000000..9c5dd3d6f28 --- /dev/null +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/LeaveBalanceChangeExpiryLog.entityType.php @@ -0,0 +1,11 @@ + + array ( + 'name' => 'LeaveBalanceChangeExpiryLog', + 'class' => 'CRM_HRLeaveAndAbsences_DAO_LeaveBalanceChangeExpiryLog', + 'table' => 'civicrm_leave_balance_change_expiry_log', + ), +); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/LeaveBalanceChangeExpiryLog.xml b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/LeaveBalanceChangeExpiryLog.xml new file mode 100644 index 00000000000..085a318d68e --- /dev/null +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/LeaveBalanceChangeExpiryLog.xml @@ -0,0 +1,96 @@ + + + + CRM/HRLeaveAndAbsences + LeaveBalanceChangeExpiryLog + civicrm_hrleaveandabsences_leave_balance_change_expiry_log + Leave Balance Change Expiry Log + 4.4 + true + + + id + int unsigned + true + Unique LeaveBalanceChangeExpiryLog ID + 4.4 + + + id + true + + + + balance_change_id + int unsigned + true + The expired balance change ID + 4.4 + + + + amount + decimal + true + 0 + The expired balance amount + 4.4 + + + + source_id + int unsigned + true + Expired Balance change source ID + 4.4 + + + + source_type + varchar + true + 20 + Expired Balance change source type + 4.4 + + + + expiry_date + date + true + The balance change expiry date + 4.4 + + + + balance_type_id + int unsigned + true + One of the values of the Leave Balance Type option group + 4.4 + + hrleaveandabsences_leave_balance_change_type + + + + + leave_date + date + The Leave date of the expired balance change(i.e If it is a leave request balance change) + 4.4 + + + + leave_request_id + int unsigned + The Leave Request ID linked to the expired balance change(i.e If it is a leave request balance change) + 4.4 + + + + created_date + datetime + The date and time this log was created + 4.4 + +
    diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/files.xml b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/files.xml index d4ce96f8978..e2e03c2040f 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/files.xml +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/files.xml @@ -14,4 +14,5 @@ + From 0243fc4921d57119e8bf28fee5a985eea66de63b Mon Sep 17 00:00:00 2001 From: Tunbola Ogunwande Date: Mon, 16 Apr 2018 17:06:12 +0100 Subject: [PATCH 137/203] FAR-246: Add Expiry Exception class, Add tests for LeaveBalanceChangeExpiry BAO --- ...idLeaveBalanceChangeExpiryLogException.php | 2 + .../BAO/LeaveBalanceChangeExpiryLogTest.php | 132 ++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Exception/InvalidLeaveBalanceChangeExpiryLogException.php create mode 100644 uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeExpiryLogTest.php diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Exception/InvalidLeaveBalanceChangeExpiryLogException.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Exception/InvalidLeaveBalanceChangeExpiryLogException.php new file mode 100644 index 00000000000..8e425629ede --- /dev/null +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Exception/InvalidLeaveBalanceChangeExpiryLogException.php @@ -0,0 +1,2 @@ + 1, + 'source_type' => LeaveBalanceChange::SOURCE_ENTITLEMENT, + 'expiry_date' => CRM_Utils_Date::processDate('2016-01-01'), + 'balance_type_id' => 1, + 'amount' => 3, + ]); + } + + /** + * @expectedException CRM_HRLeaveAndAbsences_Exception_InvalidLeaveBalanceChangeExpiryLogException + * @expectedExceptionMessage The source_id field should not be empty + */ + public function testCreateLeaveBalanceChangeExpiryLogThrowsExceptionWhenSourceIdIsAbsent() { + LeaveBalanceChangeExpiryLog::create([ + 'source_type' => LeaveBalanceChange::SOURCE_ENTITLEMENT, + 'expiry_date' => CRM_Utils_Date::processDate('2016-01-01'), + 'balance_type_id' => 1, + 'amount' => 3, + 'balance_change_id' => 1, + ]); + } + + /** + * @expectedException CRM_HRLeaveAndAbsences_Exception_InvalidLeaveBalanceChangeExpiryLogException + * @expectedExceptionMessage The source_type field should not be empty + */ + public function testCreateLeaveBalanceChangeExpiryLogThrowsExceptionWhenSourceTypeIsAbsent() { + LeaveBalanceChangeExpiryLog::create([ + 'source_id' => 1, + 'expiry_date' => CRM_Utils_Date::processDate('2016-01-01'), + 'balance_type_id' => 1, + 'amount' => 3, + 'balance_change_id' => 1, + ]); + } + + /** + * @expectedException CRM_HRLeaveAndAbsences_Exception_InvalidLeaveBalanceChangeExpiryLogException + * @expectedExceptionMessage The expiry_date field should not be empty + */ + public function testCreateLeaveBalanceChangeExpiryLogThrowsExceptionWhenExpiryDateIsAbsent() { + LeaveBalanceChangeExpiryLog::create([ + 'source_id' => 1, + 'source_type' => LeaveBalanceChange::SOURCE_ENTITLEMENT, + 'balance_type_id' => 1, + 'amount' => 3, + 'balance_change_id' => 1, + ]); + } + + /** + * @expectedException CRM_HRLeaveAndAbsences_Exception_InvalidLeaveBalanceChangeExpiryLogException + * @expectedExceptionMessage The amount field should not be empty + */ + public function testCreateLeaveBalanceChangeExpiryLogThrowsExceptionWhenAmountIsAbsent() { + LeaveBalanceChangeExpiryLog::create([ + 'source_id' => 1, + 'source_type' => LeaveBalanceChange::SOURCE_ENTITLEMENT, + 'expiry_date' => CRM_Utils_Date::processDate('2016-01-01'), + 'balance_type_id' => 1, + 'balance_change_id' => 1, + ]); + } + + public function testCreateLeaveBalanceChangeExpiryLogDoesNotThrowExceptionWhenAmountIsZero() { + $expiryLog = LeaveBalanceChangeExpiryLog::create([ + 'balance_change_id' => 1, + 'source_id' => 1, + 'source_type' => LeaveBalanceChange::SOURCE_ENTITLEMENT, + 'expiry_date' => CRM_Utils_Date::processDate('2016-01-01'), + 'balance_type_id' => 1, + 'amount' => 0, + ]); + + $this->assertNotNull($expiryLog->id); + } + + public function testUpdatesNotAllowedForTheLeaveBalanceChangeExpiryLogEntity() { + $params = [ + 'balance_change_id' => 1, + 'source_id' => 1, + 'source_type' => LeaveBalanceChange::SOURCE_ENTITLEMENT, + 'expiry_date' => CRM_Utils_Date::processDate('2017-02-01'), + 'balance_type_id' => 1, + 'amount' => 3, + 'leave_date' => CRM_Utils_Date::processDate('2017-01-01'), + 'leave_request_id' => 1, + ]; + + $expiryLog = LeaveBalanceChangeExpiryLog::create($params); + $this->setExpectedException( + CRM_HRLeaveAndAbsences_Exception_InvalidLeaveBalanceChangeExpiryLogException::class, + 'Updates not allowed for the LeaveBalanceChange Expiry Log entity' + ); + + $params['id'] = $expiryLog->id; + LeaveBalanceChangeExpiryLog::create($params); + } + + public function testTheCreatedDateCanNotBeManipulated() { + $params = [ + 'balance_change_id' => 1, + 'source_id' => 1, + 'source_type' => LeaveBalanceChange::SOURCE_ENTITLEMENT, + 'expiry_date' => CRM_Utils_Date::processDate('2016-01-01'), + 'balance_type_id' => 1, + 'amount' => 3, + 'created_date' => CRM_Utils_Date::processDate('2016-01-01') + ]; + + $dateNow = new DateTime(); + $expiryLog = LeaveBalanceChangeExpiryLog::create($params); + $this->assertEquals($dateNow, new DateTime($expiryLog->created_date), 10); + } +} From e82972749b17bb7464cd467f4f325d390691ee03 Mon Sep 17 00:00:00 2001 From: Tunbola Ogunwande Date: Mon, 16 Apr 2018 17:07:04 +0100 Subject: [PATCH 138/203] FAR-246: Add Sql in auto Install file and also upgrader for adding the expiry log table. --- .../CRM/HRLeaveAndAbsences/Upgrader.php | 1 + .../HRLeaveAndAbsences/Upgrader/Step/1022.php | 30 +++++++++++++++++++ .../sql/auto_install.sql | 23 ++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php index 9b9fd3058a4..bc583e58322 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php @@ -27,6 +27,7 @@ class CRM_HRLeaveAndAbsences_Upgrader extends CRM_HRLeaveAndAbsences_Upgrader_Ba use CRM_HRLeaveAndAbsences_Upgrader_Step_1019; use CRM_HRLeaveAndAbsences_Upgrader_Step_1020; use CRM_HRLeaveAndAbsences_Upgrader_Step_1021; + use CRM_HRLeaveAndAbsences_Upgrader_Step_1022; /** * A list of directories to be scanned for XML installation files diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php new file mode 100644 index 00000000000..a2e7d9e396b --- /dev/null +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php @@ -0,0 +1,30 @@ + Date: Tue, 17 Apr 2018 10:51:34 +0200 Subject: [PATCH 139/203] PCHR-3523: Update script --- bin/apply-core-fork-patch.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/apply-core-fork-patch.sh b/bin/apply-core-fork-patch.sh index db2df8835f3..c355bbccce0 100755 --- a/bin/apply-core-fork-patch.sh +++ b/bin/apply-core-fork-patch.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + API_URL_BASE="https://api.github.com/repos/compucorp/civicrm-core" LAST_COMMIT_PATCHED_FILE="core-fork-last-commit-patched.txt" PATCH_FILE="fork-patch.diff" @@ -49,7 +51,7 @@ createPatch () { # String ####################################### getCiviVersion () { - drush eval "echo CRM_Utils_System::version();" + drush eval "civicrm_initialize(); echo CRM_Utils_System::version();" } ####################################### @@ -78,7 +80,7 @@ JSONValue () { # String ####################################### setCivicrmRootPath () { - civiRoot=$(drush eval "echo \\Civi::paths()->getPath('[civicrm.root]/.')") + civiRoot=$(drush eval "civicrm_initialize(); echo \\Civi::paths()->getPath('[civicrm.root]/.')") } ####################################### From 612387a7a3ddd2b47ee79a6f02cb9f064829c3bb Mon Sep 17 00:00:00 2001 From: Tunbola Ogunwande Date: Tue, 17 Apr 2018 10:29:02 +0100 Subject: [PATCH 140/203] FAR-246: Code formatting and Spacing. --- .../BAO/LeaveBalanceChangeExpiryLog.php | 1 - .../DAO/LeaveBalanceChangeExpiryLog.php | 8 ++++---- .../CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php | 4 ++-- .../sql/auto_install.sql | 4 ++-- .../BAO/LeaveBalanceChangeExpiryLogTest.php | 13 +++++++------ .../LeaveBalanceChangeExpiryLog.xml | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeExpiryLog.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeExpiryLog.php index 8c805ec6b84..e5b11ec46c1 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeExpiryLog.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeExpiryLog.php @@ -26,7 +26,6 @@ public static function create($params) { return $instance; } - /** * A method for validating the params passed to the * LeaveBalanceChangeExpiryLog create method diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/LeaveBalanceChangeExpiryLog.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/LeaveBalanceChangeExpiryLog.php index ef923e1f590..f3661b6a4b5 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/LeaveBalanceChangeExpiryLog.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/DAO/LeaveBalanceChangeExpiryLog.php @@ -93,13 +93,13 @@ class CRM_HRLeaveAndAbsences_DAO_LeaveBalanceChangeExpiryLog extends CRM_Core_DA */ public $balance_type_id; /** - * The Leave date of the expired balance change(i.e If it is a leave request balance change) + * The Leave date of the expired balance change (i.e If it is a leave request balance change) * * @var date */ public $leave_date; /** - * The Leave Request ID linked to the expired balance change(i.e If it is a leave request balance change) + * The Leave Request ID linked to the expired balance change (i.e If it is a leave request balance change) * * @var int unsigned */ @@ -212,7 +212,7 @@ static function &fields() { 'name' => 'leave_date', 'type' => CRM_Utils_Type::T_DATE, 'title' => ts('Leave Date') , - 'description' => 'The Leave date of the expired balance change(i.e If it is a leave request balance change)', + 'description' => 'The Leave date of the expired balance change (i.e If it is a leave request balance change)', 'table_name' => 'civicrm_hrleaveandabsences_leave_balance_change_expiry_log', 'entity' => 'LeaveBalanceChangeExpiryLog', 'bao' => 'CRM_HRLeaveAndAbsences_DAO_LeaveBalanceChangeExpiryLog', @@ -221,7 +221,7 @@ static function &fields() { 'leave_request_id' => array( 'name' => 'leave_request_id', 'type' => CRM_Utils_Type::T_INT, - 'description' => 'The Leave Request ID linked to the expired balance change(i.e If it is a leave request balance change)', + 'description' => 'The Leave Request ID linked to the expired balance change (i.e If it is a leave request balance change)', 'table_name' => 'civicrm_hrleaveandabsences_leave_balance_change_expiry_log', 'entity' => 'LeaveBalanceChangeExpiryLog', 'bao' => 'CRM_HRLeaveAndAbsences_DAO_LeaveBalanceChangeExpiryLog', diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php index a2e7d9e396b..6c1e6ad10a5 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1022.php @@ -19,8 +19,8 @@ public function upgrade_1022() { `source_type` varchar(20) NOT NULL COMMENT 'Expired Balance change source type', `expiry_date` date NOT NULL COMMENT 'The balance change expiry date', `balance_type_id` int unsigned NOT NULL COMMENT 'One of the values of the Leave Balance Type option group', - `leave_date` date COMMENT 'The Leave date of the expired balance change(i.e If it is a leave request balance change)', - `leave_request_id` int unsigned COMMENT 'The Leave Request ID linked to the expired balance change(i.e If it is a leave request balance change)', + `leave_date` date COMMENT 'The Leave date of the expired balance change (i.e If it is a leave request balance change)', + `leave_request_id` int unsigned COMMENT 'The Leave Request ID linked to the expired balance change (i.e If it is a leave request balance change)', `created_date` datetime COMMENT 'The date and time this log was created' , PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/sql/auto_install.sql b/uk.co.compucorp.civicrm.hrleaveandabsences/sql/auto_install.sql index fe9138efb77..22fc0da4816 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/sql/auto_install.sql +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/sql/auto_install.sql @@ -432,8 +432,8 @@ CREATE TABLE `civicrm_hrleaveandabsences_leave_balance_change_expiry_log` ( `source_type` varchar(20) NOT NULL COMMENT 'Expired Balance change source type', `expiry_date` date NOT NULL COMMENT 'The balance change expiry date', `balance_type_id` int unsigned NOT NULL COMMENT 'One of the values of the Leave Balance Type option group', - `leave_date` date COMMENT 'The Leave date of the expired balance change(i.e If it is a leave request balance change)', - `leave_request_id` int unsigned COMMENT 'The Leave Request ID linked to the expired balance change(i.e If it is a leave request balance change)', + `leave_date` date COMMENT 'The Leave date of the expired balance change (i.e If it is a leave request balance change)', + `leave_request_id` int unsigned COMMENT 'The Leave Request ID linked to the expired balance change (i.e If it is a leave request balance change)', `created_date` datetime COMMENT 'The date and time this log was created' , PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ; diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeExpiryLogTest.php b/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeExpiryLogTest.php index 262fe02b274..794b87efc88 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeExpiryLogTest.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeExpiryLogTest.php @@ -2,6 +2,7 @@ use CRM_HRLeaveAndAbsences_BAO_LeaveBalanceChangeExpiryLog as LeaveBalanceChangeExpiryLog; use CRM_HRLeaveAndAbsences_BAO_LeaveBalanceChange as LeaveBalanceChange; + /** * Class CRM_HRLeaveAndAbsences_BAO_LeaveBalanceChangeExpiryLogTest * @@ -13,7 +14,7 @@ class CRM_HRLeaveAndAbsences_BAO_LeaveBalanceChangeExpiryLogTest extends BaseHea * @expectedException CRM_HRLeaveAndAbsences_Exception_InvalidLeaveBalanceChangeExpiryLogException * @expectedExceptionMessage The balance_change_id field should not be empty */ - public function testCreateLeaveBalanceChangeExpiryLogThrowsExceptionWhenBalanceChangeIdIsAbsent() { + public function testCreateThrowsExceptionWhenBalanceChangeIdIsAbsent() { LeaveBalanceChangeExpiryLog::create([ 'source_id' => 1, 'source_type' => LeaveBalanceChange::SOURCE_ENTITLEMENT, @@ -27,7 +28,7 @@ public function testCreateLeaveBalanceChangeExpiryLogThrowsExceptionWhenBalanceC * @expectedException CRM_HRLeaveAndAbsences_Exception_InvalidLeaveBalanceChangeExpiryLogException * @expectedExceptionMessage The source_id field should not be empty */ - public function testCreateLeaveBalanceChangeExpiryLogThrowsExceptionWhenSourceIdIsAbsent() { + public function testCreateThrowsExceptionWhenSourceIdIsAbsent() { LeaveBalanceChangeExpiryLog::create([ 'source_type' => LeaveBalanceChange::SOURCE_ENTITLEMENT, 'expiry_date' => CRM_Utils_Date::processDate('2016-01-01'), @@ -41,7 +42,7 @@ public function testCreateLeaveBalanceChangeExpiryLogThrowsExceptionWhenSourceId * @expectedException CRM_HRLeaveAndAbsences_Exception_InvalidLeaveBalanceChangeExpiryLogException * @expectedExceptionMessage The source_type field should not be empty */ - public function testCreateLeaveBalanceChangeExpiryLogThrowsExceptionWhenSourceTypeIsAbsent() { + public function testCreateThrowsExceptionWhenSourceTypeIsAbsent() { LeaveBalanceChangeExpiryLog::create([ 'source_id' => 1, 'expiry_date' => CRM_Utils_Date::processDate('2016-01-01'), @@ -55,7 +56,7 @@ public function testCreateLeaveBalanceChangeExpiryLogThrowsExceptionWhenSourceTy * @expectedException CRM_HRLeaveAndAbsences_Exception_InvalidLeaveBalanceChangeExpiryLogException * @expectedExceptionMessage The expiry_date field should not be empty */ - public function testCreateLeaveBalanceChangeExpiryLogThrowsExceptionWhenExpiryDateIsAbsent() { + public function testCreateThrowsExceptionWhenExpiryDateIsAbsent() { LeaveBalanceChangeExpiryLog::create([ 'source_id' => 1, 'source_type' => LeaveBalanceChange::SOURCE_ENTITLEMENT, @@ -69,7 +70,7 @@ public function testCreateLeaveBalanceChangeExpiryLogThrowsExceptionWhenExpiryDa * @expectedException CRM_HRLeaveAndAbsences_Exception_InvalidLeaveBalanceChangeExpiryLogException * @expectedExceptionMessage The amount field should not be empty */ - public function testCreateLeaveBalanceChangeExpiryLogThrowsExceptionWhenAmountIsAbsent() { + public function testCreateThrowsExceptionWhenAmountIsAbsent() { LeaveBalanceChangeExpiryLog::create([ 'source_id' => 1, 'source_type' => LeaveBalanceChange::SOURCE_ENTITLEMENT, @@ -79,7 +80,7 @@ public function testCreateLeaveBalanceChangeExpiryLogThrowsExceptionWhenAmountIs ]); } - public function testCreateLeaveBalanceChangeExpiryLogDoesNotThrowExceptionWhenAmountIsZero() { + public function testCreateDoesNotThrowExceptionWhenAmountIsZero() { $expiryLog = LeaveBalanceChangeExpiryLog::create([ 'balance_change_id' => 1, 'source_id' => 1, diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/LeaveBalanceChangeExpiryLog.xml b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/LeaveBalanceChangeExpiryLog.xml index 085a318d68e..34497085b92 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/LeaveBalanceChangeExpiryLog.xml +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/schema/CRM/HRLeaveAndAbsences/LeaveBalanceChangeExpiryLog.xml @@ -76,14 +76,14 @@ leave_date date - The Leave date of the expired balance change(i.e If it is a leave request balance change) + The Leave date of the expired balance change (i.e If it is a leave request balance change) 4.4 leave_request_id int unsigned - The Leave Request ID linked to the expired balance change(i.e If it is a leave request balance change) + The Leave Request ID linked to the expired balance change (i.e If it is a leave request balance change) 4.4 From cf3968af2518e0fc87aabbe510421cc0ccb7be97 Mon Sep 17 00:00:00 2001 From: Alessandro Verdura Date: Tue, 17 Apr 2018 14:02:08 +0200 Subject: [PATCH 141/203] PCHR-3523: Use patch instead of git apply --- bin/apply-core-fork-patch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/apply-core-fork-patch.sh b/bin/apply-core-fork-patch.sh index c355bbccce0..17889610737 100755 --- a/bin/apply-core-fork-patch.sh +++ b/bin/apply-core-fork-patch.sh @@ -20,7 +20,7 @@ civiRoot="" # None ####################################### applyPatch () { - (cd "$civiRoot" && git apply --whitespace=nowarn "$PATCH_FILE") + (cd "$civiRoot" && patch -p1 < "$PATCH_FILE" >> /dev/null) } ####################################### From 7bdf903df545b94a6322772fa657d969996f964a Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Tue, 17 Apr 2018 15:53:29 +0100 Subject: [PATCH 142/203] PCHR-3460: Add tool icon to edit job role options --- .../js/dist/job-roles.min.js | 4 +- .../controllers/job-roles.controller.js | 43 +++++++++++-------- .../src/job-roles/modules/job-roles.core.js | 1 + .../controllers/job-roles.controller.spec.js | 29 ++++++++++++- .../views/include/add_new_role.html | 28 ++++-------- .../views/include/job_role_panel.html | 28 ++++-------- 6 files changed, 72 insertions(+), 61 deletions(-) diff --git a/com.civicrm.hrjobroles/js/dist/job-roles.min.js b/com.civicrm.hrjobroles/js/dist/job-roles.min.js index fff2f9a4304..31cc6fd9d6a 100644 --- a/com.civicrm.hrjobroles/js/dist/job-roles.min.js +++ b/com.civicrm.hrjobroles/js/dist/job-roles.min.js @@ -12,6 +12,6 @@ Build date: 2014-01-10 */ -define("job-roles/modules/job-roles.config",["common/angular"],function(e){"use strict";function t(e,t,n,r,a){t.debugEnabled(a.debug),r.resolveForAll({format:["DateFormat",function(e){return e.getDateFormat()}]}).when("/",{templateUrl:a.pathBaseUrl+a.pathTpl+"mainTemplate.html?v=1",resolve:{},controller:"JobRolesController",controllerAs:"jobroles"}).otherwise({redirectTo:"/"}),n.defaults.stripTrailingSlashes=!1,e.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}e.module("hrjobroles.config",["hrjobroles.constants"]).config(t),t.$inject=["$httpProvider","$logProvider","$resourceProvider","$routeProvider","settings"]}),define("job-roles/modules/job-roles.constants",["common/angular"],function(e){"use strict";e.module("hrjobroles.constants",[]).constant("settings",{classNamePrefix:"hrjobroles-",contactId:decodeURIComponent((new RegExp("[?|&]cid=([^&;]+?)(&|#|;|$)").exec(location.search)||[null,""])[1].replace(/\+/g,"%20"))||null,debug:!0,pathApp:CRM.vars.hrjobroles.path,pathRest:CRM.url("civicrm/ajax/rest"),pathBaseUrl:CRM.vars.hrjobroles.baseURL+"/",pathTpl:"views/",pathIncludeTpl:"views/include/"})}),define("job-roles/controllers/job-roles.controller",["common/angular","common/lodash","common/moment"],function(e,t,n){"use strict";function r(r,a,o,i,s,l,u,c,d,f,m,p,b,h,v,g){function _(e,t){void 0===De.editData[e]&&(De.editData[e]={}),"cost_centre"===t?(void 0!==De.editData[e].cost_centers&&De.editData[e].cost_centers instanceof Array||(De.editData[e].cost_centers=[]),De.editData[e].cost_centers.push({id:De.editData[e].cost_centers.length+1,cost_centre_id:"",type:"1",percentage:"0",amount:"0"})):(void 0!==De.editData[e].funders&&De.editData[e].funders instanceof Array||(De.editData[e].funders=[]),De.editData[e].funders.push({id:De.editData[e].funders.length+1,funder_id:"",type:"1",percentage:"0",amount:"0"}))}function $(){De.add_new=!0}function w(){De.add_new=!1,delete De.editData.new_role_id}function y(e,t){De.viewTab[e]=t}function D(t,n){V(t)&&(t=null),V(n)&&(n=null);var r=!0;return!!t&&(e.forEach(De.contractsData,function(e){_e(t)===_e(e.start_date)&&_e(n)===_e(e.end_date)&&(r=!1)}),r)}function E(){return void 0===De.editData.new_role_id||void 0===De.editData.new_role_id.title||""===De.editData.new_role_id.title||void 0===De.editData.new_role_id.job_contract_id||""===De.editData.new_role_id.job_contract_id}function j(e){De.collapsedRows[e]=!De.collapsedRows[e]}function C(e){return v.getContracts(e).then(function(e){for(var t=[],n={},r=0;r-1&&t.start.push(e),r.indexOf("end_date")>-1&&t.end.push(e)}),b.validate(e.start,e.end,e.contractStart,e.contractEnd),0===n}function ve(e){e.start_date.$error.custom=[],e.end_date.$error.custom=[];var t=J(e.contract.$viewValue);return void 0===t?"Contract is missing":!!he({start:e.start_date.$viewValue,end:e.end_date.$viewValue,contractStart:t.start_date,contractEnd:t.end_date},{start:e.start_date.$error.custom,end:e.end_date.$error.custom})||"Error"}function ge(e){if("title"===e||" "===e)return"Title cannot be title!"}a.debug("Controller: JobRolesController");var _e=r("formatDate"),$e={},we=r("getActiveValues"),ye=["funders","cost_centers"],De=this;De.contactId=m.contactId,De.format=p.DATE_FORMAT,De.loading=!0,De.pastJobRoles=[],De.presentJobRoles=[],De.collapsedRows=[],De.contactList=[],De.editData={},De.viewTab=[],De.CalendarShow=[],De.contractsData=[],De.DepartmentsData={},De.LevelsData={},De.LocationsData={},De.RegionsData={},De.addNewRoleUrl=m.pathBaseUrl+m.pathIncludeTpl+"add_new_role.html",De.jobRolePanelUrl=m.pathBaseUrl+m.pathIncludeTpl+"job_role_panel.html",De.rowTypes={},De.rowTypes[0]={id:0,name:"Fixed"},De.rowTypes[1]={id:1,name:"%"},De.addAdditionalRow=_,De.addNewRole=$,De.cancelNewRole=w,De.changeTab=y,De.checkIfDatesAreCustom=D,De.checkNewRole=E,De.collapseRow=j,De.deleteAdditionalRow=F,De.dpOpen=A,De.getContactList=k,De.getCostLabel=L,De.initData=z,De.isChanged=P,De.isOpen=Y,De.isRowCollapsed=G,De.isTab=K,De.onAfterSave=Z,De.onCancel=X,De.onContractEdited=Q,De.onContractSelected=ee,De.open=te,De.removeRole=re,De.saveNewRole=ae,De.select=oe,De.showRowType=ie,De.showSave=se,De.status="",De.today=ue,De.updateAdditionalRowType=ce,De.updateRole=pe,De.validateRole=ve,De.validateTitle=ge,function(){le(),De.today(),o.all([q(),M(De.contactId),De.getContactList()]).then(function(){De.loading=!1})}()}return r.__name="JobRolesController",r.$inject=["$filter","$log","$q","$rootElement","$route","$routeParams","$scope","$timeout","$uibModal","DOMEventTrigger","settings","HR_settings","dateValidation","filtersService","jobRoleService","pubSub"],r}),define("job-roles/controllers/modal-dialog.controller",[],function(){"use strict";function e(e,t,n,r){function a(){e.dismiss("Cancel")}function o(t){e.close(t||!0)}t.debug("Controller: ModalDialogController");var i=this;i.copyCancel=r.copyCancel||"Cancel",i.copyConfirm=r.copyConfirm||"Yes",i.msg=r.msg||"",i.title=r.title||"CiviHR Job Roles",i.cancel=a,i.confirm=o}return e.__name="ModalDialogController",e.$inject=["$uibModalInstance","$log","$timeout","content"],e}),define("job-roles/modules/job-roles.controllers",["common/angular","job-roles/controllers/job-roles.controller","job-roles/controllers/modal-dialog.controller"],function(e,t,n){"use strict";return e.module("hrjobroles.controllers",[]).controller(t.__name,t).controller(n.__name,n)}),angular.module("xeditable",[]).value("editableOptions",{theme:"default",buttons:"right",blurElem:"cancel",blurForm:"ignore",activate:"focus"}),angular.module("xeditable").directive("editableBsdate",["editableDirectiveFactory",function(e){return e({directiveName:"editableBsdate",inputTpl:''})}]),angular.module("xeditable").directive("editableBstime",["editableDirectiveFactory",function(e){return e({directiveName:"editableBstime",inputTpl:"",render:function(){this.parent.render.call(this);var e=angular.element('
    ');e.attr("ng-model",this.inputEl.attr("ng-model")),this.inputEl.removeAttr("ng-model"),this.attrs.eNgChange&&(e.attr("ng-change",this.inputEl.attr("ng-change")),this.inputEl.removeAttr("ng-change")),this.inputEl.wrap(e)}})}]),angular.module("xeditable").directive("editableCheckbox",["editableDirectiveFactory",function(e){return e({directiveName:"editableCheckbox",inputTpl:'',render:function(){this.parent.render.call(this),this.attrs.eTitle&&(this.inputEl.wrap(""),this.inputEl.after(angular.element("").text(this.attrs.eTitle)))},autosubmit:function(){var e=this;e.inputEl.bind("change",function(){setTimeout(function(){e.scope.$apply(function(){e.scope.$form.$submit()})},500)})}})}]),angular.module("xeditable").directive("editableChecklist",["editableDirectiveFactory","editableNgOptionsParser",function(e,t){return e({directiveName:"editableChecklist",inputTpl:"",useCopy:!0,render:function(){this.parent.render.call(this);var e=t(this.attrs.eNgOptions),n='';this.inputEl.removeAttr("ng-model"),this.inputEl.removeAttr("ng-options"),this.inputEl.html(n)}})}]),function(){var e="text|email|tel|number|url|search|color|date|datetime|time|month|week".split("|");angular.forEach(e,function(e){var t="editable"+e.charAt(0).toUpperCase()+e.slice(1);angular.module("xeditable").directive(t,["editableDirectiveFactory",function(n){return n({directiveName:t,inputTpl:''})}])}),angular.module("xeditable").directive("editableRange",["editableDirectiveFactory",function(e){return e({directiveName:"editableRange",inputTpl:'',render:function(){this.parent.render.call(this),this.inputEl.after("{{$data}}")}})}])}(),angular.module("xeditable").directive("editableRadiolist",["editableDirectiveFactory","editableNgOptionsParser",function(e,t){return e({directiveName:"editableRadiolist",inputTpl:"",render:function(){this.parent.render.call(this);var e=t(this.attrs.eNgOptions),n='';this.inputEl.removeAttr("ng-model"),this.inputEl.removeAttr("ng-options"),this.inputEl.html(n)},autosubmit:function(){var e=this;e.inputEl.bind("change",function(){setTimeout(function(){e.scope.$apply(function(){e.scope.$form.$submit()})},500)})}})}]),angular.module("xeditable").directive("editableSelect",["editableDirectiveFactory",function(e){return e({directiveName:"editableSelect",inputTpl:"",autosubmit:function(){var e=this;e.inputEl.bind("change",function(){e.scope.$apply(function(){e.scope.$form.$submit()})})}})}]),angular.module("xeditable").directive("editableTextarea",["editableDirectiveFactory",function(e){return e({directiveName:"editableTextarea",inputTpl:"",addListeners:function(){var e=this;e.parent.addListeners.call(e),e.single&&"no"!==e.buttons&&e.autosubmit()},autosubmit:function(){var e=this;e.inputEl.bind("keydown",function(t){(t.ctrlKey||t.metaKey)&&13===t.keyCode&&e.scope.$apply(function(){e.scope.$form.$submit()})})}})}]),angular.module("xeditable").factory("editableController",["$q","editableUtils",function(e,t){function n(e,n,r,a,o,i,s,l,u){var c,d,f=this;f.scope=e,f.elem=r,f.attrs=n,f.inputEl=null,f.editorEl=null,f.single=!0,f.error="",f.theme=o[i.theme]||o.default,f.parent={},f.inputTpl="",f.directiveName="",f.useCopy=!1,f.single=null,f.buttons="right",f.init=function(t){if(f.single=t,f.name=n.eName||n[f.directiveName],!n[f.directiveName])throw"You should provide value for `"+f.directiveName+"` in editable element!";c=a(n[f.directiveName]),f.buttons=f.single?f.attrs.buttons||i.buttons:"no",n.eName&&f.scope.$watch("$data",function(e){f.scope.$form.$data[n.eName]=e}),n.onshow&&(f.onshow=function(){return f.catchError(a(n.onshow)(e))}),n.onhide&&(f.onhide=function(){return a(n.onhide)(e)}),n.oncancel&&(f.oncancel=function(){return a(n.oncancel)(e)}),n.onbeforesave&&(f.onbeforesave=function(){return f.catchError(a(n.onbeforesave)(e))}),n.onaftersave&&(f.onaftersave=function(){return f.catchError(a(n.onaftersave)(e))}),e.$parent.$watch(n[f.directiveName],function(){f.handleEmpty()})},f.render=function(){var e=f.theme;f.inputEl=angular.element(f.inputTpl),f.controlsEl=angular.element(e.controlsTpl),f.controlsEl.append(f.inputEl),"no"!==f.buttons&&(f.buttonsEl=angular.element(e.buttonsTpl),f.submitEl=angular.element(e.submitTpl),f.cancelEl=angular.element(e.cancelTpl),f.buttonsEl.append(f.submitEl).append(f.cancelEl),f.controlsEl.append(f.buttonsEl),f.inputEl.addClass("editable-has-buttons")),f.errorEl=angular.element(e.errorTpl),f.controlsEl.append(f.errorEl),f.editorEl=angular.element(f.single?e.formTpl:e.noformTpl),f.editorEl.append(f.controlsEl);for(var r in n.$attr)if(!(r.length<=1)){var a=!1,o=r.substring(1,2);if("e"===r.substring(0,1)&&o===o.toUpperCase()&&"Form"!==(a=r.substring(1))&&"NgSubmit"!==a){a=a.substring(0,1).toLowerCase()+t.camelToDash(a.substring(1));var s=""===n[r]?a:n[r];f.inputEl.attr(a,s)}}f.inputEl.addClass("editable-input"),f.inputEl.attr("ng-model","$data"),f.editorEl.addClass(t.camelToDash(f.directiveName)),f.single&&(f.editorEl.attr("editable-form","$form"),f.editorEl.attr("blur",f.attrs.blur||("no"===f.buttons?"cancel":i.blurElem))),angular.isFunction(e.postrender)&&e.postrender.call(f)},f.setLocalValue=function(){f.scope.$data=f.useCopy?angular.copy(c(e.$parent)):c(e.$parent)},f.show=function(){return f.setLocalValue(),f.render(),r.after(f.editorEl),l(f.editorEl)(e),f.addListeners(),r.addClass("editable-hide"),f.onshow()},f.hide=function(){return f.editorEl.remove(),r.removeClass("editable-hide"),f.onhide()},f.cancel=function(){f.oncancel()},f.addListeners=function(){f.inputEl.bind("keyup",function(e){if(f.single)switch(e.keyCode){case 27:f.scope.$apply(function(){f.scope.$form.$cancel()})}}),f.single&&"no"===f.buttons&&f.autosubmit(),f.editorEl.bind("click",function(e){1===e.which&&f.scope.$form.$visible&&(f.scope.$form._clicked=!0)})},f.setWaiting=function(e){e?(d=!f.inputEl.attr("disabled")&&!f.inputEl.attr("ng-disabled")&&!f.inputEl.attr("ng-enabled"))&&(f.inputEl.attr("disabled","disabled"),f.buttonsEl&&f.buttonsEl.find("button").attr("disabled","disabled")):d&&(f.inputEl.removeAttr("disabled"),f.buttonsEl&&f.buttonsEl.find("button").removeAttr("disabled"))},f.activate=function(){setTimeout(function(){var e=f.inputEl[0];"focus"===i.activate&&e.focus&&e.focus(),"select"===i.activate&&e.select&&e.select()},0)},f.setError=function(t){angular.isObject(t)||(e.$error=t,f.error=t)},f.catchError=function(e,t){return angular.isObject(e)&&!0!==t?u.when(e).then(angular.bind(this,function(e){this.catchError(e,!0)}),angular.bind(this,function(e){this.catchError(e,!0)})):t&&angular.isObject(e)&&e.status&&200!==e.status&&e.data&&angular.isString(e.data)?(this.setError(e.data),e=e.data):angular.isString(e)&&this.setError(e),e},f.save=function(){c.assign(e.$parent,angular.copy(f.scope.$data))},f.handleEmpty=function(){var t=c(e.$parent),n=null===t||void 0===t||""===t||angular.isArray(t)&&0===t.length;r.toggleClass("editable-empty",n)},f.autosubmit=angular.noop,f.onshow=angular.noop,f.onhide=angular.noop,f.oncancel=angular.noop,f.onbeforesave=angular.noop,f.onaftersave=angular.noop}return n.$inject=["$scope","$attrs","$element","$parse","editableThemes","editableOptions","$rootScope","$compile","$q"],n}]),angular.module("xeditable").factory("editableDirectiveFactory",["$parse","$compile","editableThemes","$rootScope","$document","editableController","editableFormController",function(e,t,n,r,a,o,i){return function(t){return{restrict:"A",scope:!0,require:[t.directiveName,"?^form"],controller:o,link:function(n,o,s,l){var u,c=l[0],d=!1;if(l[1])u=l[1],d=!0;else if(s.eForm){var f=e(s.eForm)(n);if(f)u=f,d=!0;else for(var m=0;m=0&&e.splice(n,1),t},camelToDash:function(e){var t=/[A-Z]/g;return e.replace(t,function(e,t){return(t?"-":"")+e.toLowerCase()})},dashToCamel:function(e){var t=/([\:\-\_]+(.))/g,n=/^moz([A-Z])/;return e.replace(t,function(e,t,n,r){return r?n.toUpperCase():n}).replace(n,"Moz$1")}}}]),angular.module("xeditable").factory("editableNgOptionsParser",[function(){function e(e){var n;if(!(n=e.match(t)))throw"ng-options parse error";var r,a=n[2]||n[1],o=n[4]||n[6],i=n[5],s=(n[3],n[2]?n[1]:o),l=n[7],u=n[8],c=u?n[8]:null;return void 0===i?(r=o+" in "+l,void 0!==u&&(r+=" track by "+c)):r="("+i+", "+o+") in "+l,{ngRepeat:r,locals:{valueName:o,keyName:i,valueFn:s,displayFn:a}}}var t=/^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+(.*?)(?:\s+track\s+by\s+(.*?))?$/;return e}]),angular.module("xeditable").factory("editableThemes",function(){return{default:{formTpl:'
    ',noformTpl:'',controlsTpl:'',inputTpl:"",errorTpl:'
    ',buttonsTpl:'',submitTpl:'',cancelTpl:''},bs2:{formTpl:'
    ',noformTpl:'',controlsTpl:'
    ',inputTpl:"",errorTpl:'
    ',buttonsTpl:'',submitTpl:'',cancelTpl:''},bs3:{ -formTpl:'
    ',noformTpl:'',controlsTpl:'
    ',inputTpl:"",errorTpl:'
    ',buttonsTpl:'',submitTpl:'',cancelTpl:'',buttonsClass:"",inputClass:"",postrender:function(){switch(this.directiveName){case"editableText":case"editableSelect":case"editableTextarea":case"editableEmail":case"editableTel":case"editableNumber":case"editableUrl":case"editableSearch":case"editableDate":case"editableDatetime":case"editableTime":case"editableMonth":case"editableWeek":if(this.inputEl.addClass("form-control"),this.theme.inputClass){if(this.inputEl.attr("multiple")&&("input-sm"===this.theme.inputClass||"input-lg"===this.theme.inputClass))break;this.inputEl.addClass(this.theme.inputClass)}}this.buttonsEl&&this.theme.buttonsClass&&this.buttonsEl.find("button").addClass(this.theme.buttonsClass)}}}}),function(e,t,n){"use strict";function r(e){return F(e)?e:Object.keys(e).map(function(t){return e[t]})}function a(e){return null===e}function o(e,t){return-1==Object.keys(e).map(function(r){return t[r]!==n&&t[r]==e[r]}).indexOf(!1)}function i(e,t){if(""===t)return e;var n=e.indexOf(t.charAt(0));return-1!==n&&i(e.substr(n+1),t.substr(1))}function s(e,t,n){var r=0;return e.filter(function(e){var a=D(n)?t>r&&n(e):t>r;return r=a?r+1:r,a})}function l(e,t,n){return n.round(e*n.pow(10,t))/n.pow(10,t)}function u(e,t,n){return t=t||[],Object.keys(e).forEach(function(r){if(T(e[r])&&!F(e[r])){var a=n?n+"."+r:n;u(e[r],t,a||r)}else{var o=n?n+"."+r:r;t.push(o)}}),t}function c(e){return e&&e.$evalAsync&&e.$watch}function d(){return function(e,t){return e>t}}function f(){return function(e,t){return e>=t}}function m(){return function(e,t){return t>e}}function p(){return function(e,t){return t>=e}}function b(){return function(e,t){return e==t}}function h(){return function(e,t){return e!=t}}function v(){return function(e,t){return e===t}}function g(){return function(e,t){return e!==t}}function _(e){return function(t,n){return t=T(t)?r(t):t,!(!F(t)||E(n))&&t.some(function(t){return T(t)||j(n)?e(n)(t):t===n})}}function $(e,t){return t=t||0,t>=e.length?e:F(e[t])?$(e.slice(0,t).concat(e[t],e.slice(t+1)),t):$(e,t+1)}function w(e){return function(t,n){function a(e,t){return!E(t)&&e.some(function(e){return N(e,t)})}if(t=T(t)?r(t):t,!F(t))return t;var o=[],i=e(n);return t.filter(E(n)?function(e,t,n){return n.indexOf(e)===t}:function(e){var t=i(e);return!a(o,t)&&(o.push(t),!0)})}}function y(e,t,n){return t?e+n+y(e,--t,n):e}var D=t.isDefined,E=t.isUndefined,j=t.isFunction,C=t.isString,R=t.isNumber,T=t.isObject,F=t.isArray,x=t.forEach,A=t.extend,S=t.copy,N=t.equals;String.prototype.contains||(String.prototype.contains=function(){return-1!==String.prototype.indexOf.apply(this,arguments)}),t.module("a8m.angular",[]).filter("isUndefined",function(){return function(e){return t.isUndefined(e)}}).filter("isDefined",function(){return function(e){return t.isDefined(e)}}).filter("isFunction",function(){return function(e){return t.isFunction(e)}}).filter("isString",function(){return function(e){return t.isString(e)}}).filter("isNumber",function(){return function(e){return t.isNumber(e)}}).filter("isArray",function(){return function(e){return t.isArray(e)}}).filter("isObject",function(){return function(e){return t.isObject(e)}}).filter("isEqual",function(){return function(e,n){return t.equals(e,n)}}),t.module("a8m.conditions",[]).filter({isGreaterThan:d,">":d,isGreaterThanOrEqualTo:f,">=":f,isLessThan:m,"<":m,isLessThanOrEqualTo:p,"<=":p,isEqualTo:b,"==":b,isNotEqualTo:h,"!=":h,isIdenticalTo:v,"===":v,isNotIdenticalTo:g,"!==":g}),t.module("a8m.is-null",[]).filter("isNull",function(){return function(e){return a(e)}}),t.module("a8m.after-where",[]).filter("afterWhere",function(){return function(e,t){if(e=T(e)?r(e):e,!F(e)||E(t))return e;var n=e.map(function(e){return o(t,e)}).indexOf(!0);return e.slice(-1===n?0:n)}}),t.module("a8m.after",[]).filter("after",function(){return function(e,t){return e=T(e)?r(e):e,F(e)?e.slice(t):e}}),t.module("a8m.before-where",[]).filter("beforeWhere",function(){return function(e,t){if(e=T(e)?r(e):e,!F(e)||E(t))return e;var n=e.map(function(e){return o(t,e)}).indexOf(!0);return e.slice(0,-1===n?e.length:++n)}}),t.module("a8m.before",[]).filter("before",function(){return function(e,t){return e=T(e)?r(e):e,F(e)?e.slice(0,t?--t:t):e}}),t.module("a8m.concat",[]).filter("concat",[function(){return function(e,t){if(E(t))return e;if(F(e))return e.concat(T(t)?r(t):t);if(T(e)){return r(e).concat(T(t)?r(t):t)}return e}}]),t.module("a8m.contains",[]).filter({contains:["$parse",_],some:["$parse",_]}),t.module("a8m.count-by",[]).filter("countBy",["$parse",function(e){return function(t,n){var a,o={},i=e(n);return t=T(t)?r(t):t,!F(t)||E(n)?t:(t.forEach(function(e){a=i(e),o[a]||(o[a]=0),o[a]++}),o)}}]),t.module("a8m.defaults",[]).filter("defaults",["$parse",function(e){return function(t,n){if(t=T(t)?r(t):t,!F(t)||!T(n))return t;var a=u(n);return t.forEach(function(t){a.forEach(function(r){var a=e(r),o=a.assign;E(a(t))&&o(t,a(n))})}),t}}]),t.module("a8m.every",[]).filter("every",["$parse",function(e){return function(t,n){return t=T(t)?r(t):t,!(F(t)&&!E(n))||t.every(function(t){return T(t)||j(n)?e(n)(t):t===n})}}]),t.module("a8m.filter-by",[]).filter("filterBy",["$parse",function(e){return function(t,a,o){var i;return o=C(o)||R(o)?String(o).toLowerCase():n,t=T(t)?r(t):t,!F(t)||E(o)?t:t.filter(function(t){return a.some(function(n){if(~n.indexOf("+")){var r=n.replace(new RegExp("\\s","g"),"").split("+");i=r.reduce(function(n,r,a){return 1===a?e(n)(t)+" "+e(r)(t):n+" "+e(r)(t)})}else i=e(n)(t);return!(!C(i)&&!R(i))&&String(i).toLowerCase().contains(o)})})}}]),t.module("a8m.first",[]).filter("first",["$parse",function(e){return function(t){var a,o,i;return t=T(t)?r(t):t,F(t)?(i=Array.prototype.slice.call(arguments,1),a=R(i[0])?i[0]:1,o=R(i[0])?R(i[1])?n:i[1]:i[0],i.length?s(t,a,o?e(o):o):t[0]):t}}]),t.module("a8m.flatten",[]).filter("flatten",function(){return function(e,t){return t=t||!1,e=T(e)?r(e):e,F(e)?t?[].concat.apply([],e):$(e,0):e}}),t.module("a8m.fuzzy-by",[]).filter("fuzzyBy",["$parse",function(e){return function(t,n,a,o){var s,l,u=o||!1;return t=T(t)?r(t):t,!F(t)||E(n)||E(a)?t:(l=e(n),t.filter(function(e){return s=l(e),!!C(s)&&(s=u?s:s.toLowerCase(),a=u?a:a.toLowerCase(),!1!==i(s,a))}))}}]),t.module("a8m.fuzzy",[]).filter("fuzzy",function(){return function(e,t,n){function a(e,t){var n,r;return 0=0&&R(t)&&isFinite(t)?1024>t?l(t,n,e)+" B":1048576>t?l(t/1024,n,e)+" KB":1073741824>t?l(t/1048576,n,e)+" MB":l(t/1073741824,n,e)+" GB":"NaN"}}]),t.module("a8m.math.degrees",["a8m.math"]).filter("degrees",["$math",function(e){return function(t,n){if(R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)){var r=180*t/e.PI;return e.round(r*e.pow(10,n))/e.pow(10,n)}return"NaN"}}]),t.module("a8m.math.kbFmt",["a8m.math"]).filter("kbFmt",["$math",function(e){return function(t,n){return R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)?1024>t?l(t,n,e)+" KB":1048576>t?l(t/1024,n,e)+" MB":l(t/1048576,n,e)+" GB":"NaN"}}]),t.module("a8m.math",[]).factory("$math",["$window",function(e){return e.Math}]),t.module("a8m.math.max",["a8m.math"]).filter("max",["$math","$parse",function(e,t){function n(n,r){var a=n.map(function(e){return t(r)(e)});return a.indexOf(e.max.apply(e,a))}return function(t,r){return F(t)?E(r)?e.max.apply(e,t):t[n(t,r)]:t}}]),t.module("a8m.math.min",["a8m.math"]).filter("min",["$math","$parse",function(e,t){function n(n,r){var a=n.map(function(e){return t(r)(e)});return a.indexOf(e.min.apply(e,a))}return function(t,r){return F(t)?E(r)?e.min.apply(e,t):t[n(t,r)]:t}}]),t.module("a8m.math.percent",["a8m.math"]).filter("percent",["$math","$window",function(e,t){return function(n,r,a){var o=C(n)?t.Number(n):n;return r=r||100,a=a||!1,!R(o)||t.isNaN(o)?n:a?e.round(o/r*100):o/r*100}}]),t.module("a8m.math.radians",["a8m.math"]).filter("radians",["$math",function(e){return function(t,n){if(R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)){var r=3.14159265359*t/180;return e.round(r*e.pow(10,n))/e.pow(10,n)}return"NaN"}}]),t.module("a8m.math.radix",[]).filter("radix",function(){return function(e,t){var n=/^[2-9]$|^[1-2]\d$|^3[0-6]$/;return R(e)&&n.test(t)?e.toString(t).toUpperCase():e}}),t.module("a8m.math.shortFmt",["a8m.math"]).filter("shortFmt",["$math",function(e){return function(t,n){return R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)?1e3>t?t:1e6>t?l(t/1e3,n,e)+" K":1e9>t?l(t/1e6,n,e)+" M":l(t/1e9,n,e)+" B":"NaN"}}]),t.module("a8m.math.sum",[]).filter("sum",function(){return function(e,t){return F(e)?e.reduce(function(e,t){return e+t},t||0):e}}),t.module("a8m.ends-with",[]).filter("endsWith",function(){return function(e,t,n){var r,a=n||!1;return!C(e)||E(t)?e:(e=a?e:e.toLowerCase(),r=e.length-t.length,-1!==e.indexOf(a?t:t.toLowerCase(),r))}}),t.module("a8m.latinize",[]).filter("latinize",[function(){function e(e){return e.replace(/[^\u0000-\u007E]/g,function(e){return n[e]||e})}for(var t=[{base:"A",letters:"AⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ"},{base:"AA",letters:"Ꜳ"},{base:"AE",letters:"ÆǼǢ"},{base:"AO",letters:"Ꜵ"},{base:"AU",letters:"Ꜷ"},{base:"AV",letters:"ꜸꜺ"},{base:"AY",letters:"Ꜽ"},{base:"B",letters:"BⒷBḂḄḆɃƂƁ"},{base:"C",letters:"CⒸCĆĈĊČÇḈƇȻꜾ"},{base:"D",letters:"DⒹDḊĎḌḐḒḎĐƋƊƉꝹ"},{base:"DZ",letters:"DZDŽ"},{base:"Dz",letters:"DzDž"},{base:"E",letters:"EⒺEÈÉÊỀẾỄỂẼĒḔḖĔĖËẺĚȄȆẸỆȨḜĘḘḚƐƎ"},{base:"F",letters:"FⒻFḞƑꝻ"},{base:"G",letters:"GⒼGǴĜḠĞĠǦĢǤƓꞠꝽꝾ"},{base:"H",letters:"HⒽHĤḢḦȞḤḨḪĦⱧⱵꞍ"},{base:"I",letters:"IⒾIÌÍÎĨĪĬİÏḮỈǏȈȊỊĮḬƗ"},{base:"J",letters:"JⒿJĴɈ"},{base:"K",letters:"KⓀKḰǨḲĶḴƘⱩꝀꝂꝄꞢ"},{base:"L",letters:"LⓁLĿĹĽḶḸĻḼḺŁȽⱢⱠꝈꝆꞀ"},{base:"LJ",letters:"LJ"},{base:"Lj",letters:"Lj"},{base:"M",letters:"MⓂMḾṀṂⱮƜ"},{base:"N",letters:"NⓃNǸŃÑṄŇṆŅṊṈȠƝꞐꞤ"},{base:"NJ",letters:"NJ"},{base:"Nj",letters:"Nj"},{base:"O",letters:"OⓄOÒÓÔỒỐỖỔÕṌȬṎŌṐṒŎȮȰÖȪỎŐǑȌȎƠỜỚỠỞỢỌỘǪǬØǾƆƟꝊꝌ"},{base:"OI",letters:"Ƣ"},{base:"OO",letters:"Ꝏ"},{base:"OU",letters:"Ȣ"},{base:"OE",letters:"ŒŒ"},{base:"oe",letters:"œœ"},{base:"P",letters:"PⓅPṔṖƤⱣꝐꝒꝔ"},{base:"Q",letters:"QⓆQꝖꝘɊ"},{base:"R",letters:"RⓇRŔṘŘȐȒṚṜŖṞɌⱤꝚꞦꞂ"},{base:"S",letters:"SⓈSẞŚṤŜṠŠṦṢṨȘŞⱾꞨꞄ"},{base:"T",letters:"TⓉTṪŤṬȚŢṰṮŦƬƮȾꞆ"},{base:"TZ",letters:"Ꜩ"},{base:"U",letters:"UⓊUÙÚÛŨṸŪṺŬÜǛǗǕǙỦŮŰǓȔȖƯỪỨỮỬỰỤṲŲṶṴɄ"},{base:"V",letters:"VⓋVṼṾƲꝞɅ"},{base:"VY",letters:"Ꝡ"},{base:"W",letters:"WⓌWẀẂŴẆẄẈⱲ"},{base:"X",letters:"XⓍXẊẌ"},{base:"Y",letters:"YⓎYỲÝŶỸȲẎŸỶỴƳɎỾ"},{base:"Z",letters:"ZⓏZŹẐŻŽẒẔƵȤⱿⱫꝢ"},{base:"a",letters:"aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐ"},{base:"aa",letters:"ꜳ"},{base:"ae",letters:"æǽǣ"},{base:"ao",letters:"ꜵ"},{base:"au",letters:"ꜷ"},{base:"av",letters:"ꜹꜻ"},{base:"ay",letters:"ꜽ"},{base:"b",letters:"bⓑbḃḅḇƀƃɓ"},{base:"c",letters:"cⓒcćĉċčçḉƈȼꜿↄ"},{base:"d",letters:"dⓓdḋďḍḑḓḏđƌɖɗꝺ"},{base:"dz",letters:"dzdž"},{base:"e",letters:"eⓔeèéêềếễểẽēḕḗĕėëẻěȅȇẹệȩḝęḙḛɇɛǝ"},{base:"f",letters:"fⓕfḟƒꝼ"},{base:"g",letters:"gⓖgǵĝḡğġǧģǥɠꞡᵹꝿ"},{base:"h",letters:"hⓗhĥḣḧȟḥḩḫẖħⱨⱶɥ"},{base:"hv",letters:"ƕ"},{base:"i",letters:"iⓘiìíîĩīĭïḯỉǐȉȋịįḭɨı"},{base:"j",letters:"jⓙjĵǰɉ"},{base:"k",letters:"kⓚkḱǩḳķḵƙⱪꝁꝃꝅꞣ"},{base:"l",letters:"lⓛlŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇ"},{base:"lj",letters:"lj"},{base:"m",letters:"mⓜmḿṁṃɱɯ"},{base:"n",letters:"nⓝnǹńñṅňṇņṋṉƞɲʼnꞑꞥ"},{base:"nj",letters:"nj"},{base:"o",letters:"oⓞoòóôồốỗổõṍȭṏōṑṓŏȯȱöȫỏőǒȍȏơờớỡởợọộǫǭøǿɔꝋꝍɵ"},{base:"oi",letters:"ƣ"},{base:"ou",letters:"ȣ"},{base:"oo",letters:"ꝏ"},{base:"p",letters:"pⓟpṕṗƥᵽꝑꝓꝕ"},{base:"q",letters:"qⓠqɋꝗꝙ"},{base:"r",letters:"rⓡrŕṙřȑȓṛṝŗṟɍɽꝛꞧꞃ"},{base:"s",letters:"sⓢsßśṥŝṡšṧṣṩșşȿꞩꞅẛ"},{base:"t",letters:"tⓣtṫẗťṭțţṱṯŧƭʈⱦꞇ"},{base:"tz",letters:"ꜩ"},{base:"u",letters:"uⓤuùúûũṹūṻŭüǜǘǖǚủůűǔȕȗưừứữửựụṳųṷṵʉ"},{base:"v",letters:"vⓥvṽṿʋꝟʌ"},{base:"vy",letters:"ꝡ"},{base:"w",letters:"wⓦwẁẃŵẇẅẘẉⱳ"},{base:"x",letters:"xⓧxẋẍ"},{base:"y",letters:"yⓨyỳýŷỹȳẏÿỷẙỵƴɏỿ"},{base:"z",letters:"zⓩzźẑżžẓẕƶȥɀⱬꝣ"}],n={},r=0;r<]*>/g,""):e}}),t.module("a8m.test",[]).filter("test",function(){return function(e,t,n){var r=new RegExp(t,n);return C(e)?r.test(e):e}}),t.module("a8m.trim",[]).filter("trim",function(){return function(e,t){var n=t||"\\s";return C(e)?e.replace(new RegExp("^"+n+"+|"+n+"+$","g"),""):e}}),t.module("a8m.truncate",[]).filter("truncate",function(){return function(e,t,n,r){return t=E(t)?e.length:t,r=r||!1,n=n||"",!C(e)||e.length<=t?e:e.substring(0,r?-1===e.indexOf(" ",t)?e.length:e.indexOf(" ",t):t)+n}}),t.module("a8m.ucfirst",[]).filter("ucfirst",[function(){return function(e){return C(e)?e.split(" ").map(function(e){return e.charAt(0).toUpperCase()+e.substring(1)}).join(" "):e}}]),t.module("a8m.uri-component-encode",[]).filter("uriComponentEncode",["$window",function(e){return function(t){return C(t)?e.encodeURIComponent(t):t}}]),t.module("a8m.uri-encode",[]).filter("uriEncode",["$window",function(e){return function(t){return C(t)?e.encodeURI(t):t}}]),t.module("a8m.wrap",[]).filter("wrap",function(){return function(e,t,n){return C(e)&&D(t)?[t,e,n||t].join(""):e}}),t.module("a8m.filter-watcher",[]).provider("filterWatcher",function(){this.$get=["$window","$rootScope",function(e,n){function r(e,n){return[e,t.toJson(n)].join("#").replace(/"/g,"")}function a(e){var t=e.targetScope.$id;x(d[t],function(e){delete u[e]}),delete d[t]}function o(){f(function(){n.$$phase||(u={})})}function i(e,t){var n=e.$id;return E(d[n])&&(e.$on("$destroy",a),d[n]=[]),d[n].push(t)}function s(e,t){var n=r(e,t);return u[n]}function l(e,t,n,a){var s=r(e,t);return u[s]=a,c(n)?i(n,s):o(),a}var u={},d={},f=e.setTimeout;return{isMemoized:s,memoize:l}}]}),t.module("angular.filter",["a8m.ucfirst","a8m.uri-encode","a8m.uri-component-encode","a8m.slugify","a8m.latinize","a8m.strip-tags","a8m.stringular","a8m.truncate","a8m.starts-with","a8m.ends-with","a8m.wrap","a8m.trim","a8m.ltrim","a8m.rtrim","a8m.repeat","a8m.test","a8m.match","a8m.to-array","a8m.concat","a8m.contains","a8m.unique","a8m.is-empty","a8m.after","a8m.after-where","a8m.before","a8m.before-where","a8m.defaults","a8m.where","a8m.reverse","a8m.remove","a8m.remove-with","a8m.group-by","a8m.count-by","a8m.search-field","a8m.fuzzy-by","a8m.fuzzy","a8m.omit","a8m.pick","a8m.every","a8m.filter-by","a8m.xor","a8m.map","a8m.first","a8m.last","a8m.flatten","a8m.join","a8m.math","a8m.math.max","a8m.math.min","a8m.math.percent","a8m.math.radix","a8m.math.sum","a8m.math.degrees","a8m.math.radians","a8m.math.byteFmt","a8m.math.kbFmt","a8m.math.shortFmt","a8m.angular","a8m.conditions","a8m.is-null","a8m.filter-watcher"])}(window,window.angular),define("job-roles/modules/job-roles.core",["common/angular","common/ui-select","common/directives/angular-date/date-input","common/modules/directives","common/modules/routers/compu-ng-route","common/filters/angular-date/format-date","common/services/angular-date/date-format","common/services/dom-event-trigger","common/services/pub-sub","job-roles/vendor/angular-editable","job-roles/vendor/angular-filter"],function(e){"use strict";e.module("hrjobroles.core",["angular.filter","ngAnimate","ngSanitize","ngResource","ui.bootstrap","ui.select","xeditable","common.angularDate","common.directives","common.services","compuNgRoute"])}),define("job-roles/filters/get-active-values.filter",["common/lodash"],function(e){"use strict";function t(t){return t.debug("Filter: getActiveValues"),function(t){var n={};return e.each(t,function(e,t){"1"===e.is_active&&(n[t]=e)}),n}}return t.__name="getActiveValues",t.$inject=["$log"],t}),define("job-roles/modules/job-roles.filters",["common/angular","job-roles/filters/get-active-values.filter"],function(e,t){"use strict";return e.module("hrjobroles.filters",[]).filter(t.__name,t)}),define("job-roles/modules/job-roles.run",["common/angular"],function(e){"use strict";function t(e,t,n,r){n.theme="bs3",t.contactId=r.contactId,t.pathBaseUrl=r.pathBaseUrl,t.pathTpl=r.pathTpl,t.pathIncludeTpl=r.pathIncludeTpl,t.prefix=r.classNamePrefix}e.module("hrjobroles.run",["hrjobroles.constants"]).run(t),t.$inject=["$q","$rootScope","editableOptions","settings"]}),define("job-roles/services/date-validation.service",["common/moment"],function(e){function t(t){function n(e,t){e.isValid()||l("Date is not valid!!",t)}function r(e,t){e.isSameOrAfter(t)&&l("Start Date cannot be the same as or after the End Date.",["start_date","end_date"])}function a(e,t){e.isBefore(t)&&l("Start Date cannot be lower than Contract Start Date.",["start_date"])}function o(e,t){e.isAfter(t)&&l("Start Date cannot be higher than Contract End Date.",["start_date"])}function i(e,t){e.isAfter(t)&&l("End Date cannot be higher than Contract End Date.",["end_date"])}function s(t,n){return t instanceof Date&&(t=e(t).valueOf()),e(t,n,!0).startOf("day")}var l=function(e,t){throw new Error(e,t[0])},u={dateFormats:["x","YYYY-MM-DD"],setErrorCallback:function(e){if("function"!=typeof e)throw new TypeError("Error callback must be a function.");l=e},validate:function(e,t,l,u){e=s(e,this.dateFormats),l=s(l,this.dateFormats),u=s(u,this.dateFormats),n(e,["start_date"]),o(e,u),a(e,l),(0===t||t)&&(t=s(t,this.dateFormats),n(t,["end_date"]),i(t,u),r(e,t))}};return t.DATE_FORMAT&&u.dateFormats.push(t.DATE_FORMAT.toUpperCase()),u}return t.__name="dateValidation",t.$inject=["HR_settings"],t}),define("job-roles/services/filters.service",[],function(){"use strict";function e(){return{isNotUndefined:function(e){try{return e.constructor===Array?e.filter(function(e){return"undefined"!==e&&void 0!==e}):e}catch(t){return e}},issetCostCentre:function(e){try{return e.constructor===Array?e.filter(function(e){return""!==e.cost_centre_id&&("1"===e.type&&parseInt(e.percentage)>0||"0"===e.type&&parseInt(e.amount)>0)}):e}catch(t){return e}},issetFunder:function(e){try{return e.constructor===Array?e.filter(function(e){return""!==e.funder_id&&("1"===e.type&&parseInt(e.percentage)>0||"0"===e.type&&parseInt(e.amount)>0)}):e}catch(t){return e}}}}return e.__name="filtersService",e}),define("job-roles/services/job-role.service",["common/lodash"],function(e){"use strict";function t(t,n,r){function a(n){var r=n["api.HRJobContractRevision.get"].values;delete n["api.HRJobContractRevision.get"],n.revisions=e.compact(r.map(function(e){var r=e["api.HRJobDetails.getsingle"];return r.period_start_date===n.period_start_date&&r.period_end_date===n.period_end_date?null:(r.period_start_date=t("formatDate")(r.period_start_date),r.period_end_date=t("formatDate")(r.period_end_date),r)}))}return{getContracts:function(e){var t=r.defer();return CRM.api3("HRJobContract","get",{sequential:1,contact_id:e,deleted:0,return:"title,period_end_date,period_start_date","api.HRJobContractRevision.get":{jobcontract_id:"$value.id","api.HRJobDetails.getsingle":{jobcontract_revision_id:"$value.id"}}}).done(function(e){e.values.forEach(a),t.resolve(e)}).error(function(){t.reject("An error occured while fetching items")}),t.promise},getAllJobRoles:function(e){var t=r.defer();return CRM.api3("HrJobRoles","get",{sequential:1,return:"id,job_contract_id,title,description,status,funder,funder_val_type,percent_pay_funder,amount_pay_funder,cost_center,cost_center_val_type,percent_pay_cost_center,amount_pay_cost_center,level_type,location,region,department,end_date,start_date",job_contract_id:{IN:e}}).done(function(e){t.resolve(e)}).error(function(e){t.reject("An error occured while fetching items")}),t.promise},deleteJobRole:function(e){var t=r.defer();return CRM.api3("HrJobRoles","delete",{sequential:1,id:e}).done(function(e){t.resolve(e)}).error(function(e){t.reject("An error occured while deleting items")}),t.promise},createJobRole:function(e){var t="|",n="|",a="|",o="|",i="|",s="|",l="|",u="|";if(void 0!==e.funders)for(var c=0,d=e.funders.length;c-1&&t.start.push(e),r.indexOf("end_date")>-1&&t.end.push(e)}),b.validate(e.start,e.end,e.contractStart,e.contractEnd),0===n}function $e(e){e.start_date.$error.custom=[],e.end_date.$error.custom=[];var t=L(e.contract.$viewValue);return void 0===t?"Contract is missing":!!_e({start:e.start_date.$viewValue,end:e.end_date.$viewValue,contractStart:t.start_date,contractEnd:t.end_date},{start:e.start_date.$error.custom,end:e.end_date.$error.custom})||"Error"}function we(e){if("title"===e||" "===e)return"Title cannot be title!"}a.debug("Controller: JobRolesController");var ye=r("formatDate"),De={},Ee=r("getActiveValues"),je=["funders","cost_centers"],Ce=this;Ce.contactId=m.contactId,Ce.format=p.DATE_FORMAT,Ce.loading=!0,Ce.pastJobRoles=[],Ce.presentJobRoles=[],Ce.collapsedRows=[],Ce.contactList=[],Ce.editData={},Ce.viewTab=[],Ce.CalendarShow=[],Ce.contractsData=[],Ce.DepartmentsData={},Ce.LevelsData={},Ce.LocationsData={},Ce.RegionsData={},Ce.addNewRoleUrl=m.pathBaseUrl+m.pathIncludeTpl+"add_new_role.html",Ce.jobRolePanelUrl=m.pathBaseUrl+m.pathIncludeTpl+"job_role_panel.html",Ce.rowTypes={},Ce.rowTypes[0]={id:0,name:"Fixed"},Ce.rowTypes[1]={id:1,name:"%"},Ce.addAdditionalRow=$,Ce.addNewRole=w,Ce.cancelNewRole=y,Ce.changeTab=D,Ce.checkIfDatesAreCustom=E,Ce.checkNewRole=j,Ce.collapseRow=C,Ce.deleteAdditionalRow=x,Ce.dpOpen=S,Ce.getContactList=J,Ce.getCostLabel=U,Ce.initData=P,Ce.isChanged=G,Ce.isOpen=Z,Ce.isRowCollapsed=X,Ce.isTab=Q,Ce.onAfterSave=ee,Ce.onCancel=te,Ce.onContractEdited=ne,Ce.onContractSelected=re,Ce.open=ae,Ce.removeRole=ie,Ce.saveNewRole=se,Ce.select=le,Ce.showRowType=ue,Ce.showSave=ce,Ce.status="",Ce.today=fe,Ce.updateAdditionalRowType=me,Ce.updateRole=ve,Ce.validateRole=$e,Ce.validateTitle=we,Ce.openOptionsEditor=q,function(){de(),Ce.today(),o.all([W(),I(Ce.contactId),Ce.getContactList()]).then(function(){Ce.loading=!1})}()}return r.__name="JobRolesController",r.$inject=["$filter","$log","$q","$rootElement","$route","$routeParams","$scope","$timeout","$uibModal","DOMEventTrigger","settings","HR_settings","dateValidation","filtersService","jobRoleService","pubSub","crmAngService"],r}),define("job-roles/controllers/modal-dialog.controller",[],function(){"use strict";function e(e,t,n,r){function a(){e.dismiss("Cancel")}function o(t){e.close(t||!0)}t.debug("Controller: ModalDialogController");var i=this;i.copyCancel=r.copyCancel||"Cancel",i.copyConfirm=r.copyConfirm||"Yes",i.msg=r.msg||"",i.title=r.title||"CiviHR Job Roles",i.cancel=a,i.confirm=o}return e.__name="ModalDialogController",e.$inject=["$uibModalInstance","$log","$timeout","content"],e}),define("job-roles/modules/job-roles.controllers",["common/angular","job-roles/controllers/job-roles.controller","job-roles/controllers/modal-dialog.controller"],function(e,t,n){"use strict";return e.module("hrjobroles.controllers",[]).controller(t.__name,t).controller(n.__name,n)}),angular.module("xeditable",[]).value("editableOptions",{theme:"default",buttons:"right",blurElem:"cancel",blurForm:"ignore",activate:"focus"}),angular.module("xeditable").directive("editableBsdate",["editableDirectiveFactory",function(e){return e({directiveName:"editableBsdate",inputTpl:''})}]),angular.module("xeditable").directive("editableBstime",["editableDirectiveFactory",function(e){return e({directiveName:"editableBstime",inputTpl:"",render:function(){this.parent.render.call(this);var e=angular.element('
    ');e.attr("ng-model",this.inputEl.attr("ng-model")),this.inputEl.removeAttr("ng-model"),this.attrs.eNgChange&&(e.attr("ng-change",this.inputEl.attr("ng-change")),this.inputEl.removeAttr("ng-change")),this.inputEl.wrap(e)}})}]),angular.module("xeditable").directive("editableCheckbox",["editableDirectiveFactory",function(e){return e({directiveName:"editableCheckbox",inputTpl:'',render:function(){this.parent.render.call(this),this.attrs.eTitle&&(this.inputEl.wrap(""),this.inputEl.after(angular.element("").text(this.attrs.eTitle)))},autosubmit:function(){var e=this;e.inputEl.bind("change",function(){setTimeout(function(){e.scope.$apply(function(){e.scope.$form.$submit()})},500)})}})}]),angular.module("xeditable").directive("editableChecklist",["editableDirectiveFactory","editableNgOptionsParser",function(e,t){return e({directiveName:"editableChecklist",inputTpl:"",useCopy:!0,render:function(){this.parent.render.call(this);var e=t(this.attrs.eNgOptions),n='';this.inputEl.removeAttr("ng-model"),this.inputEl.removeAttr("ng-options"),this.inputEl.html(n)}})}]),function(){var e="text|email|tel|number|url|search|color|date|datetime|time|month|week".split("|");angular.forEach(e,function(e){var t="editable"+e.charAt(0).toUpperCase()+e.slice(1);angular.module("xeditable").directive(t,["editableDirectiveFactory",function(n){return n({directiveName:t,inputTpl:''})}])}),angular.module("xeditable").directive("editableRange",["editableDirectiveFactory",function(e){return e({directiveName:"editableRange",inputTpl:'',render:function(){this.parent.render.call(this),this.inputEl.after("{{$data}}")}})}])}(),angular.module("xeditable").directive("editableRadiolist",["editableDirectiveFactory","editableNgOptionsParser",function(e,t){return e({directiveName:"editableRadiolist",inputTpl:"",render:function(){this.parent.render.call(this);var e=t(this.attrs.eNgOptions),n='';this.inputEl.removeAttr("ng-model"),this.inputEl.removeAttr("ng-options"),this.inputEl.html(n)},autosubmit:function(){var e=this;e.inputEl.bind("change",function(){setTimeout(function(){e.scope.$apply(function(){e.scope.$form.$submit()})},500)})}})}]),angular.module("xeditable").directive("editableSelect",["editableDirectiveFactory",function(e){return e({directiveName:"editableSelect",inputTpl:"",autosubmit:function(){var e=this;e.inputEl.bind("change",function(){e.scope.$apply(function(){e.scope.$form.$submit()})})}})}]),angular.module("xeditable").directive("editableTextarea",["editableDirectiveFactory",function(e){return e({directiveName:"editableTextarea",inputTpl:"",addListeners:function(){var e=this;e.parent.addListeners.call(e),e.single&&"no"!==e.buttons&&e.autosubmit()},autosubmit:function(){var e=this;e.inputEl.bind("keydown",function(t){(t.ctrlKey||t.metaKey)&&13===t.keyCode&&e.scope.$apply(function(){e.scope.$form.$submit()})})}})}]),angular.module("xeditable").factory("editableController",["$q","editableUtils",function(e,t){function n(e,n,r,a,o,i,s,l,u){var c,d,f=this;f.scope=e,f.elem=r,f.attrs=n,f.inputEl=null,f.editorEl=null,f.single=!0,f.error="",f.theme=o[i.theme]||o.default,f.parent={},f.inputTpl="",f.directiveName="",f.useCopy=!1,f.single=null,f.buttons="right",f.init=function(t){if(f.single=t,f.name=n.eName||n[f.directiveName],!n[f.directiveName])throw"You should provide value for `"+f.directiveName+"` in editable element!";c=a(n[f.directiveName]),f.buttons=f.single?f.attrs.buttons||i.buttons:"no",n.eName&&f.scope.$watch("$data",function(e){f.scope.$form.$data[n.eName]=e}),n.onshow&&(f.onshow=function(){return f.catchError(a(n.onshow)(e))}),n.onhide&&(f.onhide=function(){return a(n.onhide)(e)}),n.oncancel&&(f.oncancel=function(){return a(n.oncancel)(e)}),n.onbeforesave&&(f.onbeforesave=function(){return f.catchError(a(n.onbeforesave)(e))}),n.onaftersave&&(f.onaftersave=function(){return f.catchError(a(n.onaftersave)(e))}),e.$parent.$watch(n[f.directiveName],function(){f.handleEmpty()})},f.render=function(){var e=f.theme;f.inputEl=angular.element(f.inputTpl),f.controlsEl=angular.element(e.controlsTpl),f.controlsEl.append(f.inputEl),"no"!==f.buttons&&(f.buttonsEl=angular.element(e.buttonsTpl),f.submitEl=angular.element(e.submitTpl),f.cancelEl=angular.element(e.cancelTpl),f.buttonsEl.append(f.submitEl).append(f.cancelEl),f.controlsEl.append(f.buttonsEl),f.inputEl.addClass("editable-has-buttons")),f.errorEl=angular.element(e.errorTpl),f.controlsEl.append(f.errorEl),f.editorEl=angular.element(f.single?e.formTpl:e.noformTpl),f.editorEl.append(f.controlsEl);for(var r in n.$attr)if(!(r.length<=1)){var a=!1,o=r.substring(1,2);if("e"===r.substring(0,1)&&o===o.toUpperCase()&&"Form"!==(a=r.substring(1))&&"NgSubmit"!==a){a=a.substring(0,1).toLowerCase()+t.camelToDash(a.substring(1));var s=""===n[r]?a:n[r];f.inputEl.attr(a,s)}}f.inputEl.addClass("editable-input"),f.inputEl.attr("ng-model","$data"),f.editorEl.addClass(t.camelToDash(f.directiveName)),f.single&&(f.editorEl.attr("editable-form","$form"),f.editorEl.attr("blur",f.attrs.blur||("no"===f.buttons?"cancel":i.blurElem))),angular.isFunction(e.postrender)&&e.postrender.call(f)},f.setLocalValue=function(){f.scope.$data=f.useCopy?angular.copy(c(e.$parent)):c(e.$parent)},f.show=function(){return f.setLocalValue(),f.render(),r.after(f.editorEl),l(f.editorEl)(e),f.addListeners(),r.addClass("editable-hide"),f.onshow()},f.hide=function(){return f.editorEl.remove(),r.removeClass("editable-hide"),f.onhide()},f.cancel=function(){f.oncancel()},f.addListeners=function(){f.inputEl.bind("keyup",function(e){if(f.single)switch(e.keyCode){case 27:f.scope.$apply(function(){f.scope.$form.$cancel()})}}),f.single&&"no"===f.buttons&&f.autosubmit(),f.editorEl.bind("click",function(e){1===e.which&&f.scope.$form.$visible&&(f.scope.$form._clicked=!0)})},f.setWaiting=function(e){e?(d=!f.inputEl.attr("disabled")&&!f.inputEl.attr("ng-disabled")&&!f.inputEl.attr("ng-enabled"))&&(f.inputEl.attr("disabled","disabled"),f.buttonsEl&&f.buttonsEl.find("button").attr("disabled","disabled")):d&&(f.inputEl.removeAttr("disabled"),f.buttonsEl&&f.buttonsEl.find("button").removeAttr("disabled"))},f.activate=function(){setTimeout(function(){var e=f.inputEl[0];"focus"===i.activate&&e.focus&&e.focus(),"select"===i.activate&&e.select&&e.select()},0)},f.setError=function(t){angular.isObject(t)||(e.$error=t,f.error=t)},f.catchError=function(e,t){return angular.isObject(e)&&!0!==t?u.when(e).then(angular.bind(this,function(e){this.catchError(e,!0)}),angular.bind(this,function(e){this.catchError(e,!0)})):t&&angular.isObject(e)&&e.status&&200!==e.status&&e.data&&angular.isString(e.data)?(this.setError(e.data),e=e.data):angular.isString(e)&&this.setError(e),e},f.save=function(){c.assign(e.$parent,angular.copy(f.scope.$data))},f.handleEmpty=function(){var t=c(e.$parent),n=null===t||void 0===t||""===t||angular.isArray(t)&&0===t.length;r.toggleClass("editable-empty",n)},f.autosubmit=angular.noop,f.onshow=angular.noop,f.onhide=angular.noop,f.oncancel=angular.noop,f.onbeforesave=angular.noop,f.onaftersave=angular.noop}return n.$inject=["$scope","$attrs","$element","$parse","editableThemes","editableOptions","$rootScope","$compile","$q"],n}]),angular.module("xeditable").factory("editableDirectiveFactory",["$parse","$compile","editableThemes","$rootScope","$document","editableController","editableFormController",function(e,t,n,r,a,o,i){return function(t){return{restrict:"A",scope:!0,require:[t.directiveName,"?^form"],controller:o,link:function(n,o,s,l){var u,c=l[0],d=!1;if(l[1])u=l[1],d=!0;else if(s.eForm){var f=e(s.eForm)(n);if(f)u=f,d=!0;else for(var m=0;m=0&&e.splice(n,1),t},camelToDash:function(e){var t=/[A-Z]/g;return e.replace(t,function(e,t){return(t?"-":"")+e.toLowerCase()})},dashToCamel:function(e){var t=/([\:\-\_]+(.))/g,n=/^moz([A-Z])/;return e.replace(t,function(e,t,n,r){return r?n.toUpperCase():n}).replace(n,"Moz$1")}}}]),angular.module("xeditable").factory("editableNgOptionsParser",[function(){function e(e){var n;if(!(n=e.match(t)))throw"ng-options parse error";var r,a=n[2]||n[1],o=n[4]||n[6],i=n[5],s=(n[3],n[2]?n[1]:o),l=n[7],u=n[8],c=u?n[8]:null;return void 0===i?(r=o+" in "+l,void 0!==u&&(r+=" track by "+c)):r="("+i+", "+o+") in "+l,{ngRepeat:r,locals:{valueName:o,keyName:i,valueFn:s,displayFn:a}}}var t=/^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+(.*?)(?:\s+track\s+by\s+(.*?))?$/;return e}]),angular.module("xeditable").factory("editableThemes",function(){return{default:{formTpl:'
    ',noformTpl:'',controlsTpl:'',inputTpl:"",errorTpl:'
    ',buttonsTpl:'',submitTpl:'',cancelTpl:''},bs2:{formTpl:'
    ',noformTpl:'',controlsTpl:'
    ',inputTpl:"",errorTpl:'
    ',buttonsTpl:'',submitTpl:'', +cancelTpl:''},bs3:{formTpl:'
    ',noformTpl:'',controlsTpl:'
    ',inputTpl:"",errorTpl:'
    ',buttonsTpl:'',submitTpl:'',cancelTpl:'',buttonsClass:"",inputClass:"",postrender:function(){switch(this.directiveName){case"editableText":case"editableSelect":case"editableTextarea":case"editableEmail":case"editableTel":case"editableNumber":case"editableUrl":case"editableSearch":case"editableDate":case"editableDatetime":case"editableTime":case"editableMonth":case"editableWeek":if(this.inputEl.addClass("form-control"),this.theme.inputClass){if(this.inputEl.attr("multiple")&&("input-sm"===this.theme.inputClass||"input-lg"===this.theme.inputClass))break;this.inputEl.addClass(this.theme.inputClass)}}this.buttonsEl&&this.theme.buttonsClass&&this.buttonsEl.find("button").addClass(this.theme.buttonsClass)}}}}),function(e,t,n){"use strict";function r(e){return F(e)?e:Object.keys(e).map(function(t){return e[t]})}function a(e){return null===e}function o(e,t){return-1==Object.keys(e).map(function(r){return t[r]!==n&&t[r]==e[r]}).indexOf(!1)}function i(e,t){if(""===t)return e;var n=e.indexOf(t.charAt(0));return-1!==n&&i(e.substr(n+1),t.substr(1))}function s(e,t,n){var r=0;return e.filter(function(e){var a=D(n)?t>r&&n(e):t>r;return r=a?r+1:r,a})}function l(e,t,n){return n.round(e*n.pow(10,t))/n.pow(10,t)}function u(e,t,n){return t=t||[],Object.keys(e).forEach(function(r){if(T(e[r])&&!F(e[r])){var a=n?n+"."+r:n;u(e[r],t,a||r)}else{var o=n?n+"."+r:r;t.push(o)}}),t}function c(e){return e&&e.$evalAsync&&e.$watch}function d(){return function(e,t){return e>t}}function f(){return function(e,t){return e>=t}}function m(){return function(e,t){return t>e}}function p(){return function(e,t){return t>=e}}function b(){return function(e,t){return e==t}}function h(){return function(e,t){return e!=t}}function v(){return function(e,t){return e===t}}function g(){return function(e,t){return e!==t}}function _(e){return function(t,n){return t=T(t)?r(t):t,!(!F(t)||E(n))&&t.some(function(t){return T(t)||j(n)?e(n)(t):t===n})}}function $(e,t){return t=t||0,t>=e.length?e:F(e[t])?$(e.slice(0,t).concat(e[t],e.slice(t+1)),t):$(e,t+1)}function w(e){return function(t,n){function a(e,t){return!E(t)&&e.some(function(e){return N(e,t)})}if(t=T(t)?r(t):t,!F(t))return t;var o=[],i=e(n);return t.filter(E(n)?function(e,t,n){return n.indexOf(e)===t}:function(e){var t=i(e);return!a(o,t)&&(o.push(t),!0)})}}function y(e,t,n){return t?e+n+y(e,--t,n):e}var D=t.isDefined,E=t.isUndefined,j=t.isFunction,C=t.isString,R=t.isNumber,T=t.isObject,F=t.isArray,x=t.forEach,A=t.extend,S=t.copy,N=t.equals;String.prototype.contains||(String.prototype.contains=function(){return-1!==String.prototype.indexOf.apply(this,arguments)}),t.module("a8m.angular",[]).filter("isUndefined",function(){return function(e){return t.isUndefined(e)}}).filter("isDefined",function(){return function(e){return t.isDefined(e)}}).filter("isFunction",function(){return function(e){return t.isFunction(e)}}).filter("isString",function(){return function(e){return t.isString(e)}}).filter("isNumber",function(){return function(e){return t.isNumber(e)}}).filter("isArray",function(){return function(e){return t.isArray(e)}}).filter("isObject",function(){return function(e){return t.isObject(e)}}).filter("isEqual",function(){return function(e,n){return t.equals(e,n)}}),t.module("a8m.conditions",[]).filter({isGreaterThan:d,">":d,isGreaterThanOrEqualTo:f,">=":f,isLessThan:m,"<":m,isLessThanOrEqualTo:p,"<=":p,isEqualTo:b,"==":b,isNotEqualTo:h,"!=":h,isIdenticalTo:v,"===":v,isNotIdenticalTo:g,"!==":g}),t.module("a8m.is-null",[]).filter("isNull",function(){return function(e){return a(e)}}),t.module("a8m.after-where",[]).filter("afterWhere",function(){return function(e,t){if(e=T(e)?r(e):e,!F(e)||E(t))return e;var n=e.map(function(e){return o(t,e)}).indexOf(!0);return e.slice(-1===n?0:n)}}),t.module("a8m.after",[]).filter("after",function(){return function(e,t){return e=T(e)?r(e):e,F(e)?e.slice(t):e}}),t.module("a8m.before-where",[]).filter("beforeWhere",function(){return function(e,t){if(e=T(e)?r(e):e,!F(e)||E(t))return e;var n=e.map(function(e){return o(t,e)}).indexOf(!0);return e.slice(0,-1===n?e.length:++n)}}),t.module("a8m.before",[]).filter("before",function(){return function(e,t){return e=T(e)?r(e):e,F(e)?e.slice(0,t?--t:t):e}}),t.module("a8m.concat",[]).filter("concat",[function(){return function(e,t){if(E(t))return e;if(F(e))return e.concat(T(t)?r(t):t);if(T(e)){return r(e).concat(T(t)?r(t):t)}return e}}]),t.module("a8m.contains",[]).filter({contains:["$parse",_],some:["$parse",_]}),t.module("a8m.count-by",[]).filter("countBy",["$parse",function(e){return function(t,n){var a,o={},i=e(n);return t=T(t)?r(t):t,!F(t)||E(n)?t:(t.forEach(function(e){a=i(e),o[a]||(o[a]=0),o[a]++}),o)}}]),t.module("a8m.defaults",[]).filter("defaults",["$parse",function(e){return function(t,n){if(t=T(t)?r(t):t,!F(t)||!T(n))return t;var a=u(n);return t.forEach(function(t){a.forEach(function(r){var a=e(r),o=a.assign;E(a(t))&&o(t,a(n))})}),t}}]),t.module("a8m.every",[]).filter("every",["$parse",function(e){return function(t,n){return t=T(t)?r(t):t,!(F(t)&&!E(n))||t.every(function(t){return T(t)||j(n)?e(n)(t):t===n})}}]),t.module("a8m.filter-by",[]).filter("filterBy",["$parse",function(e){return function(t,a,o){var i;return o=C(o)||R(o)?String(o).toLowerCase():n,t=T(t)?r(t):t,!F(t)||E(o)?t:t.filter(function(t){return a.some(function(n){if(~n.indexOf("+")){var r=n.replace(new RegExp("\\s","g"),"").split("+");i=r.reduce(function(n,r,a){return 1===a?e(n)(t)+" "+e(r)(t):n+" "+e(r)(t)})}else i=e(n)(t);return!(!C(i)&&!R(i))&&String(i).toLowerCase().contains(o)})})}}]),t.module("a8m.first",[]).filter("first",["$parse",function(e){return function(t){var a,o,i;return t=T(t)?r(t):t,F(t)?(i=Array.prototype.slice.call(arguments,1),a=R(i[0])?i[0]:1,o=R(i[0])?R(i[1])?n:i[1]:i[0],i.length?s(t,a,o?e(o):o):t[0]):t}}]),t.module("a8m.flatten",[]).filter("flatten",function(){return function(e,t){return t=t||!1,e=T(e)?r(e):e,F(e)?t?[].concat.apply([],e):$(e,0):e}}),t.module("a8m.fuzzy-by",[]).filter("fuzzyBy",["$parse",function(e){return function(t,n,a,o){var s,l,u=o||!1;return t=T(t)?r(t):t,!F(t)||E(n)||E(a)?t:(l=e(n),t.filter(function(e){return s=l(e),!!C(s)&&(s=u?s:s.toLowerCase(),a=u?a:a.toLowerCase(),!1!==i(s,a))}))}}]),t.module("a8m.fuzzy",[]).filter("fuzzy",function(){return function(e,t,n){function a(e,t){var n,r;return 0=0&&R(t)&&isFinite(t)?1024>t?l(t,n,e)+" B":1048576>t?l(t/1024,n,e)+" KB":1073741824>t?l(t/1048576,n,e)+" MB":l(t/1073741824,n,e)+" GB":"NaN"}}]),t.module("a8m.math.degrees",["a8m.math"]).filter("degrees",["$math",function(e){return function(t,n){if(R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)){var r=180*t/e.PI;return e.round(r*e.pow(10,n))/e.pow(10,n)}return"NaN"}}]),t.module("a8m.math.kbFmt",["a8m.math"]).filter("kbFmt",["$math",function(e){return function(t,n){return R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)?1024>t?l(t,n,e)+" KB":1048576>t?l(t/1024,n,e)+" MB":l(t/1048576,n,e)+" GB":"NaN"}}]),t.module("a8m.math",[]).factory("$math",["$window",function(e){return e.Math}]),t.module("a8m.math.max",["a8m.math"]).filter("max",["$math","$parse",function(e,t){function n(n,r){var a=n.map(function(e){return t(r)(e)});return a.indexOf(e.max.apply(e,a))}return function(t,r){return F(t)?E(r)?e.max.apply(e,t):t[n(t,r)]:t}}]),t.module("a8m.math.min",["a8m.math"]).filter("min",["$math","$parse",function(e,t){function n(n,r){var a=n.map(function(e){return t(r)(e)});return a.indexOf(e.min.apply(e,a))}return function(t,r){return F(t)?E(r)?e.min.apply(e,t):t[n(t,r)]:t}}]),t.module("a8m.math.percent",["a8m.math"]).filter("percent",["$math","$window",function(e,t){return function(n,r,a){var o=C(n)?t.Number(n):n;return r=r||100,a=a||!1,!R(o)||t.isNaN(o)?n:a?e.round(o/r*100):o/r*100}}]),t.module("a8m.math.radians",["a8m.math"]).filter("radians",["$math",function(e){return function(t,n){if(R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)){var r=3.14159265359*t/180;return e.round(r*e.pow(10,n))/e.pow(10,n)}return"NaN"}}]),t.module("a8m.math.radix",[]).filter("radix",function(){return function(e,t){var n=/^[2-9]$|^[1-2]\d$|^3[0-6]$/;return R(e)&&n.test(t)?e.toString(t).toUpperCase():e}}),t.module("a8m.math.shortFmt",["a8m.math"]).filter("shortFmt",["$math",function(e){return function(t,n){return R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)?1e3>t?t:1e6>t?l(t/1e3,n,e)+" K":1e9>t?l(t/1e6,n,e)+" M":l(t/1e9,n,e)+" B":"NaN"}}]),t.module("a8m.math.sum",[]).filter("sum",function(){return function(e,t){return F(e)?e.reduce(function(e,t){return e+t},t||0):e}}),t.module("a8m.ends-with",[]).filter("endsWith",function(){return function(e,t,n){var r,a=n||!1;return!C(e)||E(t)?e:(e=a?e:e.toLowerCase(),r=e.length-t.length,-1!==e.indexOf(a?t:t.toLowerCase(),r))}}),t.module("a8m.latinize",[]).filter("latinize",[function(){function e(e){return e.replace(/[^\u0000-\u007E]/g,function(e){return n[e]||e})}for(var t=[{base:"A",letters:"AⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ"},{base:"AA",letters:"Ꜳ"},{base:"AE",letters:"ÆǼǢ"},{base:"AO",letters:"Ꜵ"},{base:"AU",letters:"Ꜷ"},{base:"AV",letters:"ꜸꜺ"},{base:"AY",letters:"Ꜽ"},{base:"B",letters:"BⒷBḂḄḆɃƂƁ"},{base:"C",letters:"CⒸCĆĈĊČÇḈƇȻꜾ"},{base:"D",letters:"DⒹDḊĎḌḐḒḎĐƋƊƉꝹ"},{base:"DZ",letters:"DZDŽ"},{base:"Dz",letters:"DzDž"},{base:"E",letters:"EⒺEÈÉÊỀẾỄỂẼĒḔḖĔĖËẺĚȄȆẸỆȨḜĘḘḚƐƎ"},{base:"F",letters:"FⒻFḞƑꝻ"},{base:"G",letters:"GⒼGǴĜḠĞĠǦĢǤƓꞠꝽꝾ"},{base:"H",letters:"HⒽHĤḢḦȞḤḨḪĦⱧⱵꞍ"},{base:"I",letters:"IⒾIÌÍÎĨĪĬİÏḮỈǏȈȊỊĮḬƗ"},{base:"J",letters:"JⒿJĴɈ"},{base:"K",letters:"KⓀKḰǨḲĶḴƘⱩꝀꝂꝄꞢ"},{base:"L",letters:"LⓁLĿĹĽḶḸĻḼḺŁȽⱢⱠꝈꝆꞀ"},{base:"LJ",letters:"LJ"},{base:"Lj",letters:"Lj"},{base:"M",letters:"MⓂMḾṀṂⱮƜ"},{base:"N",letters:"NⓃNǸŃÑṄŇṆŅṊṈȠƝꞐꞤ"},{base:"NJ",letters:"NJ"},{base:"Nj",letters:"Nj"},{base:"O",letters:"OⓄOÒÓÔỒỐỖỔÕṌȬṎŌṐṒŎȮȰÖȪỎŐǑȌȎƠỜỚỠỞỢỌỘǪǬØǾƆƟꝊꝌ"},{base:"OI",letters:"Ƣ"},{base:"OO",letters:"Ꝏ"},{base:"OU",letters:"Ȣ"},{base:"OE",letters:"ŒŒ"},{base:"oe",letters:"œœ"},{base:"P",letters:"PⓅPṔṖƤⱣꝐꝒꝔ"},{base:"Q",letters:"QⓆQꝖꝘɊ"},{base:"R",letters:"RⓇRŔṘŘȐȒṚṜŖṞɌⱤꝚꞦꞂ"},{base:"S",letters:"SⓈSẞŚṤŜṠŠṦṢṨȘŞⱾꞨꞄ"},{base:"T",letters:"TⓉTṪŤṬȚŢṰṮŦƬƮȾꞆ"},{base:"TZ",letters:"Ꜩ"},{base:"U",letters:"UⓊUÙÚÛŨṸŪṺŬÜǛǗǕǙỦŮŰǓȔȖƯỪỨỮỬỰỤṲŲṶṴɄ"},{base:"V",letters:"VⓋVṼṾƲꝞɅ"},{base:"VY",letters:"Ꝡ"},{base:"W",letters:"WⓌWẀẂŴẆẄẈⱲ"},{base:"X",letters:"XⓍXẊẌ"},{base:"Y",letters:"YⓎYỲÝŶỸȲẎŸỶỴƳɎỾ"},{base:"Z",letters:"ZⓏZŹẐŻŽẒẔƵȤⱿⱫꝢ"},{base:"a",letters:"aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐ"},{base:"aa",letters:"ꜳ"},{base:"ae",letters:"æǽǣ"},{base:"ao",letters:"ꜵ"},{base:"au",letters:"ꜷ"},{base:"av",letters:"ꜹꜻ"},{base:"ay",letters:"ꜽ"},{base:"b",letters:"bⓑbḃḅḇƀƃɓ"},{base:"c",letters:"cⓒcćĉċčçḉƈȼꜿↄ"},{base:"d",letters:"dⓓdḋďḍḑḓḏđƌɖɗꝺ"},{base:"dz",letters:"dzdž"},{base:"e",letters:"eⓔeèéêềếễểẽēḕḗĕėëẻěȅȇẹệȩḝęḙḛɇɛǝ"},{base:"f",letters:"fⓕfḟƒꝼ"},{base:"g",letters:"gⓖgǵĝḡğġǧģǥɠꞡᵹꝿ"},{base:"h",letters:"hⓗhĥḣḧȟḥḩḫẖħⱨⱶɥ"},{base:"hv",letters:"ƕ"},{base:"i",letters:"iⓘiìíîĩīĭïḯỉǐȉȋịįḭɨı"},{base:"j",letters:"jⓙjĵǰɉ"},{base:"k",letters:"kⓚkḱǩḳķḵƙⱪꝁꝃꝅꞣ"},{base:"l",letters:"lⓛlŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇ"},{base:"lj",letters:"lj"},{base:"m",letters:"mⓜmḿṁṃɱɯ"},{base:"n",letters:"nⓝnǹńñṅňṇņṋṉƞɲʼnꞑꞥ"},{base:"nj",letters:"nj"},{base:"o",letters:"oⓞoòóôồốỗổõṍȭṏōṑṓŏȯȱöȫỏőǒȍȏơờớỡởợọộǫǭøǿɔꝋꝍɵ"},{base:"oi",letters:"ƣ"},{base:"ou",letters:"ȣ"},{base:"oo",letters:"ꝏ"},{base:"p",letters:"pⓟpṕṗƥᵽꝑꝓꝕ"},{base:"q",letters:"qⓠqɋꝗꝙ"},{base:"r",letters:"rⓡrŕṙřȑȓṛṝŗṟɍɽꝛꞧꞃ"},{base:"s",letters:"sⓢsßśṥŝṡšṧṣṩșşȿꞩꞅẛ"},{base:"t",letters:"tⓣtṫẗťṭțţṱṯŧƭʈⱦꞇ"},{base:"tz",letters:"ꜩ"},{base:"u",letters:"uⓤuùúûũṹūṻŭüǜǘǖǚủůűǔȕȗưừứữửựụṳųṷṵʉ"},{base:"v",letters:"vⓥvṽṿʋꝟʌ"},{base:"vy",letters:"ꝡ"},{base:"w",letters:"wⓦwẁẃŵẇẅẘẉⱳ"},{base:"x",letters:"xⓧxẋẍ"},{base:"y",letters:"yⓨyỳýŷỹȳẏÿỷẙỵƴɏỿ"},{base:"z",letters:"zⓩzźẑżžẓẕƶȥɀⱬꝣ"}],n={},r=0;r<]*>/g,""):e}}),t.module("a8m.test",[]).filter("test",function(){return function(e,t,n){var r=new RegExp(t,n);return C(e)?r.test(e):e}}),t.module("a8m.trim",[]).filter("trim",function(){return function(e,t){var n=t||"\\s";return C(e)?e.replace(new RegExp("^"+n+"+|"+n+"+$","g"),""):e}}),t.module("a8m.truncate",[]).filter("truncate",function(){return function(e,t,n,r){return t=E(t)?e.length:t,r=r||!1,n=n||"",!C(e)||e.length<=t?e:e.substring(0,r?-1===e.indexOf(" ",t)?e.length:e.indexOf(" ",t):t)+n}}),t.module("a8m.ucfirst",[]).filter("ucfirst",[function(){return function(e){return C(e)?e.split(" ").map(function(e){return e.charAt(0).toUpperCase()+e.substring(1)}).join(" "):e}}]),t.module("a8m.uri-component-encode",[]).filter("uriComponentEncode",["$window",function(e){return function(t){return C(t)?e.encodeURIComponent(t):t}}]),t.module("a8m.uri-encode",[]).filter("uriEncode",["$window",function(e){return function(t){return C(t)?e.encodeURI(t):t}}]),t.module("a8m.wrap",[]).filter("wrap",function(){return function(e,t,n){return C(e)&&D(t)?[t,e,n||t].join(""):e}}),t.module("a8m.filter-watcher",[]).provider("filterWatcher",function(){this.$get=["$window","$rootScope",function(e,n){function r(e,n){return[e,t.toJson(n)].join("#").replace(/"/g,"")}function a(e){var t=e.targetScope.$id;x(d[t],function(e){delete u[e]}),delete d[t]}function o(){f(function(){n.$$phase||(u={})})}function i(e,t){var n=e.$id;return E(d[n])&&(e.$on("$destroy",a),d[n]=[]),d[n].push(t)}function s(e,t){var n=r(e,t);return u[n]}function l(e,t,n,a){var s=r(e,t);return u[s]=a,c(n)?i(n,s):o(),a}var u={},d={},f=e.setTimeout;return{isMemoized:s,memoize:l}}]}),t.module("angular.filter",["a8m.ucfirst","a8m.uri-encode","a8m.uri-component-encode","a8m.slugify","a8m.latinize","a8m.strip-tags","a8m.stringular","a8m.truncate","a8m.starts-with","a8m.ends-with","a8m.wrap","a8m.trim","a8m.ltrim","a8m.rtrim","a8m.repeat","a8m.test","a8m.match","a8m.to-array","a8m.concat","a8m.contains","a8m.unique","a8m.is-empty","a8m.after","a8m.after-where","a8m.before","a8m.before-where","a8m.defaults","a8m.where","a8m.reverse","a8m.remove","a8m.remove-with","a8m.group-by","a8m.count-by","a8m.search-field","a8m.fuzzy-by","a8m.fuzzy","a8m.omit","a8m.pick","a8m.every","a8m.filter-by","a8m.xor","a8m.map","a8m.first","a8m.last","a8m.flatten","a8m.join","a8m.math","a8m.math.max","a8m.math.min","a8m.math.percent","a8m.math.radix","a8m.math.sum","a8m.math.degrees","a8m.math.radians","a8m.math.byteFmt","a8m.math.kbFmt","a8m.math.shortFmt","a8m.angular","a8m.conditions","a8m.is-null","a8m.filter-watcher"])}(window,window.angular),define("job-roles/modules/job-roles.core",["common/angular","common/ui-select","common/directives/angular-date/date-input","common/modules/directives","common/modules/routers/compu-ng-route","common/filters/angular-date/format-date","common/services/angular-date/date-format","common/services/crm-ang.service","common/services/dom-event-trigger","common/services/pub-sub","job-roles/vendor/angular-editable","job-roles/vendor/angular-filter"],function(e){"use strict";e.module("hrjobroles.core",["angular.filter","ngAnimate","ngSanitize","ngResource","ui.bootstrap","ui.select","xeditable","common.angularDate","common.directives","common.services","compuNgRoute"])}),define("job-roles/filters/get-active-values.filter",["common/lodash"],function(e){"use strict";function t(t){return t.debug("Filter: getActiveValues"),function(t){var n={};return e.each(t,function(e,t){"1"===e.is_active&&(n[t]=e)}),n}}return t.__name="getActiveValues",t.$inject=["$log"],t}),define("job-roles/modules/job-roles.filters",["common/angular","job-roles/filters/get-active-values.filter"],function(e,t){"use strict";return e.module("hrjobroles.filters",[]).filter(t.__name,t)}),define("job-roles/modules/job-roles.run",["common/angular"],function(e){"use strict";function t(e,t,n,r){n.theme="bs3",t.contactId=r.contactId,t.pathBaseUrl=r.pathBaseUrl,t.pathTpl=r.pathTpl,t.pathIncludeTpl=r.pathIncludeTpl,t.prefix=r.classNamePrefix}e.module("hrjobroles.run",["hrjobroles.constants"]).run(t),t.$inject=["$q","$rootScope","editableOptions","settings"]}),define("job-roles/services/date-validation.service",["common/moment"],function(e){function t(t){function n(e,t){e.isValid()||l("Date is not valid!!",t)}function r(e,t){e.isSameOrAfter(t)&&l("Start Date cannot be the same as or after the End Date.",["start_date","end_date"])}function a(e,t){e.isBefore(t)&&l("Start Date cannot be lower than Contract Start Date.",["start_date"])}function o(e,t){e.isAfter(t)&&l("Start Date cannot be higher than Contract End Date.",["start_date"])}function i(e,t){e.isAfter(t)&&l("End Date cannot be higher than Contract End Date.",["end_date"])}function s(t,n){return t instanceof Date&&(t=e(t).valueOf()),e(t,n,!0).startOf("day")}var l=function(e,t){throw new Error(e,t[0])},u={dateFormats:["x","YYYY-MM-DD"],setErrorCallback:function(e){if("function"!=typeof e)throw new TypeError("Error callback must be a function.");l=e},validate:function(e,t,l,u){e=s(e,this.dateFormats),l=s(l,this.dateFormats),u=s(u,this.dateFormats),n(e,["start_date"]),o(e,u),a(e,l),(0===t||t)&&(t=s(t,this.dateFormats),n(t,["end_date"]),i(t,u),r(e,t))}};return t.DATE_FORMAT&&u.dateFormats.push(t.DATE_FORMAT.toUpperCase()),u}return t.__name="dateValidation",t.$inject=["HR_settings"],t}),define("job-roles/services/filters.service",[],function(){"use strict";function e(){return{isNotUndefined:function(e){try{return e.constructor===Array?e.filter(function(e){return"undefined"!==e&&void 0!==e}):e}catch(t){return e}},issetCostCentre:function(e){try{return e.constructor===Array?e.filter(function(e){return""!==e.cost_centre_id&&("1"===e.type&&parseInt(e.percentage)>0||"0"===e.type&&parseInt(e.amount)>0)}):e}catch(t){return e}},issetFunder:function(e){try{return e.constructor===Array?e.filter(function(e){return""!==e.funder_id&&("1"===e.type&&parseInt(e.percentage)>0||"0"===e.type&&parseInt(e.amount)>0)}):e}catch(t){return e}}}}return e.__name="filtersService",e}),define("job-roles/services/job-role.service",["common/lodash"],function(e){"use strict";function t(t,n,r){function a(n){var r=n["api.HRJobContractRevision.get"].values;delete n["api.HRJobContractRevision.get"],n.revisions=e.compact(r.map(function(e){var r=e["api.HRJobDetails.getsingle"];return r.period_start_date===n.period_start_date&&r.period_end_date===n.period_end_date?null:(r.period_start_date=t("formatDate")(r.period_start_date),r.period_end_date=t("formatDate")(r.period_end_date),r)}))}return{getContracts:function(e){var t=r.defer();return CRM.api3("HRJobContract","get",{sequential:1,contact_id:e,deleted:0,return:"title,period_end_date,period_start_date","api.HRJobContractRevision.get":{jobcontract_id:"$value.id","api.HRJobDetails.getsingle":{jobcontract_revision_id:"$value.id"}}}).done(function(e){e.values.forEach(a),t.resolve(e)}).error(function(){t.reject("An error occured while fetching items")}),t.promise},getAllJobRoles:function(e){var t=r.defer();return CRM.api3("HrJobRoles","get",{sequential:1,return:"id,job_contract_id,title,description,status,funder,funder_val_type,percent_pay_funder,amount_pay_funder,cost_center,cost_center_val_type,percent_pay_cost_center,amount_pay_cost_center,level_type,location,region,department,end_date,start_date",job_contract_id:{IN:e}}).done(function(e){t.resolve(e)}).error(function(e){t.reject("An error occured while fetching items")}),t.promise},deleteJobRole:function(e){var t=r.defer();return CRM.api3("HrJobRoles","delete",{sequential:1,id:e}).done(function(e){t.resolve(e)}).error(function(e){t.reject("An error occured while deleting items")}),t.promise},createJobRole:function(e){var t="|",n="|",a="|",o="|",i="|",s="|",l="|",u="|";if(void 0!==e.funders)for(var c=0,d=e.funders.length;c
    - - + +
    @@ -125,11 +122,8 @@ - - + + @@ -150,11 +144,8 @@ - - + + @@ -175,11 +166,8 @@ - - + + diff --git a/com.civicrm.hrjobroles/views/include/job_role_panel.html b/com.civicrm.hrjobroles/views/include/job_role_panel.html index 51ee14cee44..8e8f582f2c3 100755 --- a/com.civicrm.hrjobroles/views/include/job_role_panel.html +++ b/com.civicrm.hrjobroles/views/include/job_role_panel.html @@ -172,11 +172,8 @@ - - + + @@ -205,11 +202,8 @@ - - + + @@ -238,11 +232,8 @@ - - + + @@ -271,11 +262,8 @@ - - + + From 6ef41b69576f1bf1a9f115434a51e77e457a461f Mon Sep 17 00:00:00 2001 From: Tunbola Ogunwande Date: Tue, 17 Apr 2018 16:27:26 +0100 Subject: [PATCH 143/203] FAR-247: Log expired balance changes data. Add tests. --- .../BAO/LeaveBalanceChange.php | 28 +++++- .../BAO/LeaveBalanceChangeTest.php | 96 +++++++++++++++++++ 2 files changed, 123 insertions(+), 1 deletion(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChange.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChange.php index fee1f0f7d8a..91195552913 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChange.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChange.php @@ -8,6 +8,7 @@ use CRM_Hrjobcontract_BAO_HRJobContractRevision as HRJobContractRevision; use CRM_Hrjobcontract_BAO_HRJobDetails as HRJobDetails; use CRM_HRLeaveAndAbsences_Service_LeaveDateAmountDeduction as LeaveDateAmountDeduction; +use CRM_HRLeaveAndAbsences_BAO_LeaveBalanceChangeExpiryLog as LeaveBalanceChangeExpiryLog; class CRM_HRLeaveAndAbsences_BAO_LeaveBalanceChange extends CRM_HRLeaveAndAbsences_DAO_LeaveBalanceChange { @@ -1029,7 +1030,8 @@ private static function calculateExpiryAmount($balanceChanges, $datesOverlapping $params['id'] = $expiryBalanceChange->id; } - self::create($params); + $balanceChange = self::create($params); + self::logExpiredBalanceChange($balanceChange); $numberOfRecords++; } @@ -1037,6 +1039,30 @@ private static function calculateExpiryAmount($balanceChanges, $datesOverlapping return $numberOfRecords; } + /** + * Logs the expired balance change using the LeaveBalanceChangeExpiryLog entity. + * + * @param \CRM_HRLeaveAndAbsences_BAO_LeaveBalanceChange $expiredBalanceChange + */ + private static function logExpiredBalanceChange($expiredBalanceChange) { + $logData = [ + 'balance_change_id' => $expiredBalanceChange->id, + 'source_id' => $expiredBalanceChange->source_id, + 'source_type' => $expiredBalanceChange->source_type, + 'expiry_date' => CRM_Utils_Date::processDate($expiredBalanceChange->expiry_date), + 'balance_type_id' => $expiredBalanceChange->type_id, + 'amount' => $expiredBalanceChange->amount, + ]; + + if ($expiredBalanceChange->source_type == self::SOURCE_LEAVE_REQUEST_DAY) { + $leaveDate = LeaveRequestDate::findById($expiredBalanceChange->source_id); + $logData['leave_date'] = CRM_Utils_Date::processDate($leaveDate->date); + $logData['leave_request_id'] = $leaveDate->leave_request_id; + } + + LeaveBalanceChangeExpiryLog::create($logData); + } + /** * Returns the current balance (i.e. not including balance changes caused by * open leave requests) for the given Contacts during the given Absence Period. diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeTest.php b/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeTest.php index 3ab41e63fa6..1c226252d5c 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeTest.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeTest.php @@ -12,6 +12,7 @@ use CRM_HRLeaveAndAbsences_Test_Fabricator_LeavePeriodEntitlement as LeavePeriodEntitlementFabricator; use CRM_Hrjobcontract_Test_Fabricator_HRJobContract as HRJobContractFabricator; use CRM_HRLeaveAndAbsences_Factory_LeaveDateAmountDeduction as LeaveDateAmountDeductionFactory; +use CRM_HRLeaveAndAbsences_BAO_LeaveBalanceChangeExpiryLog as LeaveBalanceChangeExpiryLog; /** * Class CRM_HRLeaveAndAbsences_BAO_LeaveBalanceChangeTest @@ -3559,6 +3560,101 @@ public function testCalculateAmountForDateReturnsZeroWhenContactWorkDayIsNull() $this->assertEquals(0, $amount); } + public function testCreateExpiryRecordsLogsExpiredBalanceChanges() { + $absencePeriod = AbsencePeriodFabricator::fabricate([ + 'start_date' => CRM_Utils_Date::processDate('2017-01-01'), + 'end_date' => CRM_Utils_Date::processDate('2017-12-31') + ]); + + $periodEntitlement = LeavePeriodEntitlementFabricator::fabricate([ + 'contact_id' => 1, + 'period_id' => $absencePeriod->id, + 'type_id' => 1, + ]); + + $broughtForwardAmount = 5; + $broughtForwardExpiryDate = new DateTime('2017-04-01'); + $broughtForwardBalance = $this->createBroughtForwardBalanceChange( + $periodEntitlement->id, + $broughtForwardAmount, + $broughtForwardExpiryDate->format('YmdHis') + ); + + $toilLeaveDate = new DateTime('2017-05-17'); + $toilExpiryDate = new DateTime('2017-08-01'); + $toilRequest = LeaveRequestFabricator::fabricateWithoutValidation([ + 'contact_id' => $periodEntitlement->contact_id, + 'type_id' => $periodEntitlement->type_id, + 'from_date' => $toilLeaveDate->format('YmdHis'), + 'to_date' => $toilLeaveDate->format('YmdHis'), + 'toil_expiry_date' => $toilExpiryDate->format('YmdHis'), + 'toil_to_accrue' => 1, + 'toil_duration' => 100, + 'request_type' => LeaveRequest::REQUEST_TYPE_TOIL + ], true); + + LeaveBalanceChange::createExpiryRecords(); + + $balanceExpiryLogs = $this->getBalanceChangeExpiryLogRecords(); + $this->assertCount(2, $balanceExpiryLogs); + + //Get the expiry balance record for the TOIL balance change + $toilBalanceChange = $this->findToilRequestMainBalanceChange($toilRequest->id); + $toilExpiryRecord = $this->getExpiryRecordForBalanceChange($toilBalanceChange->id); + $toilDate = $toilRequest->getDates()[0]; + + //Get expiry balance record for the brought forward balance change + $broughtForwardExpiryRecord = $this->getExpiryRecordForBalanceChange($broughtForwardBalance->id); + + $expectedToilLog = [ + 'id' => $balanceExpiryLogs[$toilExpiryRecord->id]['id'], + 'balance_change_id' => $toilExpiryRecord->id, + 'amount' => -1 * $toilRequest->toil_to_accrue, + 'source_id' => $toilDate->id, + 'source_type' => LeaveBalanceChange::SOURCE_LEAVE_REQUEST_DAY, + 'expiry_date' => $toilExpiryDate->format('Y-m-d'), + 'balance_type_id' => $toilExpiryRecord->type_id, + 'leave_date' => $toilLeaveDate->format('Y-m-d'), + 'leave_request_id' => $toilRequest->id + ]; + + $expectedBroughtForwardLog = [ + 'id' => $balanceExpiryLogs[$broughtForwardExpiryRecord->id]['id'], + 'balance_change_id' => $broughtForwardExpiryRecord->id, + 'amount' => -1 * $broughtForwardAmount, + 'source_id' => $periodEntitlement->id, + 'source_type' => LeaveBalanceChange::SOURCE_ENTITLEMENT, + 'expiry_date' => $broughtForwardExpiryDate->format('Y-m-d'), + 'balance_type_id' => $broughtForwardExpiryRecord->type_id, + 'leave_date' => NULL, + 'leave_request_id' => NULL + ]; + + $dateNow = new DateTime(); + $this->assertEquals($dateNow, new DateTime($balanceExpiryLogs[$toilExpiryRecord->id]['created_date']), 10); + $this->assertEquals($dateNow, new DateTime($balanceExpiryLogs[$broughtForwardExpiryRecord->id]['created_date']), 10); + + //we need to remove the created dates from the array as its not possible to assert the exact value. + unset($balanceExpiryLogs[$toilExpiryRecord->id]['created_date']); + unset($balanceExpiryLogs[$broughtForwardExpiryRecord->id]['created_date']); + + $this->assertEquals($expectedToilLog, $balanceExpiryLogs[$toilExpiryRecord->id]); + $this->assertEquals($expectedBroughtForwardLog, $balanceExpiryLogs[$broughtForwardExpiryRecord->id]); + } + + private function getBalanceChangeExpiryLogRecords() { + $leaveExpiryLog = new LeaveBalanceChangeExpiryLog(); + $leaveExpiryLog->find(); + + $records = []; + while($leaveExpiryLog->fetch()) { + $records[$leaveExpiryLog->balance_change_id] = $leaveExpiryLog->toArray() ; + } + + return $records; + } + + private function getBalanceChangesForPeriodEntitlement($leavePeriodEntitlement) { $record = new LeaveBalanceChange(); $record->source_id = $leavePeriodEntitlement->id; From 820bd327171da07b9fcfbb63e453500349fe88c8 Mon Sep 17 00:00:00 2001 From: Tunbola Ogunwande Date: Tue, 17 Apr 2018 16:27:57 +0100 Subject: [PATCH 144/203] FAR-247: Add upgrader to fix wrongly expired balance changes. --- .../CRM/HRLeaveAndAbsences/Upgrader.php | 1 + .../HRLeaveAndAbsences/Upgrader/Step/1023.php | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1023.php diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php index bc583e58322..8cb6897b1eb 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader.php @@ -28,6 +28,7 @@ class CRM_HRLeaveAndAbsences_Upgrader extends CRM_HRLeaveAndAbsences_Upgrader_Ba use CRM_HRLeaveAndAbsences_Upgrader_Step_1020; use CRM_HRLeaveAndAbsences_Upgrader_Step_1021; use CRM_HRLeaveAndAbsences_Upgrader_Step_1022; + use CRM_HRLeaveAndAbsences_Upgrader_Step_1023; /** * A list of directories to be scanned for XML installation files diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1023.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1023.php new file mode 100644 index 00000000000..2a36717e973 --- /dev/null +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/Upgrader/Step/1023.php @@ -0,0 +1,24 @@ + '$today'"); + + return TRUE; + } +} From 81d97c204a4e6f84ec836f07b055f481a88b6360 Mon Sep 17 00:00:00 2001 From: Tunbola Ogunwande Date: Tue, 17 Apr 2018 17:39:49 +0100 Subject: [PATCH 145/203] FAR-247: Use server time rather than Db time to get records to expire. --- .../CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChange.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChange.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChange.php index 91195552913..93b96733ef1 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChange.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChange.php @@ -753,7 +753,7 @@ private static function getBalanceChangesToExpire() { LEFT JOIN {$absencePeriodTable} absence_period ON period_entitlement.period_id = absence_period.id WHERE balance_to_expire.expiry_date IS NOT NULL AND - balance_to_expire.expiry_date < CURDATE() AND + balance_to_expire.expiry_date < %3 AND balance_to_expire.expired_balance_change_id IS NULL AND expired_balance_change.id IS NULL ORDER BY balance_to_expire.expiry_date ASC, balance_to_expire.id ASC @@ -762,6 +762,7 @@ private static function getBalanceChangesToExpire() { $params = [ 1 => [self::SOURCE_LEAVE_REQUEST_DAY, 'String'], 2 => [self::SOURCE_ENTITLEMENT, 'String'], + 3 => [date('Y-m-d'), 'String'] ]; $result = CRM_Core_DAO::executeQuery($query, $params); From 8bbaaff2a131d0511c8bd4203b161eee8a36115e Mon Sep 17 00:00:00 2001 From: Tunbola Ogunwande Date: Wed, 18 Apr 2018 14:46:10 +0100 Subject: [PATCH 146/203] FAR-252: Modify SQL query fetching balance changes to expire not to fetch those linked to deleted TOIL requests --- .../BAO/LeaveBalanceChange.php | 3 +- .../BAO/LeaveBalanceChangeTest.php | 47 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChange.php b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChange.php index 93b96733ef1..5a67592f88d 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChange.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChange.php @@ -755,7 +755,8 @@ private static function getBalanceChangesToExpire() { WHERE balance_to_expire.expiry_date IS NOT NULL AND balance_to_expire.expiry_date < %3 AND balance_to_expire.expired_balance_change_id IS NULL AND - expired_balance_change.id IS NULL + expired_balance_change.id IS NULL AND + coalesce(leave_request.type_id, period_entitlement.type_id) IS NOT NULL ORDER BY balance_to_expire.expiry_date ASC, balance_to_expire.id ASC "; diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeTest.php b/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeTest.php index 1c226252d5c..5000ab9804a 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeTest.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeTest.php @@ -3642,6 +3642,53 @@ public function testCreateExpiryRecordsLogsExpiredBalanceChanges() { $this->assertEquals($expectedBroughtForwardLog, $balanceExpiryLogs[$broughtForwardExpiryRecord->id]); } + public function testCreateExpiryRecordsDoesTryToExpireBalanceChangesLinkedToSoftDeletedToilRequest() { + $absencePeriod = AbsencePeriodFabricator::fabricate([ + 'start_date' => CRM_Utils_Date::processDate('2017-01-01'), + 'end_date' => CRM_Utils_Date::processDate('2017-12-31') + ]); + + $periodEntitlement = LeavePeriodEntitlementFabricator::fabricate([ + 'contact_id' => 1, + 'period_id' => $absencePeriod->id, + 'type_id' => 1, + ]); + + $toilRequest = LeaveRequestFabricator::fabricateWithoutValidation([ + 'contact_id' => $periodEntitlement->contact_id, + 'type_id' => $periodEntitlement->type_id, + 'from_date' => CRM_Utils_Date::processDate('2017-05-17'), + 'to_date' => CRM_Utils_Date::processDate('2017-05-17'), + 'toil_expiry_date' => CRM_Utils_Date::processDate('2017-08-01'), + 'toil_to_accrue' => 1, + 'toil_duration' => 100, + 'request_type' => LeaveRequest::REQUEST_TYPE_TOIL + ], true); + + $toilRequest2 = LeaveRequestFabricator::fabricateWithoutValidation([ + 'contact_id' => $periodEntitlement->contact_id, + 'type_id' => $periodEntitlement->type_id, + 'from_date' => CRM_Utils_Date::processDate('2017-08-09'), + 'to_date' => CRM_Utils_Date::processDate('2017-08-09'), + 'toil_expiry_date' => CRM_Utils_Date::processDate('2017-11-01'), + 'toil_to_accrue' => 1, + 'toil_duration' => 100, + 'request_type' => LeaveRequest::REQUEST_TYPE_TOIL + ], true); + + //Delete the first TOIL request + LeaveRequest::softDelete($toilRequest->id); + + LeaveBalanceChange::createExpiryRecords(); + $toilBalanceChange = $this->findToilRequestMainBalanceChange($toilRequest2->id); + $toilExpiryRecord = $this->getExpiryRecordForBalanceChange($toilBalanceChange->id); + + //only the expiry record second TOIL request will be created since the first is deleted. + $balanceExpiryLogs = $this->getBalanceChangeExpiryLogRecords(); + $this->assertCount(1, $balanceExpiryLogs); + $this->assertNotNull($balanceExpiryLogs[$toilExpiryRecord->id]); + } + private function getBalanceChangeExpiryLogRecords() { $leaveExpiryLog = new LeaveBalanceChangeExpiryLog(); $leaveExpiryLog->find(); From 60a6eb874bbda14706e3c815ba737981f1d3d296 Mon Sep 17 00:00:00 2001 From: Tunbola Ogunwande Date: Wed, 18 Apr 2018 16:37:16 +0100 Subject: [PATCH 147/203] FAR-252: PR feedback --- .../CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeTest.php b/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeTest.php index 5000ab9804a..d70e36d6764 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeTest.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveBalanceChangeTest.php @@ -3642,7 +3642,7 @@ public function testCreateExpiryRecordsLogsExpiredBalanceChanges() { $this->assertEquals($expectedBroughtForwardLog, $balanceExpiryLogs[$broughtForwardExpiryRecord->id]); } - public function testCreateExpiryRecordsDoesTryToExpireBalanceChangesLinkedToSoftDeletedToilRequest() { + public function testCreateExpiryRecordsDoesNotExpireBalanceChangesLinkedToSoftDeletedToilRequest() { $absencePeriod = AbsencePeriodFabricator::fabricate([ 'start_date' => CRM_Utils_Date::processDate('2017-01-01'), 'end_date' => CRM_Utils_Date::processDate('2017-12-31') @@ -3663,7 +3663,7 @@ public function testCreateExpiryRecordsDoesTryToExpireBalanceChangesLinkedToSoft 'toil_to_accrue' => 1, 'toil_duration' => 100, 'request_type' => LeaveRequest::REQUEST_TYPE_TOIL - ], true); + ], TRUE); $toilRequest2 = LeaveRequestFabricator::fabricateWithoutValidation([ 'contact_id' => $periodEntitlement->contact_id, @@ -3674,7 +3674,7 @@ public function testCreateExpiryRecordsDoesTryToExpireBalanceChangesLinkedToSoft 'toil_to_accrue' => 1, 'toil_duration' => 100, 'request_type' => LeaveRequest::REQUEST_TYPE_TOIL - ], true); + ], TRUE); //Delete the first TOIL request LeaveRequest::softDelete($toilRequest->id); From ebda75b982db5edb01d41071ef29af05deb09ea9 Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Wed, 18 Apr 2018 15:15:19 +0100 Subject: [PATCH 148/203] PCHR-3460: PR Feedback --- .../js/dist/job-roles.min.js | 4 +- .../controllers/job-roles.controller.js | 121 +++-------- .../controllers/job-roles.controller.spec.js | 190 +++++++----------- .../js/test/mocks/data/job-role.data.js | 100 +++++++++ .../views/include/add_new_role.html | 8 +- .../views/include/job_role_panel.html | 8 +- 6 files changed, 214 insertions(+), 217 deletions(-) diff --git a/com.civicrm.hrjobroles/js/dist/job-roles.min.js b/com.civicrm.hrjobroles/js/dist/job-roles.min.js index 31cc6fd9d6a..6f010dec8c6 100644 --- a/com.civicrm.hrjobroles/js/dist/job-roles.min.js +++ b/com.civicrm.hrjobroles/js/dist/job-roles.min.js @@ -12,6 +12,6 @@ Build date: 2014-01-10 */ -define("job-roles/modules/job-roles.config",["common/angular"],function(e){"use strict";function t(e,t,n,r,a){t.debugEnabled(a.debug),r.resolveForAll({format:["DateFormat",function(e){return e.getDateFormat()}]}).when("/",{templateUrl:a.pathBaseUrl+a.pathTpl+"mainTemplate.html?v=1",resolve:{},controller:"JobRolesController",controllerAs:"jobroles"}).otherwise({redirectTo:"/"}),n.defaults.stripTrailingSlashes=!1,e.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}e.module("hrjobroles.config",["hrjobroles.constants"]).config(t),t.$inject=["$httpProvider","$logProvider","$resourceProvider","$routeProvider","settings"]}),define("job-roles/modules/job-roles.constants",["common/angular"],function(e){"use strict";e.module("hrjobroles.constants",[]).constant("settings",{classNamePrefix:"hrjobroles-",contactId:decodeURIComponent((new RegExp("[?|&]cid=([^&;]+?)(&|#|;|$)").exec(location.search)||[null,""])[1].replace(/\+/g,"%20"))||null,debug:!0,pathApp:CRM.vars.hrjobroles.path,pathRest:CRM.url("civicrm/ajax/rest"),pathBaseUrl:CRM.vars.hrjobroles.baseURL+"/",pathTpl:"views/",pathIncludeTpl:"views/include/"})}),define("job-roles/controllers/job-roles.controller",["common/angular","common/lodash","common/moment"],function(e,t,n){"use strict";function r(r,a,o,i,s,l,u,c,d,f,m,p,b,h,v,g,_){function $(e,t){void 0===Ce.editData[e]&&(Ce.editData[e]={}),"cost_centre"===t?(void 0!==Ce.editData[e].cost_centers&&Ce.editData[e].cost_centers instanceof Array||(Ce.editData[e].cost_centers=[]),Ce.editData[e].cost_centers.push({id:Ce.editData[e].cost_centers.length+1,cost_centre_id:"",type:"1",percentage:"0",amount:"0"})):(void 0!==Ce.editData[e].funders&&Ce.editData[e].funders instanceof Array||(Ce.editData[e].funders=[]),Ce.editData[e].funders.push({id:Ce.editData[e].funders.length+1,funder_id:"",type:"1",percentage:"0",amount:"0"}))}function w(){Ce.add_new=!0}function y(){Ce.add_new=!1,delete Ce.editData.new_role_id}function D(e,t){Ce.viewTab[e]=t}function E(t,n){K(t)&&(t=null),K(n)&&(n=null);var r=!0;return!!t&&(e.forEach(Ce.contractsData,function(e){ye(t)===ye(e.start_date)&&ye(n)===ye(e.end_date)&&(r=!1)}),r)}function j(){return void 0===Ce.editData.new_role_id||void 0===Ce.editData.new_role_id.title||""===Ce.editData.new_role_id.title||void 0===Ce.editData.new_role_id.job_contract_id||""===Ce.editData.new_role_id.job_contract_id}function C(e){Ce.collapsedRows[e]=!Ce.collapsedRows[e]}function R(e){return v.getContracts(e).then(function(e){for(var t=[],n={},r=0;r-1&&t.start.push(e),r.indexOf("end_date")>-1&&t.end.push(e)}),b.validate(e.start,e.end,e.contractStart,e.contractEnd),0===n}function $e(e){e.start_date.$error.custom=[],e.end_date.$error.custom=[];var t=L(e.contract.$viewValue);return void 0===t?"Contract is missing":!!_e({start:e.start_date.$viewValue,end:e.end_date.$viewValue,contractStart:t.start_date,contractEnd:t.end_date},{start:e.start_date.$error.custom,end:e.end_date.$error.custom})||"Error"}function we(e){if("title"===e||" "===e)return"Title cannot be title!"}a.debug("Controller: JobRolesController");var ye=r("formatDate"),De={},Ee=r("getActiveValues"),je=["funders","cost_centers"],Ce=this;Ce.contactId=m.contactId,Ce.format=p.DATE_FORMAT,Ce.loading=!0,Ce.pastJobRoles=[],Ce.presentJobRoles=[],Ce.collapsedRows=[],Ce.contactList=[],Ce.editData={},Ce.viewTab=[],Ce.CalendarShow=[],Ce.contractsData=[],Ce.DepartmentsData={},Ce.LevelsData={},Ce.LocationsData={},Ce.RegionsData={},Ce.addNewRoleUrl=m.pathBaseUrl+m.pathIncludeTpl+"add_new_role.html",Ce.jobRolePanelUrl=m.pathBaseUrl+m.pathIncludeTpl+"job_role_panel.html",Ce.rowTypes={},Ce.rowTypes[0]={id:0,name:"Fixed"},Ce.rowTypes[1]={id:1,name:"%"},Ce.addAdditionalRow=$,Ce.addNewRole=w,Ce.cancelNewRole=y,Ce.changeTab=D,Ce.checkIfDatesAreCustom=E,Ce.checkNewRole=j,Ce.collapseRow=C,Ce.deleteAdditionalRow=x,Ce.dpOpen=S,Ce.getContactList=J,Ce.getCostLabel=U,Ce.initData=P,Ce.isChanged=G,Ce.isOpen=Z,Ce.isRowCollapsed=X,Ce.isTab=Q,Ce.onAfterSave=ee,Ce.onCancel=te,Ce.onContractEdited=ne,Ce.onContractSelected=re,Ce.open=ae,Ce.removeRole=ie,Ce.saveNewRole=se,Ce.select=le,Ce.showRowType=ue,Ce.showSave=ce,Ce.status="",Ce.today=fe,Ce.updateAdditionalRowType=me,Ce.updateRole=ve,Ce.validateRole=$e,Ce.validateTitle=we,Ce.openOptionsEditor=q,function(){de(),Ce.today(),o.all([W(),I(Ce.contactId),Ce.getContactList()]).then(function(){Ce.loading=!1})}()}return r.__name="JobRolesController",r.$inject=["$filter","$log","$q","$rootElement","$route","$routeParams","$scope","$timeout","$uibModal","DOMEventTrigger","settings","HR_settings","dateValidation","filtersService","jobRoleService","pubSub","crmAngService"],r}),define("job-roles/controllers/modal-dialog.controller",[],function(){"use strict";function e(e,t,n,r){function a(){e.dismiss("Cancel")}function o(t){e.close(t||!0)}t.debug("Controller: ModalDialogController");var i=this;i.copyCancel=r.copyCancel||"Cancel",i.copyConfirm=r.copyConfirm||"Yes",i.msg=r.msg||"",i.title=r.title||"CiviHR Job Roles",i.cancel=a,i.confirm=o}return e.__name="ModalDialogController",e.$inject=["$uibModalInstance","$log","$timeout","content"],e}),define("job-roles/modules/job-roles.controllers",["common/angular","job-roles/controllers/job-roles.controller","job-roles/controllers/modal-dialog.controller"],function(e,t,n){"use strict";return e.module("hrjobroles.controllers",[]).controller(t.__name,t).controller(n.__name,n)}),angular.module("xeditable",[]).value("editableOptions",{theme:"default",buttons:"right",blurElem:"cancel",blurForm:"ignore",activate:"focus"}),angular.module("xeditable").directive("editableBsdate",["editableDirectiveFactory",function(e){return e({directiveName:"editableBsdate",inputTpl:''})}]),angular.module("xeditable").directive("editableBstime",["editableDirectiveFactory",function(e){return e({directiveName:"editableBstime",inputTpl:"",render:function(){this.parent.render.call(this);var e=angular.element('
    ');e.attr("ng-model",this.inputEl.attr("ng-model")),this.inputEl.removeAttr("ng-model"),this.attrs.eNgChange&&(e.attr("ng-change",this.inputEl.attr("ng-change")),this.inputEl.removeAttr("ng-change")),this.inputEl.wrap(e)}})}]),angular.module("xeditable").directive("editableCheckbox",["editableDirectiveFactory",function(e){return e({directiveName:"editableCheckbox",inputTpl:'',render:function(){this.parent.render.call(this),this.attrs.eTitle&&(this.inputEl.wrap(""),this.inputEl.after(angular.element("").text(this.attrs.eTitle)))},autosubmit:function(){var e=this;e.inputEl.bind("change",function(){setTimeout(function(){e.scope.$apply(function(){e.scope.$form.$submit()})},500)})}})}]),angular.module("xeditable").directive("editableChecklist",["editableDirectiveFactory","editableNgOptionsParser",function(e,t){return e({directiveName:"editableChecklist",inputTpl:"",useCopy:!0,render:function(){this.parent.render.call(this);var e=t(this.attrs.eNgOptions),n='';this.inputEl.removeAttr("ng-model"),this.inputEl.removeAttr("ng-options"),this.inputEl.html(n)}})}]),function(){var e="text|email|tel|number|url|search|color|date|datetime|time|month|week".split("|");angular.forEach(e,function(e){var t="editable"+e.charAt(0).toUpperCase()+e.slice(1);angular.module("xeditable").directive(t,["editableDirectiveFactory",function(n){return n({directiveName:t,inputTpl:''})}])}),angular.module("xeditable").directive("editableRange",["editableDirectiveFactory",function(e){return e({directiveName:"editableRange",inputTpl:'',render:function(){this.parent.render.call(this),this.inputEl.after("{{$data}}")}})}])}(),angular.module("xeditable").directive("editableRadiolist",["editableDirectiveFactory","editableNgOptionsParser",function(e,t){return e({directiveName:"editableRadiolist",inputTpl:"",render:function(){this.parent.render.call(this);var e=t(this.attrs.eNgOptions),n='';this.inputEl.removeAttr("ng-model"),this.inputEl.removeAttr("ng-options"),this.inputEl.html(n)},autosubmit:function(){var e=this;e.inputEl.bind("change",function(){setTimeout(function(){e.scope.$apply(function(){e.scope.$form.$submit()})},500)})}})}]),angular.module("xeditable").directive("editableSelect",["editableDirectiveFactory",function(e){return e({directiveName:"editableSelect",inputTpl:"",autosubmit:function(){var e=this;e.inputEl.bind("change",function(){e.scope.$apply(function(){e.scope.$form.$submit()})})}})}]),angular.module("xeditable").directive("editableTextarea",["editableDirectiveFactory",function(e){return e({directiveName:"editableTextarea",inputTpl:"",addListeners:function(){var e=this;e.parent.addListeners.call(e),e.single&&"no"!==e.buttons&&e.autosubmit()},autosubmit:function(){var e=this;e.inputEl.bind("keydown",function(t){(t.ctrlKey||t.metaKey)&&13===t.keyCode&&e.scope.$apply(function(){e.scope.$form.$submit()})})}})}]),angular.module("xeditable").factory("editableController",["$q","editableUtils",function(e,t){function n(e,n,r,a,o,i,s,l,u){var c,d,f=this;f.scope=e,f.elem=r,f.attrs=n,f.inputEl=null,f.editorEl=null,f.single=!0,f.error="",f.theme=o[i.theme]||o.default,f.parent={},f.inputTpl="",f.directiveName="",f.useCopy=!1,f.single=null,f.buttons="right",f.init=function(t){if(f.single=t,f.name=n.eName||n[f.directiveName],!n[f.directiveName])throw"You should provide value for `"+f.directiveName+"` in editable element!";c=a(n[f.directiveName]),f.buttons=f.single?f.attrs.buttons||i.buttons:"no",n.eName&&f.scope.$watch("$data",function(e){f.scope.$form.$data[n.eName]=e}),n.onshow&&(f.onshow=function(){return f.catchError(a(n.onshow)(e))}),n.onhide&&(f.onhide=function(){return a(n.onhide)(e)}),n.oncancel&&(f.oncancel=function(){return a(n.oncancel)(e)}),n.onbeforesave&&(f.onbeforesave=function(){return f.catchError(a(n.onbeforesave)(e))}),n.onaftersave&&(f.onaftersave=function(){return f.catchError(a(n.onaftersave)(e))}),e.$parent.$watch(n[f.directiveName],function(){f.handleEmpty()})},f.render=function(){var e=f.theme;f.inputEl=angular.element(f.inputTpl),f.controlsEl=angular.element(e.controlsTpl),f.controlsEl.append(f.inputEl),"no"!==f.buttons&&(f.buttonsEl=angular.element(e.buttonsTpl),f.submitEl=angular.element(e.submitTpl),f.cancelEl=angular.element(e.cancelTpl),f.buttonsEl.append(f.submitEl).append(f.cancelEl),f.controlsEl.append(f.buttonsEl),f.inputEl.addClass("editable-has-buttons")),f.errorEl=angular.element(e.errorTpl),f.controlsEl.append(f.errorEl),f.editorEl=angular.element(f.single?e.formTpl:e.noformTpl),f.editorEl.append(f.controlsEl);for(var r in n.$attr)if(!(r.length<=1)){var a=!1,o=r.substring(1,2);if("e"===r.substring(0,1)&&o===o.toUpperCase()&&"Form"!==(a=r.substring(1))&&"NgSubmit"!==a){a=a.substring(0,1).toLowerCase()+t.camelToDash(a.substring(1));var s=""===n[r]?a:n[r];f.inputEl.attr(a,s)}}f.inputEl.addClass("editable-input"),f.inputEl.attr("ng-model","$data"),f.editorEl.addClass(t.camelToDash(f.directiveName)),f.single&&(f.editorEl.attr("editable-form","$form"),f.editorEl.attr("blur",f.attrs.blur||("no"===f.buttons?"cancel":i.blurElem))),angular.isFunction(e.postrender)&&e.postrender.call(f)},f.setLocalValue=function(){f.scope.$data=f.useCopy?angular.copy(c(e.$parent)):c(e.$parent)},f.show=function(){return f.setLocalValue(),f.render(),r.after(f.editorEl),l(f.editorEl)(e),f.addListeners(),r.addClass("editable-hide"),f.onshow()},f.hide=function(){return f.editorEl.remove(),r.removeClass("editable-hide"),f.onhide()},f.cancel=function(){f.oncancel()},f.addListeners=function(){f.inputEl.bind("keyup",function(e){if(f.single)switch(e.keyCode){case 27:f.scope.$apply(function(){f.scope.$form.$cancel()})}}),f.single&&"no"===f.buttons&&f.autosubmit(),f.editorEl.bind("click",function(e){1===e.which&&f.scope.$form.$visible&&(f.scope.$form._clicked=!0)})},f.setWaiting=function(e){e?(d=!f.inputEl.attr("disabled")&&!f.inputEl.attr("ng-disabled")&&!f.inputEl.attr("ng-enabled"))&&(f.inputEl.attr("disabled","disabled"),f.buttonsEl&&f.buttonsEl.find("button").attr("disabled","disabled")):d&&(f.inputEl.removeAttr("disabled"),f.buttonsEl&&f.buttonsEl.find("button").removeAttr("disabled"))},f.activate=function(){setTimeout(function(){var e=f.inputEl[0];"focus"===i.activate&&e.focus&&e.focus(),"select"===i.activate&&e.select&&e.select()},0)},f.setError=function(t){angular.isObject(t)||(e.$error=t,f.error=t)},f.catchError=function(e,t){return angular.isObject(e)&&!0!==t?u.when(e).then(angular.bind(this,function(e){this.catchError(e,!0)}),angular.bind(this,function(e){this.catchError(e,!0)})):t&&angular.isObject(e)&&e.status&&200!==e.status&&e.data&&angular.isString(e.data)?(this.setError(e.data),e=e.data):angular.isString(e)&&this.setError(e),e},f.save=function(){c.assign(e.$parent,angular.copy(f.scope.$data))},f.handleEmpty=function(){var t=c(e.$parent),n=null===t||void 0===t||""===t||angular.isArray(t)&&0===t.length;r.toggleClass("editable-empty",n)},f.autosubmit=angular.noop,f.onshow=angular.noop,f.onhide=angular.noop,f.oncancel=angular.noop,f.onbeforesave=angular.noop,f.onaftersave=angular.noop}return n.$inject=["$scope","$attrs","$element","$parse","editableThemes","editableOptions","$rootScope","$compile","$q"],n}]),angular.module("xeditable").factory("editableDirectiveFactory",["$parse","$compile","editableThemes","$rootScope","$document","editableController","editableFormController",function(e,t,n,r,a,o,i){return function(t){return{restrict:"A",scope:!0,require:[t.directiveName,"?^form"],controller:o,link:function(n,o,s,l){var u,c=l[0],d=!1;if(l[1])u=l[1],d=!0;else if(s.eForm){var f=e(s.eForm)(n);if(f)u=f,d=!0;else for(var m=0;m=0&&e.splice(n,1),t},camelToDash:function(e){var t=/[A-Z]/g;return e.replace(t,function(e,t){return(t?"-":"")+e.toLowerCase()})},dashToCamel:function(e){var t=/([\:\-\_]+(.))/g,n=/^moz([A-Z])/;return e.replace(t,function(e,t,n,r){return r?n.toUpperCase():n}).replace(n,"Moz$1")}}}]),angular.module("xeditable").factory("editableNgOptionsParser",[function(){function e(e){var n;if(!(n=e.match(t)))throw"ng-options parse error";var r,a=n[2]||n[1],o=n[4]||n[6],i=n[5],s=(n[3],n[2]?n[1]:o),l=n[7],u=n[8],c=u?n[8]:null;return void 0===i?(r=o+" in "+l,void 0!==u&&(r+=" track by "+c)):r="("+i+", "+o+") in "+l,{ngRepeat:r,locals:{valueName:o,keyName:i,valueFn:s,displayFn:a}}}var t=/^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+(.*?)(?:\s+track\s+by\s+(.*?))?$/;return e}]),angular.module("xeditable").factory("editableThemes",function(){return{default:{formTpl:'
    ',noformTpl:'',controlsTpl:'',inputTpl:"",errorTpl:'
    ',buttonsTpl:'',submitTpl:'',cancelTpl:''},bs2:{formTpl:'
    ',noformTpl:'',controlsTpl:'
    ',inputTpl:"",errorTpl:'
    ',buttonsTpl:'',submitTpl:'', -cancelTpl:''},bs3:{formTpl:'
    ',noformTpl:'',controlsTpl:'
    ',inputTpl:"",errorTpl:'
    ',buttonsTpl:'',submitTpl:'',cancelTpl:'',buttonsClass:"",inputClass:"",postrender:function(){switch(this.directiveName){case"editableText":case"editableSelect":case"editableTextarea":case"editableEmail":case"editableTel":case"editableNumber":case"editableUrl":case"editableSearch":case"editableDate":case"editableDatetime":case"editableTime":case"editableMonth":case"editableWeek":if(this.inputEl.addClass("form-control"),this.theme.inputClass){if(this.inputEl.attr("multiple")&&("input-sm"===this.theme.inputClass||"input-lg"===this.theme.inputClass))break;this.inputEl.addClass(this.theme.inputClass)}}this.buttonsEl&&this.theme.buttonsClass&&this.buttonsEl.find("button").addClass(this.theme.buttonsClass)}}}}),function(e,t,n){"use strict";function r(e){return F(e)?e:Object.keys(e).map(function(t){return e[t]})}function a(e){return null===e}function o(e,t){return-1==Object.keys(e).map(function(r){return t[r]!==n&&t[r]==e[r]}).indexOf(!1)}function i(e,t){if(""===t)return e;var n=e.indexOf(t.charAt(0));return-1!==n&&i(e.substr(n+1),t.substr(1))}function s(e,t,n){var r=0;return e.filter(function(e){var a=D(n)?t>r&&n(e):t>r;return r=a?r+1:r,a})}function l(e,t,n){return n.round(e*n.pow(10,t))/n.pow(10,t)}function u(e,t,n){return t=t||[],Object.keys(e).forEach(function(r){if(T(e[r])&&!F(e[r])){var a=n?n+"."+r:n;u(e[r],t,a||r)}else{var o=n?n+"."+r:r;t.push(o)}}),t}function c(e){return e&&e.$evalAsync&&e.$watch}function d(){return function(e,t){return e>t}}function f(){return function(e,t){return e>=t}}function m(){return function(e,t){return t>e}}function p(){return function(e,t){return t>=e}}function b(){return function(e,t){return e==t}}function h(){return function(e,t){return e!=t}}function v(){return function(e,t){return e===t}}function g(){return function(e,t){return e!==t}}function _(e){return function(t,n){return t=T(t)?r(t):t,!(!F(t)||E(n))&&t.some(function(t){return T(t)||j(n)?e(n)(t):t===n})}}function $(e,t){return t=t||0,t>=e.length?e:F(e[t])?$(e.slice(0,t).concat(e[t],e.slice(t+1)),t):$(e,t+1)}function w(e){return function(t,n){function a(e,t){return!E(t)&&e.some(function(e){return N(e,t)})}if(t=T(t)?r(t):t,!F(t))return t;var o=[],i=e(n);return t.filter(E(n)?function(e,t,n){return n.indexOf(e)===t}:function(e){var t=i(e);return!a(o,t)&&(o.push(t),!0)})}}function y(e,t,n){return t?e+n+y(e,--t,n):e}var D=t.isDefined,E=t.isUndefined,j=t.isFunction,C=t.isString,R=t.isNumber,T=t.isObject,F=t.isArray,x=t.forEach,A=t.extend,S=t.copy,N=t.equals;String.prototype.contains||(String.prototype.contains=function(){return-1!==String.prototype.indexOf.apply(this,arguments)}),t.module("a8m.angular",[]).filter("isUndefined",function(){return function(e){return t.isUndefined(e)}}).filter("isDefined",function(){return function(e){return t.isDefined(e)}}).filter("isFunction",function(){return function(e){return t.isFunction(e)}}).filter("isString",function(){return function(e){return t.isString(e)}}).filter("isNumber",function(){return function(e){return t.isNumber(e)}}).filter("isArray",function(){return function(e){return t.isArray(e)}}).filter("isObject",function(){return function(e){return t.isObject(e)}}).filter("isEqual",function(){return function(e,n){return t.equals(e,n)}}),t.module("a8m.conditions",[]).filter({isGreaterThan:d,">":d,isGreaterThanOrEqualTo:f,">=":f,isLessThan:m,"<":m,isLessThanOrEqualTo:p,"<=":p,isEqualTo:b,"==":b,isNotEqualTo:h,"!=":h,isIdenticalTo:v,"===":v,isNotIdenticalTo:g,"!==":g}),t.module("a8m.is-null",[]).filter("isNull",function(){return function(e){return a(e)}}),t.module("a8m.after-where",[]).filter("afterWhere",function(){return function(e,t){if(e=T(e)?r(e):e,!F(e)||E(t))return e;var n=e.map(function(e){return o(t,e)}).indexOf(!0);return e.slice(-1===n?0:n)}}),t.module("a8m.after",[]).filter("after",function(){return function(e,t){return e=T(e)?r(e):e,F(e)?e.slice(t):e}}),t.module("a8m.before-where",[]).filter("beforeWhere",function(){return function(e,t){if(e=T(e)?r(e):e,!F(e)||E(t))return e;var n=e.map(function(e){return o(t,e)}).indexOf(!0);return e.slice(0,-1===n?e.length:++n)}}),t.module("a8m.before",[]).filter("before",function(){return function(e,t){return e=T(e)?r(e):e,F(e)?e.slice(0,t?--t:t):e}}),t.module("a8m.concat",[]).filter("concat",[function(){return function(e,t){if(E(t))return e;if(F(e))return e.concat(T(t)?r(t):t);if(T(e)){return r(e).concat(T(t)?r(t):t)}return e}}]),t.module("a8m.contains",[]).filter({contains:["$parse",_],some:["$parse",_]}),t.module("a8m.count-by",[]).filter("countBy",["$parse",function(e){return function(t,n){var a,o={},i=e(n);return t=T(t)?r(t):t,!F(t)||E(n)?t:(t.forEach(function(e){a=i(e),o[a]||(o[a]=0),o[a]++}),o)}}]),t.module("a8m.defaults",[]).filter("defaults",["$parse",function(e){return function(t,n){if(t=T(t)?r(t):t,!F(t)||!T(n))return t;var a=u(n);return t.forEach(function(t){a.forEach(function(r){var a=e(r),o=a.assign;E(a(t))&&o(t,a(n))})}),t}}]),t.module("a8m.every",[]).filter("every",["$parse",function(e){return function(t,n){return t=T(t)?r(t):t,!(F(t)&&!E(n))||t.every(function(t){return T(t)||j(n)?e(n)(t):t===n})}}]),t.module("a8m.filter-by",[]).filter("filterBy",["$parse",function(e){return function(t,a,o){var i;return o=C(o)||R(o)?String(o).toLowerCase():n,t=T(t)?r(t):t,!F(t)||E(o)?t:t.filter(function(t){return a.some(function(n){if(~n.indexOf("+")){var r=n.replace(new RegExp("\\s","g"),"").split("+");i=r.reduce(function(n,r,a){return 1===a?e(n)(t)+" "+e(r)(t):n+" "+e(r)(t)})}else i=e(n)(t);return!(!C(i)&&!R(i))&&String(i).toLowerCase().contains(o)})})}}]),t.module("a8m.first",[]).filter("first",["$parse",function(e){return function(t){var a,o,i;return t=T(t)?r(t):t,F(t)?(i=Array.prototype.slice.call(arguments,1),a=R(i[0])?i[0]:1,o=R(i[0])?R(i[1])?n:i[1]:i[0],i.length?s(t,a,o?e(o):o):t[0]):t}}]),t.module("a8m.flatten",[]).filter("flatten",function(){return function(e,t){return t=t||!1,e=T(e)?r(e):e,F(e)?t?[].concat.apply([],e):$(e,0):e}}),t.module("a8m.fuzzy-by",[]).filter("fuzzyBy",["$parse",function(e){return function(t,n,a,o){var s,l,u=o||!1;return t=T(t)?r(t):t,!F(t)||E(n)||E(a)?t:(l=e(n),t.filter(function(e){return s=l(e),!!C(s)&&(s=u?s:s.toLowerCase(),a=u?a:a.toLowerCase(),!1!==i(s,a))}))}}]),t.module("a8m.fuzzy",[]).filter("fuzzy",function(){return function(e,t,n){function a(e,t){var n,r;return 0=0&&R(t)&&isFinite(t)?1024>t?l(t,n,e)+" B":1048576>t?l(t/1024,n,e)+" KB":1073741824>t?l(t/1048576,n,e)+" MB":l(t/1073741824,n,e)+" GB":"NaN"}}]),t.module("a8m.math.degrees",["a8m.math"]).filter("degrees",["$math",function(e){return function(t,n){if(R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)){var r=180*t/e.PI;return e.round(r*e.pow(10,n))/e.pow(10,n)}return"NaN"}}]),t.module("a8m.math.kbFmt",["a8m.math"]).filter("kbFmt",["$math",function(e){return function(t,n){return R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)?1024>t?l(t,n,e)+" KB":1048576>t?l(t/1024,n,e)+" MB":l(t/1048576,n,e)+" GB":"NaN"}}]),t.module("a8m.math",[]).factory("$math",["$window",function(e){return e.Math}]),t.module("a8m.math.max",["a8m.math"]).filter("max",["$math","$parse",function(e,t){function n(n,r){var a=n.map(function(e){return t(r)(e)});return a.indexOf(e.max.apply(e,a))}return function(t,r){return F(t)?E(r)?e.max.apply(e,t):t[n(t,r)]:t}}]),t.module("a8m.math.min",["a8m.math"]).filter("min",["$math","$parse",function(e,t){function n(n,r){var a=n.map(function(e){return t(r)(e)});return a.indexOf(e.min.apply(e,a))}return function(t,r){return F(t)?E(r)?e.min.apply(e,t):t[n(t,r)]:t}}]),t.module("a8m.math.percent",["a8m.math"]).filter("percent",["$math","$window",function(e,t){return function(n,r,a){var o=C(n)?t.Number(n):n;return r=r||100,a=a||!1,!R(o)||t.isNaN(o)?n:a?e.round(o/r*100):o/r*100}}]),t.module("a8m.math.radians",["a8m.math"]).filter("radians",["$math",function(e){return function(t,n){if(R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)){var r=3.14159265359*t/180;return e.round(r*e.pow(10,n))/e.pow(10,n)}return"NaN"}}]),t.module("a8m.math.radix",[]).filter("radix",function(){return function(e,t){var n=/^[2-9]$|^[1-2]\d$|^3[0-6]$/;return R(e)&&n.test(t)?e.toString(t).toUpperCase():e}}),t.module("a8m.math.shortFmt",["a8m.math"]).filter("shortFmt",["$math",function(e){return function(t,n){return R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)?1e3>t?t:1e6>t?l(t/1e3,n,e)+" K":1e9>t?l(t/1e6,n,e)+" M":l(t/1e9,n,e)+" B":"NaN"}}]),t.module("a8m.math.sum",[]).filter("sum",function(){return function(e,t){return F(e)?e.reduce(function(e,t){return e+t},t||0):e}}),t.module("a8m.ends-with",[]).filter("endsWith",function(){return function(e,t,n){var r,a=n||!1;return!C(e)||E(t)?e:(e=a?e:e.toLowerCase(),r=e.length-t.length,-1!==e.indexOf(a?t:t.toLowerCase(),r))}}),t.module("a8m.latinize",[]).filter("latinize",[function(){function e(e){return e.replace(/[^\u0000-\u007E]/g,function(e){return n[e]||e})}for(var t=[{base:"A",letters:"AⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ"},{base:"AA",letters:"Ꜳ"},{base:"AE",letters:"ÆǼǢ"},{base:"AO",letters:"Ꜵ"},{base:"AU",letters:"Ꜷ"},{base:"AV",letters:"ꜸꜺ"},{base:"AY",letters:"Ꜽ"},{base:"B",letters:"BⒷBḂḄḆɃƂƁ"},{base:"C",letters:"CⒸCĆĈĊČÇḈƇȻꜾ"},{base:"D",letters:"DⒹDḊĎḌḐḒḎĐƋƊƉꝹ"},{base:"DZ",letters:"DZDŽ"},{base:"Dz",letters:"DzDž"},{base:"E",letters:"EⒺEÈÉÊỀẾỄỂẼĒḔḖĔĖËẺĚȄȆẸỆȨḜĘḘḚƐƎ"},{base:"F",letters:"FⒻFḞƑꝻ"},{base:"G",letters:"GⒼGǴĜḠĞĠǦĢǤƓꞠꝽꝾ"},{base:"H",letters:"HⒽHĤḢḦȞḤḨḪĦⱧⱵꞍ"},{base:"I",letters:"IⒾIÌÍÎĨĪĬİÏḮỈǏȈȊỊĮḬƗ"},{base:"J",letters:"JⒿJĴɈ"},{base:"K",letters:"KⓀKḰǨḲĶḴƘⱩꝀꝂꝄꞢ"},{base:"L",letters:"LⓁLĿĹĽḶḸĻḼḺŁȽⱢⱠꝈꝆꞀ"},{base:"LJ",letters:"LJ"},{base:"Lj",letters:"Lj"},{base:"M",letters:"MⓂMḾṀṂⱮƜ"},{base:"N",letters:"NⓃNǸŃÑṄŇṆŅṊṈȠƝꞐꞤ"},{base:"NJ",letters:"NJ"},{base:"Nj",letters:"Nj"},{base:"O",letters:"OⓄOÒÓÔỒỐỖỔÕṌȬṎŌṐṒŎȮȰÖȪỎŐǑȌȎƠỜỚỠỞỢỌỘǪǬØǾƆƟꝊꝌ"},{base:"OI",letters:"Ƣ"},{base:"OO",letters:"Ꝏ"},{base:"OU",letters:"Ȣ"},{base:"OE",letters:"ŒŒ"},{base:"oe",letters:"œœ"},{base:"P",letters:"PⓅPṔṖƤⱣꝐꝒꝔ"},{base:"Q",letters:"QⓆQꝖꝘɊ"},{base:"R",letters:"RⓇRŔṘŘȐȒṚṜŖṞɌⱤꝚꞦꞂ"},{base:"S",letters:"SⓈSẞŚṤŜṠŠṦṢṨȘŞⱾꞨꞄ"},{base:"T",letters:"TⓉTṪŤṬȚŢṰṮŦƬƮȾꞆ"},{base:"TZ",letters:"Ꜩ"},{base:"U",letters:"UⓊUÙÚÛŨṸŪṺŬÜǛǗǕǙỦŮŰǓȔȖƯỪỨỮỬỰỤṲŲṶṴɄ"},{base:"V",letters:"VⓋVṼṾƲꝞɅ"},{base:"VY",letters:"Ꝡ"},{base:"W",letters:"WⓌWẀẂŴẆẄẈⱲ"},{base:"X",letters:"XⓍXẊẌ"},{base:"Y",letters:"YⓎYỲÝŶỸȲẎŸỶỴƳɎỾ"},{base:"Z",letters:"ZⓏZŹẐŻŽẒẔƵȤⱿⱫꝢ"},{base:"a",letters:"aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐ"},{base:"aa",letters:"ꜳ"},{base:"ae",letters:"æǽǣ"},{base:"ao",letters:"ꜵ"},{base:"au",letters:"ꜷ"},{base:"av",letters:"ꜹꜻ"},{base:"ay",letters:"ꜽ"},{base:"b",letters:"bⓑbḃḅḇƀƃɓ"},{base:"c",letters:"cⓒcćĉċčçḉƈȼꜿↄ"},{base:"d",letters:"dⓓdḋďḍḑḓḏđƌɖɗꝺ"},{base:"dz",letters:"dzdž"},{base:"e",letters:"eⓔeèéêềếễểẽēḕḗĕėëẻěȅȇẹệȩḝęḙḛɇɛǝ"},{base:"f",letters:"fⓕfḟƒꝼ"},{base:"g",letters:"gⓖgǵĝḡğġǧģǥɠꞡᵹꝿ"},{base:"h",letters:"hⓗhĥḣḧȟḥḩḫẖħⱨⱶɥ"},{base:"hv",letters:"ƕ"},{base:"i",letters:"iⓘiìíîĩīĭïḯỉǐȉȋịįḭɨı"},{base:"j",letters:"jⓙjĵǰɉ"},{base:"k",letters:"kⓚkḱǩḳķḵƙⱪꝁꝃꝅꞣ"},{base:"l",letters:"lⓛlŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇ"},{base:"lj",letters:"lj"},{base:"m",letters:"mⓜmḿṁṃɱɯ"},{base:"n",letters:"nⓝnǹńñṅňṇņṋṉƞɲʼnꞑꞥ"},{base:"nj",letters:"nj"},{base:"o",letters:"oⓞoòóôồốỗổõṍȭṏōṑṓŏȯȱöȫỏőǒȍȏơờớỡởợọộǫǭøǿɔꝋꝍɵ"},{base:"oi",letters:"ƣ"},{base:"ou",letters:"ȣ"},{base:"oo",letters:"ꝏ"},{base:"p",letters:"pⓟpṕṗƥᵽꝑꝓꝕ"},{base:"q",letters:"qⓠqɋꝗꝙ"},{base:"r",letters:"rⓡrŕṙřȑȓṛṝŗṟɍɽꝛꞧꞃ"},{base:"s",letters:"sⓢsßśṥŝṡšṧṣṩșşȿꞩꞅẛ"},{base:"t",letters:"tⓣtṫẗťṭțţṱṯŧƭʈⱦꞇ"},{base:"tz",letters:"ꜩ"},{base:"u",letters:"uⓤuùúûũṹūṻŭüǜǘǖǚủůűǔȕȗưừứữửựụṳųṷṵʉ"},{base:"v",letters:"vⓥvṽṿʋꝟʌ"},{base:"vy",letters:"ꝡ"},{base:"w",letters:"wⓦwẁẃŵẇẅẘẉⱳ"},{base:"x",letters:"xⓧxẋẍ"},{base:"y",letters:"yⓨyỳýŷỹȳẏÿỷẙỵƴɏỿ"},{base:"z",letters:"zⓩzźẑżžẓẕƶȥɀⱬꝣ"}],n={},r=0;r<]*>/g,""):e}}),t.module("a8m.test",[]).filter("test",function(){return function(e,t,n){var r=new RegExp(t,n);return C(e)?r.test(e):e}}),t.module("a8m.trim",[]).filter("trim",function(){return function(e,t){var n=t||"\\s";return C(e)?e.replace(new RegExp("^"+n+"+|"+n+"+$","g"),""):e}}),t.module("a8m.truncate",[]).filter("truncate",function(){return function(e,t,n,r){return t=E(t)?e.length:t,r=r||!1,n=n||"",!C(e)||e.length<=t?e:e.substring(0,r?-1===e.indexOf(" ",t)?e.length:e.indexOf(" ",t):t)+n}}),t.module("a8m.ucfirst",[]).filter("ucfirst",[function(){return function(e){return C(e)?e.split(" ").map(function(e){return e.charAt(0).toUpperCase()+e.substring(1)}).join(" "):e}}]),t.module("a8m.uri-component-encode",[]).filter("uriComponentEncode",["$window",function(e){return function(t){return C(t)?e.encodeURIComponent(t):t}}]),t.module("a8m.uri-encode",[]).filter("uriEncode",["$window",function(e){return function(t){return C(t)?e.encodeURI(t):t}}]),t.module("a8m.wrap",[]).filter("wrap",function(){return function(e,t,n){return C(e)&&D(t)?[t,e,n||t].join(""):e}}),t.module("a8m.filter-watcher",[]).provider("filterWatcher",function(){this.$get=["$window","$rootScope",function(e,n){function r(e,n){return[e,t.toJson(n)].join("#").replace(/"/g,"")}function a(e){var t=e.targetScope.$id;x(d[t],function(e){delete u[e]}),delete d[t]}function o(){f(function(){n.$$phase||(u={})})}function i(e,t){var n=e.$id;return E(d[n])&&(e.$on("$destroy",a),d[n]=[]),d[n].push(t)}function s(e,t){var n=r(e,t);return u[n]}function l(e,t,n,a){var s=r(e,t);return u[s]=a,c(n)?i(n,s):o(),a}var u={},d={},f=e.setTimeout;return{isMemoized:s,memoize:l}}]}),t.module("angular.filter",["a8m.ucfirst","a8m.uri-encode","a8m.uri-component-encode","a8m.slugify","a8m.latinize","a8m.strip-tags","a8m.stringular","a8m.truncate","a8m.starts-with","a8m.ends-with","a8m.wrap","a8m.trim","a8m.ltrim","a8m.rtrim","a8m.repeat","a8m.test","a8m.match","a8m.to-array","a8m.concat","a8m.contains","a8m.unique","a8m.is-empty","a8m.after","a8m.after-where","a8m.before","a8m.before-where","a8m.defaults","a8m.where","a8m.reverse","a8m.remove","a8m.remove-with","a8m.group-by","a8m.count-by","a8m.search-field","a8m.fuzzy-by","a8m.fuzzy","a8m.omit","a8m.pick","a8m.every","a8m.filter-by","a8m.xor","a8m.map","a8m.first","a8m.last","a8m.flatten","a8m.join","a8m.math","a8m.math.max","a8m.math.min","a8m.math.percent","a8m.math.radix","a8m.math.sum","a8m.math.degrees","a8m.math.radians","a8m.math.byteFmt","a8m.math.kbFmt","a8m.math.shortFmt","a8m.angular","a8m.conditions","a8m.is-null","a8m.filter-watcher"])}(window,window.angular),define("job-roles/modules/job-roles.core",["common/angular","common/ui-select","common/directives/angular-date/date-input","common/modules/directives","common/modules/routers/compu-ng-route","common/filters/angular-date/format-date","common/services/angular-date/date-format","common/services/crm-ang.service","common/services/dom-event-trigger","common/services/pub-sub","job-roles/vendor/angular-editable","job-roles/vendor/angular-filter"],function(e){"use strict";e.module("hrjobroles.core",["angular.filter","ngAnimate","ngSanitize","ngResource","ui.bootstrap","ui.select","xeditable","common.angularDate","common.directives","common.services","compuNgRoute"])}),define("job-roles/filters/get-active-values.filter",["common/lodash"],function(e){"use strict";function t(t){return t.debug("Filter: getActiveValues"),function(t){var n={};return e.each(t,function(e,t){"1"===e.is_active&&(n[t]=e)}),n}}return t.__name="getActiveValues",t.$inject=["$log"],t}),define("job-roles/modules/job-roles.filters",["common/angular","job-roles/filters/get-active-values.filter"],function(e,t){"use strict";return e.module("hrjobroles.filters",[]).filter(t.__name,t)}),define("job-roles/modules/job-roles.run",["common/angular"],function(e){"use strict";function t(e,t,n,r){n.theme="bs3",t.contactId=r.contactId,t.pathBaseUrl=r.pathBaseUrl,t.pathTpl=r.pathTpl,t.pathIncludeTpl=r.pathIncludeTpl,t.prefix=r.classNamePrefix}e.module("hrjobroles.run",["hrjobroles.constants"]).run(t),t.$inject=["$q","$rootScope","editableOptions","settings"]}),define("job-roles/services/date-validation.service",["common/moment"],function(e){function t(t){function n(e,t){e.isValid()||l("Date is not valid!!",t)}function r(e,t){e.isSameOrAfter(t)&&l("Start Date cannot be the same as or after the End Date.",["start_date","end_date"])}function a(e,t){e.isBefore(t)&&l("Start Date cannot be lower than Contract Start Date.",["start_date"])}function o(e,t){e.isAfter(t)&&l("Start Date cannot be higher than Contract End Date.",["start_date"])}function i(e,t){e.isAfter(t)&&l("End Date cannot be higher than Contract End Date.",["end_date"])}function s(t,n){return t instanceof Date&&(t=e(t).valueOf()),e(t,n,!0).startOf("day")}var l=function(e,t){throw new Error(e,t[0])},u={dateFormats:["x","YYYY-MM-DD"],setErrorCallback:function(e){if("function"!=typeof e)throw new TypeError("Error callback must be a function.");l=e},validate:function(e,t,l,u){e=s(e,this.dateFormats),l=s(l,this.dateFormats),u=s(u,this.dateFormats),n(e,["start_date"]),o(e,u),a(e,l),(0===t||t)&&(t=s(t,this.dateFormats),n(t,["end_date"]),i(t,u),r(e,t))}};return t.DATE_FORMAT&&u.dateFormats.push(t.DATE_FORMAT.toUpperCase()),u}return t.__name="dateValidation",t.$inject=["HR_settings"],t}),define("job-roles/services/filters.service",[],function(){"use strict";function e(){return{isNotUndefined:function(e){try{return e.constructor===Array?e.filter(function(e){return"undefined"!==e&&void 0!==e}):e}catch(t){return e}},issetCostCentre:function(e){try{return e.constructor===Array?e.filter(function(e){return""!==e.cost_centre_id&&("1"===e.type&&parseInt(e.percentage)>0||"0"===e.type&&parseInt(e.amount)>0)}):e}catch(t){return e}},issetFunder:function(e){try{return e.constructor===Array?e.filter(function(e){return""!==e.funder_id&&("1"===e.type&&parseInt(e.percentage)>0||"0"===e.type&&parseInt(e.amount)>0)}):e}catch(t){return e}}}}return e.__name="filtersService",e}),define("job-roles/services/job-role.service",["common/lodash"],function(e){"use strict";function t(t,n,r){function a(n){var r=n["api.HRJobContractRevision.get"].values;delete n["api.HRJobContractRevision.get"],n.revisions=e.compact(r.map(function(e){var r=e["api.HRJobDetails.getsingle"];return r.period_start_date===n.period_start_date&&r.period_end_date===n.period_end_date?null:(r.period_start_date=t("formatDate")(r.period_start_date),r.period_end_date=t("formatDate")(r.period_end_date),r)}))}return{getContracts:function(e){var t=r.defer();return CRM.api3("HRJobContract","get",{sequential:1,contact_id:e,deleted:0,return:"title,period_end_date,period_start_date","api.HRJobContractRevision.get":{jobcontract_id:"$value.id","api.HRJobDetails.getsingle":{jobcontract_revision_id:"$value.id"}}}).done(function(e){e.values.forEach(a),t.resolve(e)}).error(function(){t.reject("An error occured while fetching items")}),t.promise},getAllJobRoles:function(e){var t=r.defer();return CRM.api3("HrJobRoles","get",{sequential:1,return:"id,job_contract_id,title,description,status,funder,funder_val_type,percent_pay_funder,amount_pay_funder,cost_center,cost_center_val_type,percent_pay_cost_center,amount_pay_cost_center,level_type,location,region,department,end_date,start_date",job_contract_id:{IN:e}}).done(function(e){t.resolve(e)}).error(function(e){t.reject("An error occured while fetching items")}),t.promise},deleteJobRole:function(e){var t=r.defer();return CRM.api3("HrJobRoles","delete",{sequential:1,id:e}).done(function(e){t.resolve(e)}).error(function(e){t.reject("An error occured while deleting items")}),t.promise},createJobRole:function(e){var t="|",n="|",a="|",o="|",i="|",s="|",l="|",u="|";if(void 0!==e.funders)for(var c=0,d=e.funders.length;c-1&&t.start.push(e),r.indexOf("end_date")>-1&&t.end.push(e)}),h.validate(e.start,e.end,e.contractStart,e.contractEnd),0===n}function $e(e){e.start_date.$error.custom=[],e.end_date.$error.custom=[];var t=L(e.contract.$viewValue);return void 0===t?"Contract is missing":!!_e({start:e.start_date.$viewValue,end:e.end_date.$viewValue,contractStart:t.start_date,contractEnd:t.end_date},{start:e.start_date.$error.custom,end:e.end_date.$error.custom})||"Error"}function we(e){if("title"===e||" "===e)return"Title cannot be title!"}a.debug("Controller: JobRolesController");var ye=r("formatDate"),De={},Ee=r("getActiveValues"),je=["funders","cost_centers"],Ce=this;Ce.contactId=m.contactId,Ce.format=p.DATE_FORMAT,Ce.loading=!0,Ce.pastJobRoles=[],Ce.presentJobRoles=[],Ce.collapsedRows=[],Ce.contactList=[],Ce.editData={},Ce.viewTab=[],Ce.CalendarShow=[],Ce.contractsData=[],Ce.DepartmentsData={},Ce.LevelsData={},Ce.LocationsData={},Ce.RegionsData={},Ce.addNewRoleUrl=m.pathBaseUrl+m.pathIncludeTpl+"add_new_role.html",Ce.jobRolePanelUrl=m.pathBaseUrl+m.pathIncludeTpl+"job_role_panel.html",Ce.rowTypes={},Ce.rowTypes[0]={id:0,name:"Fixed"},Ce.rowTypes[1]={id:1,name:"%"},Ce.addAdditionalRow=$,Ce.addNewRole=w,Ce.cancelNewRole=y,Ce.changeTab=D,Ce.checkIfDatesAreCustom=E,Ce.checkNewRole=j,Ce.collapseRow=C,Ce.deleteAdditionalRow=x,Ce.dpOpen=S,Ce.getContactList=J,Ce.getCostLabel=U,Ce.initData=P,Ce.isChanged=G,Ce.isOpen=Z,Ce.isRowCollapsed=X,Ce.isTab=Q,Ce.onAfterSave=ee,Ce.onCancel=te,Ce.onContractEdited=ne,Ce.onContractSelected=re,Ce.open=ae,Ce.removeRole=ie,Ce.saveNewRole=se,Ce.select=le,Ce.showRowType=ue,Ce.showSave=ce,Ce.status="",Ce.today=fe,Ce.updateAdditionalRowType=me,Ce.updateRole=ve,Ce.validateRole=$e,Ce.validateTitle=we,Ce.openOptionsEditor=q,function(){de(),Ce.today(),o.all([W(),I(Ce.contactId),Ce.getContactList()]).then(function(){Ce.loading=!1})}()}return r.__name="JobRolesController",r.$inject=["$filter","$log","$q","$rootElement","$route","$routeParams","$scope","$timeout","$uibModal","DOMEventTrigger","settings","HR_settings","crmAngService","dateValidation","filtersService","jobRoleService","pubSub"],r}),define("job-roles/controllers/modal-dialog.controller",[],function(){"use strict";function e(e,t,n,r){function a(){e.dismiss("Cancel")}function o(t){e.close(t||!0)}t.debug("Controller: ModalDialogController");var i=this;i.copyCancel=r.copyCancel||"Cancel",i.copyConfirm=r.copyConfirm||"Yes",i.msg=r.msg||"",i.title=r.title||"CiviHR Job Roles",i.cancel=a,i.confirm=o}return e.__name="ModalDialogController",e.$inject=["$uibModalInstance","$log","$timeout","content"],e}),define("job-roles/modules/job-roles.controllers",["common/angular","job-roles/controllers/job-roles.controller","job-roles/controllers/modal-dialog.controller"],function(e,t,n){"use strict";return e.module("hrjobroles.controllers",[]).controller(t.__name,t).controller(n.__name,n)}),angular.module("xeditable",[]).value("editableOptions",{theme:"default",buttons:"right",blurElem:"cancel",blurForm:"ignore",activate:"focus"}),angular.module("xeditable").directive("editableBsdate",["editableDirectiveFactory",function(e){return e({directiveName:"editableBsdate",inputTpl:''})}]),angular.module("xeditable").directive("editableBstime",["editableDirectiveFactory",function(e){return e({directiveName:"editableBstime",inputTpl:"",render:function(){this.parent.render.call(this);var e=angular.element('
    ');e.attr("ng-model",this.inputEl.attr("ng-model")),this.inputEl.removeAttr("ng-model"),this.attrs.eNgChange&&(e.attr("ng-change",this.inputEl.attr("ng-change")),this.inputEl.removeAttr("ng-change")),this.inputEl.wrap(e)}})}]),angular.module("xeditable").directive("editableCheckbox",["editableDirectiveFactory",function(e){return e({directiveName:"editableCheckbox",inputTpl:'',render:function(){this.parent.render.call(this),this.attrs.eTitle&&(this.inputEl.wrap(""),this.inputEl.after(angular.element("").text(this.attrs.eTitle)))},autosubmit:function(){var e=this;e.inputEl.bind("change",function(){setTimeout(function(){e.scope.$apply(function(){e.scope.$form.$submit()})},500)})}})}]),angular.module("xeditable").directive("editableChecklist",["editableDirectiveFactory","editableNgOptionsParser",function(e,t){return e({directiveName:"editableChecklist",inputTpl:"",useCopy:!0,render:function(){this.parent.render.call(this);var e=t(this.attrs.eNgOptions),n='';this.inputEl.removeAttr("ng-model"),this.inputEl.removeAttr("ng-options"),this.inputEl.html(n)}})}]),function(){var e="text|email|tel|number|url|search|color|date|datetime|time|month|week".split("|");angular.forEach(e,function(e){var t="editable"+e.charAt(0).toUpperCase()+e.slice(1);angular.module("xeditable").directive(t,["editableDirectiveFactory",function(n){return n({directiveName:t,inputTpl:''})}])}),angular.module("xeditable").directive("editableRange",["editableDirectiveFactory",function(e){return e({directiveName:"editableRange",inputTpl:'',render:function(){this.parent.render.call(this),this.inputEl.after("{{$data}}")}})}])}(),angular.module("xeditable").directive("editableRadiolist",["editableDirectiveFactory","editableNgOptionsParser",function(e,t){return e({directiveName:"editableRadiolist",inputTpl:"",render:function(){this.parent.render.call(this);var e=t(this.attrs.eNgOptions),n='';this.inputEl.removeAttr("ng-model"),this.inputEl.removeAttr("ng-options"),this.inputEl.html(n)},autosubmit:function(){var e=this;e.inputEl.bind("change",function(){setTimeout(function(){e.scope.$apply(function(){e.scope.$form.$submit()})},500)})}})}]),angular.module("xeditable").directive("editableSelect",["editableDirectiveFactory",function(e){return e({directiveName:"editableSelect",inputTpl:"",autosubmit:function(){var e=this;e.inputEl.bind("change",function(){e.scope.$apply(function(){e.scope.$form.$submit()})})}})}]),angular.module("xeditable").directive("editableTextarea",["editableDirectiveFactory",function(e){return e({directiveName:"editableTextarea",inputTpl:"",addListeners:function(){var e=this;e.parent.addListeners.call(e),e.single&&"no"!==e.buttons&&e.autosubmit()},autosubmit:function(){var e=this;e.inputEl.bind("keydown",function(t){(t.ctrlKey||t.metaKey)&&13===t.keyCode&&e.scope.$apply(function(){e.scope.$form.$submit()})})}})}]),angular.module("xeditable").factory("editableController",["$q","editableUtils",function(e,t){function n(e,n,r,a,o,i,s,l,u){var c,d,f=this;f.scope=e,f.elem=r,f.attrs=n,f.inputEl=null,f.editorEl=null,f.single=!0,f.error="",f.theme=o[i.theme]||o.default,f.parent={},f.inputTpl="",f.directiveName="",f.useCopy=!1,f.single=null,f.buttons="right",f.init=function(t){if(f.single=t,f.name=n.eName||n[f.directiveName],!n[f.directiveName])throw"You should provide value for `"+f.directiveName+"` in editable element!";c=a(n[f.directiveName]),f.buttons=f.single?f.attrs.buttons||i.buttons:"no",n.eName&&f.scope.$watch("$data",function(e){f.scope.$form.$data[n.eName]=e}),n.onshow&&(f.onshow=function(){return f.catchError(a(n.onshow)(e))}),n.onhide&&(f.onhide=function(){return a(n.onhide)(e)}),n.oncancel&&(f.oncancel=function(){return a(n.oncancel)(e)}),n.onbeforesave&&(f.onbeforesave=function(){return f.catchError(a(n.onbeforesave)(e))}),n.onaftersave&&(f.onaftersave=function(){return f.catchError(a(n.onaftersave)(e))}),e.$parent.$watch(n[f.directiveName],function(){f.handleEmpty()})},f.render=function(){var e=f.theme;f.inputEl=angular.element(f.inputTpl),f.controlsEl=angular.element(e.controlsTpl),f.controlsEl.append(f.inputEl),"no"!==f.buttons&&(f.buttonsEl=angular.element(e.buttonsTpl),f.submitEl=angular.element(e.submitTpl),f.cancelEl=angular.element(e.cancelTpl),f.buttonsEl.append(f.submitEl).append(f.cancelEl),f.controlsEl.append(f.buttonsEl),f.inputEl.addClass("editable-has-buttons")),f.errorEl=angular.element(e.errorTpl),f.controlsEl.append(f.errorEl),f.editorEl=angular.element(f.single?e.formTpl:e.noformTpl),f.editorEl.append(f.controlsEl);for(var r in n.$attr)if(!(r.length<=1)){var a=!1,o=r.substring(1,2);if("e"===r.substring(0,1)&&o===o.toUpperCase()&&"Form"!==(a=r.substring(1))&&"NgSubmit"!==a){a=a.substring(0,1).toLowerCase()+t.camelToDash(a.substring(1));var s=""===n[r]?a:n[r];f.inputEl.attr(a,s)}}f.inputEl.addClass("editable-input"),f.inputEl.attr("ng-model","$data"),f.editorEl.addClass(t.camelToDash(f.directiveName)),f.single&&(f.editorEl.attr("editable-form","$form"),f.editorEl.attr("blur",f.attrs.blur||("no"===f.buttons?"cancel":i.blurElem))),angular.isFunction(e.postrender)&&e.postrender.call(f)},f.setLocalValue=function(){f.scope.$data=f.useCopy?angular.copy(c(e.$parent)):c(e.$parent)},f.show=function(){return f.setLocalValue(),f.render(),r.after(f.editorEl),l(f.editorEl)(e),f.addListeners(),r.addClass("editable-hide"),f.onshow()},f.hide=function(){return f.editorEl.remove(),r.removeClass("editable-hide"),f.onhide()},f.cancel=function(){f.oncancel()},f.addListeners=function(){f.inputEl.bind("keyup",function(e){if(f.single)switch(e.keyCode){case 27:f.scope.$apply(function(){f.scope.$form.$cancel()})}}),f.single&&"no"===f.buttons&&f.autosubmit(),f.editorEl.bind("click",function(e){1===e.which&&f.scope.$form.$visible&&(f.scope.$form._clicked=!0)})},f.setWaiting=function(e){e?(d=!f.inputEl.attr("disabled")&&!f.inputEl.attr("ng-disabled")&&!f.inputEl.attr("ng-enabled"))&&(f.inputEl.attr("disabled","disabled"),f.buttonsEl&&f.buttonsEl.find("button").attr("disabled","disabled")):d&&(f.inputEl.removeAttr("disabled"),f.buttonsEl&&f.buttonsEl.find("button").removeAttr("disabled"))},f.activate=function(){setTimeout(function(){var e=f.inputEl[0];"focus"===i.activate&&e.focus&&e.focus(),"select"===i.activate&&e.select&&e.select()},0)},f.setError=function(t){angular.isObject(t)||(e.$error=t,f.error=t)},f.catchError=function(e,t){return angular.isObject(e)&&!0!==t?u.when(e).then(angular.bind(this,function(e){this.catchError(e,!0)}),angular.bind(this,function(e){this.catchError(e,!0)})):t&&angular.isObject(e)&&e.status&&200!==e.status&&e.data&&angular.isString(e.data)?(this.setError(e.data),e=e.data):angular.isString(e)&&this.setError(e),e},f.save=function(){c.assign(e.$parent,angular.copy(f.scope.$data))},f.handleEmpty=function(){var t=c(e.$parent),n=null===t||void 0===t||""===t||angular.isArray(t)&&0===t.length;r.toggleClass("editable-empty",n)},f.autosubmit=angular.noop,f.onshow=angular.noop,f.onhide=angular.noop,f.oncancel=angular.noop,f.onbeforesave=angular.noop,f.onaftersave=angular.noop}return n.$inject=["$scope","$attrs","$element","$parse","editableThemes","editableOptions","$rootScope","$compile","$q"],n}]),angular.module("xeditable").factory("editableDirectiveFactory",["$parse","$compile","editableThemes","$rootScope","$document","editableController","editableFormController",function(e,t,n,r,a,o,i){return function(t){return{restrict:"A",scope:!0,require:[t.directiveName,"?^form"],controller:o,link:function(n,o,s,l){var u,c=l[0],d=!1;if(l[1])u=l[1],d=!0;else if(s.eForm){var f=e(s.eForm)(n);if(f)u=f,d=!0;else for(var m=0;m=0&&e.splice(n,1),t},camelToDash:function(e){var t=/[A-Z]/g;return e.replace(t,function(e,t){return(t?"-":"")+e.toLowerCase()})},dashToCamel:function(e){var t=/([\:\-\_]+(.))/g,n=/^moz([A-Z])/;return e.replace(t,function(e,t,n,r){return r?n.toUpperCase():n}).replace(n,"Moz$1")}}}]),angular.module("xeditable").factory("editableNgOptionsParser",[function(){function e(e){var n;if(!(n=e.match(t)))throw"ng-options parse error";var r,a=n[2]||n[1],o=n[4]||n[6],i=n[5],s=(n[3],n[2]?n[1]:o),l=n[7],u=n[8],c=u?n[8]:null;return void 0===i?(r=o+" in "+l,void 0!==u&&(r+=" track by "+c)):r="("+i+", "+o+") in "+l,{ngRepeat:r,locals:{valueName:o,keyName:i,valueFn:s,displayFn:a}}}var t=/^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+(.*?)(?:\s+track\s+by\s+(.*?))?$/;return e}]),angular.module("xeditable").factory("editableThemes",function(){return{default:{formTpl:'
    ',noformTpl:'',controlsTpl:'',inputTpl:"",errorTpl:'
    ',buttonsTpl:'',submitTpl:'',cancelTpl:''},bs2:{formTpl:'
    ',noformTpl:'',controlsTpl:'
    ',inputTpl:"",errorTpl:'
    ',buttonsTpl:'',submitTpl:'',cancelTpl:''},bs3:{formTpl:'
    ',noformTpl:'',controlsTpl:'
    ',inputTpl:"",errorTpl:'
    ', +buttonsTpl:'',submitTpl:'',cancelTpl:'',buttonsClass:"",inputClass:"",postrender:function(){switch(this.directiveName){case"editableText":case"editableSelect":case"editableTextarea":case"editableEmail":case"editableTel":case"editableNumber":case"editableUrl":case"editableSearch":case"editableDate":case"editableDatetime":case"editableTime":case"editableMonth":case"editableWeek":if(this.inputEl.addClass("form-control"),this.theme.inputClass){if(this.inputEl.attr("multiple")&&("input-sm"===this.theme.inputClass||"input-lg"===this.theme.inputClass))break;this.inputEl.addClass(this.theme.inputClass)}}this.buttonsEl&&this.theme.buttonsClass&&this.buttonsEl.find("button").addClass(this.theme.buttonsClass)}}}}),function(e,t,n){"use strict";function r(e){return F(e)?e:Object.keys(e).map(function(t){return e[t]})}function a(e){return null===e}function o(e,t){return-1==Object.keys(e).map(function(r){return t[r]!==n&&t[r]==e[r]}).indexOf(!1)}function i(e,t){if(""===t)return e;var n=e.indexOf(t.charAt(0));return-1!==n&&i(e.substr(n+1),t.substr(1))}function s(e,t,n){var r=0;return e.filter(function(e){var a=D(n)?t>r&&n(e):t>r;return r=a?r+1:r,a})}function l(e,t,n){return n.round(e*n.pow(10,t))/n.pow(10,t)}function u(e,t,n){return t=t||[],Object.keys(e).forEach(function(r){if(T(e[r])&&!F(e[r])){var a=n?n+"."+r:n;u(e[r],t,a||r)}else{var o=n?n+"."+r:r;t.push(o)}}),t}function c(e){return e&&e.$evalAsync&&e.$watch}function d(){return function(e,t){return e>t}}function f(){return function(e,t){return e>=t}}function m(){return function(e,t){return t>e}}function p(){return function(e,t){return t>=e}}function b(){return function(e,t){return e==t}}function h(){return function(e,t){return e!=t}}function v(){return function(e,t){return e===t}}function g(){return function(e,t){return e!==t}}function _(e){return function(t,n){return t=T(t)?r(t):t,!(!F(t)||E(n))&&t.some(function(t){return T(t)||j(n)?e(n)(t):t===n})}}function $(e,t){return t=t||0,t>=e.length?e:F(e[t])?$(e.slice(0,t).concat(e[t],e.slice(t+1)),t):$(e,t+1)}function w(e){return function(t,n){function a(e,t){return!E(t)&&e.some(function(e){return N(e,t)})}if(t=T(t)?r(t):t,!F(t))return t;var o=[],i=e(n);return t.filter(E(n)?function(e,t,n){return n.indexOf(e)===t}:function(e){var t=i(e);return!a(o,t)&&(o.push(t),!0)})}}function y(e,t,n){return t?e+n+y(e,--t,n):e}var D=t.isDefined,E=t.isUndefined,j=t.isFunction,C=t.isString,R=t.isNumber,T=t.isObject,F=t.isArray,x=t.forEach,A=t.extend,S=t.copy,N=t.equals;String.prototype.contains||(String.prototype.contains=function(){return-1!==String.prototype.indexOf.apply(this,arguments)}),t.module("a8m.angular",[]).filter("isUndefined",function(){return function(e){return t.isUndefined(e)}}).filter("isDefined",function(){return function(e){return t.isDefined(e)}}).filter("isFunction",function(){return function(e){return t.isFunction(e)}}).filter("isString",function(){return function(e){return t.isString(e)}}).filter("isNumber",function(){return function(e){return t.isNumber(e)}}).filter("isArray",function(){return function(e){return t.isArray(e)}}).filter("isObject",function(){return function(e){return t.isObject(e)}}).filter("isEqual",function(){return function(e,n){return t.equals(e,n)}}),t.module("a8m.conditions",[]).filter({isGreaterThan:d,">":d,isGreaterThanOrEqualTo:f,">=":f,isLessThan:m,"<":m,isLessThanOrEqualTo:p,"<=":p,isEqualTo:b,"==":b,isNotEqualTo:h,"!=":h,isIdenticalTo:v,"===":v,isNotIdenticalTo:g,"!==":g}),t.module("a8m.is-null",[]).filter("isNull",function(){return function(e){return a(e)}}),t.module("a8m.after-where",[]).filter("afterWhere",function(){return function(e,t){if(e=T(e)?r(e):e,!F(e)||E(t))return e;var n=e.map(function(e){return o(t,e)}).indexOf(!0);return e.slice(-1===n?0:n)}}),t.module("a8m.after",[]).filter("after",function(){return function(e,t){return e=T(e)?r(e):e,F(e)?e.slice(t):e}}),t.module("a8m.before-where",[]).filter("beforeWhere",function(){return function(e,t){if(e=T(e)?r(e):e,!F(e)||E(t))return e;var n=e.map(function(e){return o(t,e)}).indexOf(!0);return e.slice(0,-1===n?e.length:++n)}}),t.module("a8m.before",[]).filter("before",function(){return function(e,t){return e=T(e)?r(e):e,F(e)?e.slice(0,t?--t:t):e}}),t.module("a8m.concat",[]).filter("concat",[function(){return function(e,t){if(E(t))return e;if(F(e))return e.concat(T(t)?r(t):t);if(T(e)){return r(e).concat(T(t)?r(t):t)}return e}}]),t.module("a8m.contains",[]).filter({contains:["$parse",_],some:["$parse",_]}),t.module("a8m.count-by",[]).filter("countBy",["$parse",function(e){return function(t,n){var a,o={},i=e(n);return t=T(t)?r(t):t,!F(t)||E(n)?t:(t.forEach(function(e){a=i(e),o[a]||(o[a]=0),o[a]++}),o)}}]),t.module("a8m.defaults",[]).filter("defaults",["$parse",function(e){return function(t,n){if(t=T(t)?r(t):t,!F(t)||!T(n))return t;var a=u(n);return t.forEach(function(t){a.forEach(function(r){var a=e(r),o=a.assign;E(a(t))&&o(t,a(n))})}),t}}]),t.module("a8m.every",[]).filter("every",["$parse",function(e){return function(t,n){return t=T(t)?r(t):t,!(F(t)&&!E(n))||t.every(function(t){return T(t)||j(n)?e(n)(t):t===n})}}]),t.module("a8m.filter-by",[]).filter("filterBy",["$parse",function(e){return function(t,a,o){var i;return o=C(o)||R(o)?String(o).toLowerCase():n,t=T(t)?r(t):t,!F(t)||E(o)?t:t.filter(function(t){return a.some(function(n){if(~n.indexOf("+")){var r=n.replace(new RegExp("\\s","g"),"").split("+");i=r.reduce(function(n,r,a){return 1===a?e(n)(t)+" "+e(r)(t):n+" "+e(r)(t)})}else i=e(n)(t);return!(!C(i)&&!R(i))&&String(i).toLowerCase().contains(o)})})}}]),t.module("a8m.first",[]).filter("first",["$parse",function(e){return function(t){var a,o,i;return t=T(t)?r(t):t,F(t)?(i=Array.prototype.slice.call(arguments,1),a=R(i[0])?i[0]:1,o=R(i[0])?R(i[1])?n:i[1]:i[0],i.length?s(t,a,o?e(o):o):t[0]):t}}]),t.module("a8m.flatten",[]).filter("flatten",function(){return function(e,t){return t=t||!1,e=T(e)?r(e):e,F(e)?t?[].concat.apply([],e):$(e,0):e}}),t.module("a8m.fuzzy-by",[]).filter("fuzzyBy",["$parse",function(e){return function(t,n,a,o){var s,l,u=o||!1;return t=T(t)?r(t):t,!F(t)||E(n)||E(a)?t:(l=e(n),t.filter(function(e){return s=l(e),!!C(s)&&(s=u?s:s.toLowerCase(),a=u?a:a.toLowerCase(),!1!==i(s,a))}))}}]),t.module("a8m.fuzzy",[]).filter("fuzzy",function(){return function(e,t,n){function a(e,t){var n,r;return 0=0&&R(t)&&isFinite(t)?1024>t?l(t,n,e)+" B":1048576>t?l(t/1024,n,e)+" KB":1073741824>t?l(t/1048576,n,e)+" MB":l(t/1073741824,n,e)+" GB":"NaN"}}]),t.module("a8m.math.degrees",["a8m.math"]).filter("degrees",["$math",function(e){return function(t,n){if(R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)){var r=180*t/e.PI;return e.round(r*e.pow(10,n))/e.pow(10,n)}return"NaN"}}]),t.module("a8m.math.kbFmt",["a8m.math"]).filter("kbFmt",["$math",function(e){return function(t,n){return R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)?1024>t?l(t,n,e)+" KB":1048576>t?l(t/1024,n,e)+" MB":l(t/1048576,n,e)+" GB":"NaN"}}]),t.module("a8m.math",[]).factory("$math",["$window",function(e){return e.Math}]),t.module("a8m.math.max",["a8m.math"]).filter("max",["$math","$parse",function(e,t){function n(n,r){var a=n.map(function(e){return t(r)(e)});return a.indexOf(e.max.apply(e,a))}return function(t,r){return F(t)?E(r)?e.max.apply(e,t):t[n(t,r)]:t}}]),t.module("a8m.math.min",["a8m.math"]).filter("min",["$math","$parse",function(e,t){function n(n,r){var a=n.map(function(e){return t(r)(e)});return a.indexOf(e.min.apply(e,a))}return function(t,r){return F(t)?E(r)?e.min.apply(e,t):t[n(t,r)]:t}}]),t.module("a8m.math.percent",["a8m.math"]).filter("percent",["$math","$window",function(e,t){return function(n,r,a){var o=C(n)?t.Number(n):n;return r=r||100,a=a||!1,!R(o)||t.isNaN(o)?n:a?e.round(o/r*100):o/r*100}}]),t.module("a8m.math.radians",["a8m.math"]).filter("radians",["$math",function(e){return function(t,n){if(R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)){var r=3.14159265359*t/180;return e.round(r*e.pow(10,n))/e.pow(10,n)}return"NaN"}}]),t.module("a8m.math.radix",[]).filter("radix",function(){return function(e,t){var n=/^[2-9]$|^[1-2]\d$|^3[0-6]$/;return R(e)&&n.test(t)?e.toString(t).toUpperCase():e}}),t.module("a8m.math.shortFmt",["a8m.math"]).filter("shortFmt",["$math",function(e){return function(t,n){return R(n)&&isFinite(n)&&n%1==0&&n>=0&&R(t)&&isFinite(t)?1e3>t?t:1e6>t?l(t/1e3,n,e)+" K":1e9>t?l(t/1e6,n,e)+" M":l(t/1e9,n,e)+" B":"NaN"}}]),t.module("a8m.math.sum",[]).filter("sum",function(){return function(e,t){return F(e)?e.reduce(function(e,t){return e+t},t||0):e}}),t.module("a8m.ends-with",[]).filter("endsWith",function(){return function(e,t,n){var r,a=n||!1;return!C(e)||E(t)?e:(e=a?e:e.toLowerCase(),r=e.length-t.length,-1!==e.indexOf(a?t:t.toLowerCase(),r))}}),t.module("a8m.latinize",[]).filter("latinize",[function(){function e(e){return e.replace(/[^\u0000-\u007E]/g,function(e){return n[e]||e})}for(var t=[{base:"A",letters:"AⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ"},{base:"AA",letters:"Ꜳ"},{base:"AE",letters:"ÆǼǢ"},{base:"AO",letters:"Ꜵ"},{base:"AU",letters:"Ꜷ"},{base:"AV",letters:"ꜸꜺ"},{base:"AY",letters:"Ꜽ"},{base:"B",letters:"BⒷBḂḄḆɃƂƁ"},{base:"C",letters:"CⒸCĆĈĊČÇḈƇȻꜾ"},{base:"D",letters:"DⒹDḊĎḌḐḒḎĐƋƊƉꝹ"},{base:"DZ",letters:"DZDŽ"},{base:"Dz",letters:"DzDž"},{base:"E",letters:"EⒺEÈÉÊỀẾỄỂẼĒḔḖĔĖËẺĚȄȆẸỆȨḜĘḘḚƐƎ"},{base:"F",letters:"FⒻFḞƑꝻ"},{base:"G",letters:"GⒼGǴĜḠĞĠǦĢǤƓꞠꝽꝾ"},{base:"H",letters:"HⒽHĤḢḦȞḤḨḪĦⱧⱵꞍ"},{base:"I",letters:"IⒾIÌÍÎĨĪĬİÏḮỈǏȈȊỊĮḬƗ"},{base:"J",letters:"JⒿJĴɈ"},{base:"K",letters:"KⓀKḰǨḲĶḴƘⱩꝀꝂꝄꞢ"},{base:"L",letters:"LⓁLĿĹĽḶḸĻḼḺŁȽⱢⱠꝈꝆꞀ"},{base:"LJ",letters:"LJ"},{base:"Lj",letters:"Lj"},{base:"M",letters:"MⓂMḾṀṂⱮƜ"},{base:"N",letters:"NⓃNǸŃÑṄŇṆŅṊṈȠƝꞐꞤ"},{base:"NJ",letters:"NJ"},{base:"Nj",letters:"Nj"},{base:"O",letters:"OⓄOÒÓÔỒỐỖỔÕṌȬṎŌṐṒŎȮȰÖȪỎŐǑȌȎƠỜỚỠỞỢỌỘǪǬØǾƆƟꝊꝌ"},{base:"OI",letters:"Ƣ"},{base:"OO",letters:"Ꝏ"},{base:"OU",letters:"Ȣ"},{base:"OE",letters:"ŒŒ"},{base:"oe",letters:"œœ"},{base:"P",letters:"PⓅPṔṖƤⱣꝐꝒꝔ"},{base:"Q",letters:"QⓆQꝖꝘɊ"},{base:"R",letters:"RⓇRŔṘŘȐȒṚṜŖṞɌⱤꝚꞦꞂ"},{base:"S",letters:"SⓈSẞŚṤŜṠŠṦṢṨȘŞⱾꞨꞄ"},{base:"T",letters:"TⓉTṪŤṬȚŢṰṮŦƬƮȾꞆ"},{base:"TZ",letters:"Ꜩ"},{base:"U",letters:"UⓊUÙÚÛŨṸŪṺŬÜǛǗǕǙỦŮŰǓȔȖƯỪỨỮỬỰỤṲŲṶṴɄ"},{base:"V",letters:"VⓋVṼṾƲꝞɅ"},{base:"VY",letters:"Ꝡ"},{base:"W",letters:"WⓌWẀẂŴẆẄẈⱲ"},{base:"X",letters:"XⓍXẊẌ"},{base:"Y",letters:"YⓎYỲÝŶỸȲẎŸỶỴƳɎỾ"},{base:"Z",letters:"ZⓏZŹẐŻŽẒẔƵȤⱿⱫꝢ"},{base:"a",letters:"aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐ"},{base:"aa",letters:"ꜳ"},{base:"ae",letters:"æǽǣ"},{base:"ao",letters:"ꜵ"},{base:"au",letters:"ꜷ"},{base:"av",letters:"ꜹꜻ"},{base:"ay",letters:"ꜽ"},{base:"b",letters:"bⓑbḃḅḇƀƃɓ"},{base:"c",letters:"cⓒcćĉċčçḉƈȼꜿↄ"},{base:"d",letters:"dⓓdḋďḍḑḓḏđƌɖɗꝺ"},{base:"dz",letters:"dzdž"},{base:"e",letters:"eⓔeèéêềếễểẽēḕḗĕėëẻěȅȇẹệȩḝęḙḛɇɛǝ"},{base:"f",letters:"fⓕfḟƒꝼ"},{base:"g",letters:"gⓖgǵĝḡğġǧģǥɠꞡᵹꝿ"},{base:"h",letters:"hⓗhĥḣḧȟḥḩḫẖħⱨⱶɥ"},{base:"hv",letters:"ƕ"},{base:"i",letters:"iⓘiìíîĩīĭïḯỉǐȉȋịįḭɨı"},{base:"j",letters:"jⓙjĵǰɉ"},{base:"k",letters:"kⓚkḱǩḳķḵƙⱪꝁꝃꝅꞣ"},{base:"l",letters:"lⓛlŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇ"},{base:"lj",letters:"lj"},{base:"m",letters:"mⓜmḿṁṃɱɯ"},{base:"n",letters:"nⓝnǹńñṅňṇņṋṉƞɲʼnꞑꞥ"},{base:"nj",letters:"nj"},{base:"o",letters:"oⓞoòóôồốỗổõṍȭṏōṑṓŏȯȱöȫỏőǒȍȏơờớỡởợọộǫǭøǿɔꝋꝍɵ"},{base:"oi",letters:"ƣ"},{base:"ou",letters:"ȣ"},{base:"oo",letters:"ꝏ"},{base:"p",letters:"pⓟpṕṗƥᵽꝑꝓꝕ"},{base:"q",letters:"qⓠqɋꝗꝙ"},{base:"r",letters:"rⓡrŕṙřȑȓṛṝŗṟɍɽꝛꞧꞃ"},{base:"s",letters:"sⓢsßśṥŝṡšṧṣṩșşȿꞩꞅẛ"},{base:"t",letters:"tⓣtṫẗťṭțţṱṯŧƭʈⱦꞇ"},{base:"tz",letters:"ꜩ"},{base:"u",letters:"uⓤuùúûũṹūṻŭüǜǘǖǚủůűǔȕȗưừứữửựụṳųṷṵʉ"},{base:"v",letters:"vⓥvṽṿʋꝟʌ"},{base:"vy",letters:"ꝡ"},{base:"w",letters:"wⓦwẁẃŵẇẅẘẉⱳ"},{base:"x",letters:"xⓧxẋẍ"},{base:"y",letters:"yⓨyỳýŷỹȳẏÿỷẙỵƴɏỿ"},{base:"z",letters:"zⓩzźẑżžẓẕƶȥɀⱬꝣ"}],n={},r=0;r<]*>/g,""):e}}),t.module("a8m.test",[]).filter("test",function(){return function(e,t,n){var r=new RegExp(t,n);return C(e)?r.test(e):e}}),t.module("a8m.trim",[]).filter("trim",function(){return function(e,t){var n=t||"\\s";return C(e)?e.replace(new RegExp("^"+n+"+|"+n+"+$","g"),""):e}}),t.module("a8m.truncate",[]).filter("truncate",function(){return function(e,t,n,r){return t=E(t)?e.length:t,r=r||!1,n=n||"",!C(e)||e.length<=t?e:e.substring(0,r?-1===e.indexOf(" ",t)?e.length:e.indexOf(" ",t):t)+n}}),t.module("a8m.ucfirst",[]).filter("ucfirst",[function(){return function(e){return C(e)?e.split(" ").map(function(e){return e.charAt(0).toUpperCase()+e.substring(1)}).join(" "):e}}]),t.module("a8m.uri-component-encode",[]).filter("uriComponentEncode",["$window",function(e){return function(t){return C(t)?e.encodeURIComponent(t):t}}]),t.module("a8m.uri-encode",[]).filter("uriEncode",["$window",function(e){return function(t){return C(t)?e.encodeURI(t):t}}]),t.module("a8m.wrap",[]).filter("wrap",function(){return function(e,t,n){return C(e)&&D(t)?[t,e,n||t].join(""):e}}),t.module("a8m.filter-watcher",[]).provider("filterWatcher",function(){this.$get=["$window","$rootScope",function(e,n){function r(e,n){return[e,t.toJson(n)].join("#").replace(/"/g,"")}function a(e){var t=e.targetScope.$id;x(d[t],function(e){delete u[e]}),delete d[t]}function o(){f(function(){n.$$phase||(u={})})}function i(e,t){var n=e.$id;return E(d[n])&&(e.$on("$destroy",a),d[n]=[]),d[n].push(t)}function s(e,t){var n=r(e,t);return u[n]}function l(e,t,n,a){var s=r(e,t);return u[s]=a,c(n)?i(n,s):o(),a}var u={},d={},f=e.setTimeout;return{isMemoized:s,memoize:l}}]}),t.module("angular.filter",["a8m.ucfirst","a8m.uri-encode","a8m.uri-component-encode","a8m.slugify","a8m.latinize","a8m.strip-tags","a8m.stringular","a8m.truncate","a8m.starts-with","a8m.ends-with","a8m.wrap","a8m.trim","a8m.ltrim","a8m.rtrim","a8m.repeat","a8m.test","a8m.match","a8m.to-array","a8m.concat","a8m.contains","a8m.unique","a8m.is-empty","a8m.after","a8m.after-where","a8m.before","a8m.before-where","a8m.defaults","a8m.where","a8m.reverse","a8m.remove","a8m.remove-with","a8m.group-by","a8m.count-by","a8m.search-field","a8m.fuzzy-by","a8m.fuzzy","a8m.omit","a8m.pick","a8m.every","a8m.filter-by","a8m.xor","a8m.map","a8m.first","a8m.last","a8m.flatten","a8m.join","a8m.math","a8m.math.max","a8m.math.min","a8m.math.percent","a8m.math.radix","a8m.math.sum","a8m.math.degrees","a8m.math.radians","a8m.math.byteFmt","a8m.math.kbFmt","a8m.math.shortFmt","a8m.angular","a8m.conditions","a8m.is-null","a8m.filter-watcher"])}(window,window.angular),define("job-roles/modules/job-roles.core",["common/angular","common/ui-select","common/directives/angular-date/date-input","common/modules/directives","common/modules/routers/compu-ng-route","common/filters/angular-date/format-date","common/services/angular-date/date-format","common/services/crm-ang.service","common/services/dom-event-trigger","common/services/pub-sub","job-roles/vendor/angular-editable","job-roles/vendor/angular-filter"],function(e){"use strict";e.module("hrjobroles.core",["angular.filter","ngAnimate","ngSanitize","ngResource","ui.bootstrap","ui.select","xeditable","common.angularDate","common.directives","common.services","compuNgRoute"])}),define("job-roles/filters/get-active-values.filter",["common/lodash"],function(e){"use strict";function t(t){return t.debug("Filter: getActiveValues"),function(t){var n={};return e.each(t,function(e,t){"1"===e.is_active&&(n[t]=e)}),n}}return t.__name="getActiveValues",t.$inject=["$log"],t}),define("job-roles/modules/job-roles.filters",["common/angular","job-roles/filters/get-active-values.filter"],function(e,t){"use strict";return e.module("hrjobroles.filters",[]).filter(t.__name,t)}),define("job-roles/modules/job-roles.run",["common/angular"],function(e){"use strict";function t(e,t,n,r){n.theme="bs3",t.contactId=r.contactId,t.pathBaseUrl=r.pathBaseUrl,t.pathTpl=r.pathTpl,t.pathIncludeTpl=r.pathIncludeTpl,t.prefix=r.classNamePrefix}e.module("hrjobroles.run",["hrjobroles.constants"]).run(t),t.$inject=["$q","$rootScope","editableOptions","settings"]}),define("job-roles/services/date-validation.service",["common/moment"],function(e){function t(t){function n(e,t){e.isValid()||l("Date is not valid!!",t)}function r(e,t){e.isSameOrAfter(t)&&l("Start Date cannot be the same as or after the End Date.",["start_date","end_date"])}function a(e,t){e.isBefore(t)&&l("Start Date cannot be lower than Contract Start Date.",["start_date"])}function o(e,t){e.isAfter(t)&&l("Start Date cannot be higher than Contract End Date.",["start_date"])}function i(e,t){e.isAfter(t)&&l("End Date cannot be higher than Contract End Date.",["end_date"])}function s(t,n){return t instanceof Date&&(t=e(t).valueOf()),e(t,n,!0).startOf("day")}var l=function(e,t){throw new Error(e,t[0])},u={dateFormats:["x","YYYY-MM-DD"],setErrorCallback:function(e){if("function"!=typeof e)throw new TypeError("Error callback must be a function.");l=e},validate:function(e,t,l,u){e=s(e,this.dateFormats),l=s(l,this.dateFormats),u=s(u,this.dateFormats),n(e,["start_date"]),o(e,u),a(e,l),(0===t||t)&&(t=s(t,this.dateFormats),n(t,["end_date"]),i(t,u),r(e,t))}};return t.DATE_FORMAT&&u.dateFormats.push(t.DATE_FORMAT.toUpperCase()),u}return t.__name="dateValidation",t.$inject=["HR_settings"],t}),define("job-roles/services/filters.service",[],function(){"use strict";function e(){return{isNotUndefined:function(e){try{return e.constructor===Array?e.filter(function(e){return"undefined"!==e&&void 0!==e}):e}catch(t){return e}},issetCostCentre:function(e){try{return e.constructor===Array?e.filter(function(e){return""!==e.cost_centre_id&&("1"===e.type&&parseInt(e.percentage)>0||"0"===e.type&&parseInt(e.amount)>0)}):e}catch(t){return e}},issetFunder:function(e){try{return e.constructor===Array?e.filter(function(e){return""!==e.funder_id&&("1"===e.type&&parseInt(e.percentage)>0||"0"===e.type&&parseInt(e.amount)>0)}):e}catch(t){return e}}}}return e.__name="filtersService",e}),define("job-roles/services/job-role.service",["common/lodash"],function(e){"use strict";function t(t,n,r){function a(n){var r=n["api.HRJobContractRevision.get"].values;delete n["api.HRJobContractRevision.get"],n.revisions=e.compact(r.map(function(e){var r=e["api.HRJobDetails.getsingle"];return r.period_start_date===n.period_start_date&&r.period_end_date===n.period_end_date?null:(r.period_start_date=t("formatDate")(r.period_start_date),r.period_end_date=t("formatDate")(r.period_end_date),r)}))}return{getContracts:function(e){var t=r.defer();return CRM.api3("HRJobContract","get",{sequential:1,contact_id:e,deleted:0,return:"title,period_end_date,period_start_date","api.HRJobContractRevision.get":{jobcontract_id:"$value.id","api.HRJobDetails.getsingle":{jobcontract_revision_id:"$value.id"}}}).done(function(e){e.values.forEach(a),t.resolve(e)}).error(function(){t.reject("An error occured while fetching items")}),t.promise},getAllJobRoles:function(e){var t=r.defer();return CRM.api3("HrJobRoles","get",{sequential:1,return:"id,job_contract_id,title,description,status,funder,funder_val_type,percent_pay_funder,amount_pay_funder,cost_center,cost_center_val_type,percent_pay_cost_center,amount_pay_cost_center,level_type,location,region,department,end_date,start_date",job_contract_id:{IN:e}}).done(function(e){t.resolve(e)}).error(function(e){t.reject("An error occured while fetching items")}),t.promise},deleteJobRole:function(e){var t=r.defer();return CRM.api3("HrJobRoles","delete",{sequential:1,id:e}).done(function(e){t.resolve(e)}).error(function(e){t.reject("An error occured while deleting items")}),t.promise},createJobRole:function(e){var t="|",n="|",a="|",o="|",i="|",s="|",l="|",u="|";if(void 0!==e.funders)for(var c=0,d=e.funders.length;c - + @@ -123,7 +123,7 @@ - + @@ -145,7 +145,7 @@ - + @@ -167,7 +167,7 @@ - + diff --git a/com.civicrm.hrjobroles/views/include/job_role_panel.html b/com.civicrm.hrjobroles/views/include/job_role_panel.html index 8e8f582f2c3..0ed4738f9e3 100755 --- a/com.civicrm.hrjobroles/views/include/job_role_panel.html +++ b/com.civicrm.hrjobroles/views/include/job_role_panel.html @@ -173,7 +173,7 @@ - + @@ -203,7 +203,7 @@ - + @@ -233,7 +233,7 @@ - + @@ -263,7 +263,7 @@ - + From 341d751ae580a33c4ef470cb1090bc33ad3d3574 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Thu, 19 Apr 2018 17:39:12 +0100 Subject: [PATCH 149/203] PCHR-3162: Add missing upgraders to upgradeBundle function --- hrjobcontract/CRM/Hrjobcontract/Upgrader.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php index 1ddc054ede4..a858562a875 100755 --- a/hrjobcontract/CRM/Hrjobcontract/Upgrader.php +++ b/hrjobcontract/CRM/Hrjobcontract/Upgrader.php @@ -512,6 +512,8 @@ public function upgradeBundle() { $this->upgrade_1030(); $this->upgrade_1032(); $this->upgrade_1033(); + $this->upgrade_1034(); + $this->upgrade_1035(); $this->upgrade_1036(); } From 93d1b000f4c470916e6297c265355eee2234b527 Mon Sep 17 00:00:00 2001 From: Alessandro Verdura Date: Mon, 23 Apr 2018 17:31:01 +0200 Subject: [PATCH 150/203] PCHR-3592: Add slack notifications to jenkinsfile --- Jenkinsfile | 69 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 31be1839ff0..61cc6457c07 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -23,7 +23,7 @@ pipeline { stages { stage('Pre-tasks execution') { steps { - sendBuildStartdNotification() + sendBuildStartNotification() // Print all Environment variables sh 'printenv | sort' @@ -189,26 +189,34 @@ pipeline { /* * Sends a notification when the build starts */ -def sendBuildStartdNotification() { - def message = 'Building ' + getBuildTargetLink() + '. ' + getReportLink() +def sendBuildStartNotification() { + def msgHipChat = 'Building ' + getBuildTargetLink('hipchat') + '. ' + getReportLink('hipchat') + def msgSlack = 'Building ' + getBuildTargetLink('slack') + '. ' + getReportLink('slack') - sendHipchatNotification('YELLOW', message) + sendHipchatNotification('YELLOW', msgHipChat) + sendSlackNotification('warning', msgSlack) } /* * Sends a notification when the build is completed successfully */ def sendBuildSuccessNotification() { - def message = getBuildTargetLink() + ' built successfully. Time: $BUILD_DURATION. ' + getReportLink() - sendHipchatNotification('GREEN', message) + def msgHipChat = getBuildTargetLink('hipchat') + ' built successfully. Time: $BUILD_DURATION. ' + getReportLink('hipchat') + def msgSlack = getBuildTargetLink('slack') + ' built successfully. Time: ' + getBuildDuration(currentBuild) + '. ' + getReportLink('slack') + + sendHipchatNotification('GREEN', msgHipChat) + sendSlackNotification('good', msgSlack) } /* * Sends a notification when the build fails */ def sendBuildFailureNotification() { - def message = 'Failed to build ' + getBuildTargetLink() + '. Time: $BUILD_DURATION. No. of failed tests: ${TEST_COUNTS,var=\"fail\"}. ' + getReportLink() - sendHipchatNotification('RED', message) + def msgHipChat = 'Failed to build ' + getBuildTargetLink('hipchat') + '. Time: $BUILD_DURATION. No. of failed tests: ${TEST_COUNTS,var=\"fail\"}. ' + getReportLink('hipchat') + def msgSlack = 'Failed to build ' + getBuildTargetLink('slack') + '. Time: ' + getBuildDuration(currentBuild) + '. ' + getReportLink('slack') + + sendHipchatNotification('RED', msgHipChat) + sendSlackNotification('danger', msgSlack) } /* @@ -218,16 +226,38 @@ def sendHipchatNotification(String color, String message) { hipchatSend color: color, message: message, notify: true } +/* + * Sends a notification to Slack + */ +def sendSlackNotification(String color, String message) { + slackSend color: color, message: message, notify: true +} + +/* + * Returns the build duration without the "and counting" suffix + */ +def getBuildDuration(build) { + return build.durationString.replace(' and counting', '') +} + /* * Returns a link to what is being built. If it's a PR, then it's a link to the pull request itself. * If it's a branch, then it's a link in the format http://github.com/org/repo/tree/branch */ -def getBuildTargetLink() { - if(buildIsForAPullRequest()) { - return "\"${env.CHANGE_TITLE}\"" +def getBuildTargetLink(String client) { + def link = '' + def forPR = buildIsForAPullRequest() + + switch (client) { + case 'hipchat': + link = forPR ? "\"${env.CHANGE_TITLE}\"" : '"' + env.BRANCH_NAME + '"' + break; + case 'slack': + link = forPR ? "<${env.CHANGE_URL}|${env.CHANGE_TITLE}>" : '<' + getRepositoryUrlForBuildBranch() + '|' + env.BRANCH_NAME + '>' + break; } - return '"' + env.BRANCH_NAME + '"' + return link } /* @@ -250,8 +280,19 @@ def getRepositoryUrlForBuildBranch() { /* * Returns the Blue Ocean build report URL for the current job */ -def getReportLink() { - return 'Click here to see the build report' +def getReportLink(String client) { + def link = '' + + switch (client) { + case 'hipchat': + link = 'Click here to see the build report' + break + case 'slack': + link = "Click <${env.RUN_DISPLAY_URL}|here> to see the build report" + break + } + + return link } def cloneCiviHRRepositories(String envBranch) { From 9f2524f2bb90911e70b867969d86c0f3659bff5b Mon Sep 17 00:00:00 2001 From: Samson Alajede Date: Tue, 24 Apr 2018 11:37:25 +0100 Subject: [PATCH 151/203] PCHR-3461: Add tool icon to edit leave options --- .../js/angular/dist/absence-tab.min.js | 8 ++-- .../js/angular/dist/admin-dashboard.min.js | 6 +-- .../js/angular/dist/manager-leave.min.js | 10 ++--- .../js/angular/dist/my-leave.min.js | 2 +- ...tab-custom-work-pattern-modal.component.js | 22 ++++++++--- ...quest-modal-details-sickness.controller.js | 23 ++++++++--- ...ustom-work-pattern-modal.component.spec.js | 29 ++++++++++++-- ...-modal-details-sickness.controller.spec.js | 38 +++++++++++++++++-- .../Form/WorkPattern/Calendar.tpl | 21 +++++++++- ...absence-tab-custom-work-pattern-modal.html | 5 ++- .../details-tab/sickness.html | 5 ++- 11 files changed, 137 insertions(+), 32 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js index a5ba013375b..2e0ec4dde34 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js @@ -1,5 +1,5 @@ -!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,o){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:t(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,o,s,i){return t.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return s.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,o,s){return t.debug("WorkPatternAPI.getCalendar",n,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,o){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,o,s,i){function r(t,n){return u().then(function(a){var o=this.days[c(t).valueOf()];return!!o&&e.find(a,function(e){return e.name===n}).value===o.type}.bind(this))}function c(e){return t(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[c(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,o){return t.debug("Calendar"),n.extend({get:function(n,s,i,r){return t.debug("Calendar.get"),a.getCalendar(n,s,i,r).then(function(t){var a=t.values.map(function(e){return o.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function o(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,o,s){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return o.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",t,n,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t,n,o,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var i=a.defer();t&&n||i.reject("contact_id and period_id are mandatory");var r={contact_id:t,period_id:n,statuses:o?{IN:o}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",r,!1).then(function(e){i.resolve(e.values)}),i.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?o.reject(t(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(t){return s.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,o&&(i.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return r.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),n.all(t)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(s.permissions.admin.administer).then(function(t){return t?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,o,s,i){return n.all(this.processFilters(e),t,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,o){return n.balanceChangeByAbsenceType(e,t,a,o)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/instances/work-pattern.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("WorkPatternInstance",["$log","ModelInstance",function(e,t){return e.debug("WorkPatternInstance"),t.extend({})}])}),define("leave-absences/shared/models/work-pattern.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/work-pattern.instance"],function(e,t){"use strict";t.factory("WorkPattern",["$log","Model","WorkPatternAPI","WorkPatternInstance",function(t,n,a,o){return t.debug("WorkPattern"),n.extend({assignWorkPattern:function(e,t,n,o,s,i){return a.assignWorkPattern(e,t,n,o,s,i)},default:function(){return a.get({is_default:!0}).then(function(t){return o.init(e.first(t),!0)})},unassignWorkPattern:function(e){return a.unassignWorkPattern(e)},workPatternsOf:function(e,t,n){return a.workPatternsOf(e,t,n).then(function(e){return e.map(function(e){return o.init(e,!0)})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function u(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?c():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return o.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):i.all()}function m(e){return"me"===e?o.leaveManagees(v.contactId):"unassigned"===e?o.leaveManagees(void 0,{unassigned:!0}):o.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){r.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,u()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:i.contactId}).leaveManagees().then(function(e){i.lookupContacts=e}).then(o)}}}function o(){return t.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:i.filters.userSettings.department?i.filters.userSettings.department.value:null,level_type:i.filters.userSettings.level_type?i.filters.userSettings.level_type.value:null,location:i.filters.userSettings.location?i.filters.userSettings.location.value:null,region:i.filters.userSettings.region?i.filters.userSettings.region.value:null,id:{IN:i.filters.userSettings.contact?[i.filters.userSettings.contact.id]:i.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var i;return{init:function(e){return i=e,i.showContactName=!0,i.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function o(a,o,s,i,r,c,u,l,d,m){function f(){for(var e=[],t=n(M.selectedPeriod.start_date).clone().startOf("month"),a=n(M.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(A(t)),t.add(1,"month");M.months=e}function p(){i.$new().$watch(function(){return M.selectedMonths},function(t,n){null===n||e.equals(t,n)||I()})}function h(e){M.injectMonths=!0,S("injected").then(function(){I(e)}).then(function(){M.loading.calendar=!1})}function v(){k=a("LeaveCalendar"+t.capitalize(L)+"Controller").init(M)}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function g(){return c.all().then(function(e){M.absencePeriods=t.sortBy(e,"start_date"),M.selectedPeriod=t.find(M.absencePeriods,function(e){return!!e.current})}).then(f).then(w)}function _(){return u.all().then(u.loadCalculationUnits)}function y(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return k.loadContacts().then(function(e){M.contacts=e})}function C(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){M.filters.optionValues.regions=e.hrjc_region,M.filters.optionValues.locations=e.hrjc_location,M.filters.optionValues.levelTypes=e.hrjc_level_type,M.filters.optionValues.departments=e.hrjc_department})}function D(){return l.all()}function T(){return o.all([_(),D(),y()]).then(function(e){M.supportData.absenceTypes=e[0],M.supportData.publicHolidays=e[1],M.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,M.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,M.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,M.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function P(){var e=o.resolve();return M.injectMonths&&(e=S("destroyed"),M.injectMonths=!1),e}function A(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function R(e){e=t.includes(["contacts","period"],e)?e:"period",o.resolve().then(function(){M.loading.calendar=!0}).then(P).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function I(e){var n=M.selectedMonths.length?M.months.filter(function(e){return t.includes(M.selectedMonths,e.index)}):M.months;i.$emit("LeaveCalendar::showMonths",n,!!e)}function w(){M.selectedMonths=[n().month()]}function O(){return M.roleOverride?o.resolve().then(function(){L=M.roleOverride}):o.all([m(r.permissions.admin.administer),m(r.permissions.ssp.manage)]).then(function(e){L=e[0]?"admin":e[1]?"manager":"staff"})}function S(e){return o(function(n){var a=0,o=i.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===M.months.length&&(o(),n())})})}s.debug("Component: leave-calendar");var k,L,M=this;M.absencePeriods=[],M.contacts=[],M.contactIdsToReduceTo=null,M.injectMonths=!1,M.months=[],M.selectedMonths=null,M.selectedPeriod=null,M.showContactName=!1,M.showFilters=!1,M.supportData={},M.loading={calendar:!0,page:!0},M.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},M.labelPeriod=b,M.refresh=R,function(){O().then(p).then(v).then(P).then(g).then(function(){return o.all([q(),T()])}).then(function(){return M.showFilters?C():t.noop}).then(function(){h()}).then(function(){M.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",o]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,o){"use strict";function s(){y.calculationUnit=i(y.supportData.calculationUnits,"value",b.calculation_unit)}function i(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function r(){var e,n;return n=t(y.contactData.leaveRequest.from_date).isSame(y.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+y.calculationUnit.name+"-on-"+e+"-tooltip"}function c(){b=i(y.supportData.absenceTypes,"id",y.contactData.leaveRequest.type_id),y.contactData.leaveRequest["type_id.title"]=b.title}function u(){"days"===y.calculationUnit.name&&(g=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.from_date_type),_=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.to_date_type),y.contactData.leaveRequest["from_date_type.label"]=g.label,y.contactData.leaveRequest["to_date_type.label"]=_.label)}function l(e,t,n,a,s){e.stopPropagation(),o.openModal(t,n,a,s)}function d(){y.dates.from=new Date(y.contactData.leaveRequest.from_date),y.dates.to=new Date(y.contactData.leaveRequest.to_date)}function m(){y.contactData.isAccruedTOIL?y.label="AT":"days"===y.calculationUnit.name?f():p()}function f(){y.label=y.contactData.isAM?"AM":y.contactData.isPM?"PM":""}function p(){var e=t(y.contactData.leaveRequest.from_date).isSame(y.date,"day"),n=t(y.contactData.leaveRequest.to_date).isSame(y.date,"day");y.label=e?t(y.contactData.leaveRequest.from_date).format("HH:mm"):n?t(y.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){y.tooltipTemplate=y.contactData.isAccruedTOIL?"accrued-toil-tooltip":r()}function v(){a.$watch("day.contactData.leaveRequest",function(){y.contactData&&y.contactData.leaveRequest&&(c(),s(),u(),m(),d(),h()) -})}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(e){_([e]),U(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return j[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){k(e),U(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=P(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){F.push(o.$on("LeaveCalendar::showMonths",$)),F.push(r.subscribe("LeaveRequest::new",u)),F.push(r.subscribe("LeaveRequest::edit",B)),F.push(r.subscribe("LeaveRequest::updatedByManager",B)),F.push(r.subscribe("LeaveRequest::delete",h)),F.push(r.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function D(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function T(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function P(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function A(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function R(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function I(){return[R(c.statusNames.approved),R(c.statusNames.adminApproved),R(c.statusNames.awaitingApproval),R(c.statusNames.moreInformationRequired)]}function w(){return H.month.loading=!0,a.all([S(),O()]).then(b).then(x).then(function(){N=!0}).then(function(){H.month.loading=!1})}function O(){return i.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:I()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function S(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){j=e.indexBy(t,"contact_id")})}function k(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function L(){o.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function M(t,n,o){var s,i;return t.contactsData[n]=t.contactsData[n]||{},i=m(n),s=!0===o?a.resolve():a.all([i.isWeekend(p(t.date)),i.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:D(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?T(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function x(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return M(e,t.id)}))}))}function $(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!N)&&w())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=A(e);t&&(h(t),-1!==I().indexOf(e.status_id)&&u(e))}function U(e){return a.all(P(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],j={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=L,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,i,r,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(i.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=D[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&r.publish("ManagerBadge:: Update Count"),r.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(D,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:D[e].label,isDirectAction:D[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,D={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return r.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,c.serverDateFormat).toDate()}function h(e){return t(e).format(c.serverDateFormat)}function v(e){var t;return i.resolve().then(function(){F(e),"from"===e&&N(),S("hours")&&(_(e),"from"!==e||te.uiOptions.multipleDays||_("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return i.reject("Please change date as it is not in any absence period")}).then(W).then(function(){if(t)return x()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(V(),!t)return E();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(P).finally(y)}function b(){return V(),E()}function g(){return te.uiOptions.toDate=null,F("to"),i.resolve().then(V).then(te.setDaysSelectionModeExtended).then(y).then(!te.uiOptions.multipleDays&&E)}function _(e){te.uiOptions.times[e].loading=!0}function y(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,S("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function C(){return te.request?te.request.request_type:te.leaveType||null}function D(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(j).catch(P)}function P(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function A(){return te.isMode("create")||te.forceRecalculateBalanceChange?E():T()}function R(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():i.resolve()}function I(){ee.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){Q()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){J(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",E))}function w(){te.isMode("edit")&&(te.isLeaveStatus(c.statusNames.approved)||te.isLeaveStatus(c.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function O(){o.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(K(e),V()))})}function S(e){return te.selectedAbsenceType.calculation_unit_name===e}function k(e){return te.request.request_type===e}function L(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function M(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function x(){return u.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function $(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function E(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(j).catch(P).finally(function(){te.loading.balanceChange=!1})):i.resolve()}function B(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function U(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),V(),z()}function j(e){te.balance.change=e,te.request.balance_change=e.amount,f(),B(),te.loading.balanceChange=!1}function W(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function H(){return!te.isMode("create")&&U()||te.isMode("create")&&(k("sickness")||S("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,i.resolve().then(te.setDaysSelectionModeExtended)}function G(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function Y(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function V(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(S("hours")||k("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function X(){e.forEach(ee,function(e){e()})}function Q(){var e,t=te.selectedAbsenceType.calculation_unit_name;return Y(),e=t!==te.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&H).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&V).then(y).then(E)}function J(e){return te.absenceTypes=e,Y(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),G(),E()}function K(e){var t=D(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(D(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(D(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=c.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:$},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:r.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=b,te.daysSelectionModeChangeHandler=g,te.disableAndShowLoadingTimeInput=_,te.getMomentDateWithGivenTime=D,te.handleError=P,te.isCalculationUnit=S,te.isLeaveType=k,te.isNotWorkingDay=L,te.performBalanceChangeCalculation=E,te.setRequestDateTimesAndDateTypes=V,te.updateEndTimeInputMinTime=K,te.$onDestroy=X,function(){n("RequestModalDetails"+e.capitalize(C(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",te),I(),te.initChildController().then(function(){return i.all([x(),M()])}).then(!te.isMode("create")&&R).then(H).then(function(){if(!te.isMode("create"))return i.resolve().then(te.initTimesExtended).then(V)}).then(!te.isMode("create")&&W).then(w).then(G).then(A).then(O).then(!te.isMode("view")&&te.initWatchersExtended).catch(P).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l){function d(){return O.fileUploader&&O.fileUploader.queue.length>0}function m(){return O.getFilesAmount()0?R.map(function(e){return e.label}).join(", "):""}function q(){return O.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(R.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){w[e.label]=t})})).catch(function(){w=null})}function D(){return c.valuesOf("safe_file_extension").then(function(e){R=e})}function T(e){return!e.attachment_id||O.canManage}function P(){e.forEach(I,function(e){e()})}function A(e,t){O.fileUploader.queue&&O.fileUploader.queue.length>0?O.fileUploader.uploadAll({entityID:O.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var R=[],I=[],w={},O=Object.create(this);return O.filesLoaded=!1,O.fileUploader=null,O.today=Date.now(),O.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",O.userDateFormat=i.DATE_FORMAT,O.$onDestroy=P,O.canRemoveAttachment=T,O.canSubmit=d,O.canUploadMore=m,O.formatDateTime=f,O.getAuthorName=p,O.getFilesAmount=h,O.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",O),g(),a.all([D(),q()]).then(_).finally(function(){O.filesLoaded=!0})}(),O}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,o){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],s.openLeavePopup=a,function(){o=n.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,o,s,i,r,c,u,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var t=j[e.status];t?t(e.leaveRequest):W.refresh()}function b(t){t.dataIndex=e.indexBy(t.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return i.all().then(i.loadCalculationUnits).then(function(t){W.absenceTypes=t,W.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return R("approved",{status_id:F(m.statusNames.approved)})}function C(){return n.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function D(){return r.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(t){var n=e.find(W.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function T(){return r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return M(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function P(){return n.all([r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),A({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:M(e[0]),expiredTOILS:x(e[1].list)})}).then(function(t){W.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function A(t){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function R(e,t){return A(t).then(function(t){W.sections[e].data=t.list})}function I(){return n.all(Object.values(W.sections).filter(function(e){return e.open}).map(k))}function w(){return R("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function O(){return R("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function S(){return R("holidays",{public_holiday:!0})}function k(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function L(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){W.leaveRequestStatuses=e.indexBy(t,"value")})}function M(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(W.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function x(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function $(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(W.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],B(t,a))})}function B(e,t){var n=W.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function U(){W.loading.content=!0,n.all([D(),C()]).then(function(){W.loading.content=!1}).then(function(){return n.all([I(),h()])})}function N(e){var t=W.sections[e];t.open=!t.open,t.open&&!t.data.length&&k(t)}function F(t){return e.find(W.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var j={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:T},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:P},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w}},W.labelPeriod=g,W.refresh=U,W.toggleSection=N,function(){n.all([L(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return n.all([D(),C()])}).then(function(){W.loading.content=!1}),$()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report", -controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function u(){var e=i.request,t=!!e.from_date&&!!e.to_date,n=i.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return i.canCalculateChange()}function d(t,n){var a=i.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);i.uiOptions.multipleDays||("from"===t&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=i.convertDateToServerFormat(t),r.isPublicHoliday(t).then(function(n){return n?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,i.requestDayTypes).then(function(t){return t.length?t:i.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return A(n,e),e})):o.reject([])}function f(e,n){return e=t(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return o.resolve()}function v(){return C(i.uiOptions.fromDate,"from").then(function(){return C(i.uiOptions.toDate,"to")})}function b(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,t){i.isCalculationUnit("days")||+e==+t||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function g(e){var n=t(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),i.uiOptions.times[e].time=n}function _(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],t=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(T)).then(function(){["from","to"].forEach(function(e){g(e),I(e),t[e].amount=Math.min(i.request[e+"_date_amount"],t[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function y(){["from","to"].forEach(function(e){b(e),q(e)})}function q(e){s.$watch(function(){return i.uiOptions.times[e].time},function(t,n){i.isCalculationUnit("days")||t===n||(i.setRequestDateTimesAndDateTypes(),t&&I(e,!0))})}function C(e,t){return m(e,t).then(function(){i.loading[t+"DayTypes"]=!1})}function D(e){return C(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return T(e).then(function(){I(e,!0)})})}function T(e){var t=i.uiOptions[e+"Date"],n=!i.uiOptions.multipleDays;return t?i.request.getWorkDayForDate(i.convertDateToServerFormat(t)).then(function(t){S[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return S[e]={},i.handleError(t)}).finally(function(){n&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(t){var n=i.uiOptions.times[t];i["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function A(t,n){var a="request"+e.startCase(t)+"DayTypes";i[a]=n,i.isMode("create")&&(i.request[t+"_date_type"]=i[a][0].value)}function R(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),T("from").then(function(){I("from",!0)})):o.resolve()}function I(e,t){var n=i.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,c=S[a].number_of_hours?p(s,r).toString():"0";o.maxAmount=c,t&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function O(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?T("from").then(function(){I("from",!0)}):o.resolve()}var S={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=c,i.canCalculateChange=u,i.canSubmit=l,i.initChildController=h,i.initDayTypesExtended=v,i.initTimesExtended=_,i.initWatchersExtended=y,i.onAbsenceTypeUpdateExtended=O,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=R}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s){function i(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function r(){return a.all([l(),d()])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function d(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=i,s.initChildController=r,s.isChecked=c,s.isDocumentInRequest=u}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=t.duration(t(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,t=!c.uiOptions.multipleDays&&!!c.request.from_date,n=t||e,a=F.from_date!==c.request.from_date||F.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&n&&W.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,t=c.request;return b({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function b(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&W.hasExpirationFromAdminSettings,t=W.hasPreviousExpirationDate,n=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=n&&(a||e||t)}function _(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function y(){return W.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){W.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",y().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function D(){o.$watch(function(){return c.request.toil_to_accrue},function(e,t){+e!=+t&&c.performBalanceChangeCalculation()})}function T(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&c.isCalculationUnit("hours")&&k(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function P(){var e=c.uiOptions.times;e.from.time=t(c.request.from_date).format("HH:mm"),e.to.time=t(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function A(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,t){e!==t&&(c.setRequestDateTimesAndDateTypes(),U(),l(),L())})})}function R(){c.isMode("view")||(D(),T(),A())}function I(t){return i.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){c.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function w(){return l(),L(),U()}function O(){return x(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),j?j=!1:L(),U()}function S(e){c.uiOptions.times[e].time=""}function k(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function L(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function M(){F=e.cloneDeep(c.request.attributes())}function x(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function $(){c.setRequestDateTimesAndDateTypes(),l(),L(),c.isCalculationUnit("hours")?k():c.request.toil_to_accrue=null}function E(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){I(!1)})}function B(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function U(){return f()?d().catch(a.resolve):a.resolve()}function N(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var F,j=!c.isMode("create"),W={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=P,c.initWatchersExtended=R,c.onAbsenceTypeUpdateExtended=$,c.onDateChangeExtended=w,c.openToilInDaysAccrualOptionsEditor=E,c.resetUIInputsExtended=S,c.setDaysSelectionModeExtended=O,c.updateExpiryDate=N,function(){M(),x(),B(),!c.isMode("create")&&_()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,D){function T(e){"days"===xe.selectedAbsenceType.calculation_unit_name?delete xe.request[e+"_date_amount"]:delete xe.request[e+"_date_type"]}function P(){["from","to"].forEach(T)}function A(){var e=xe.requestStatuses[y.statusNames.awaitingApproval].value;we.status_id===e&&e!==xe.request.status_id&&d.publish("ManagerBadge:: Update Count")}function R(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!xe.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function O(){var e=R();return xe.isMode("edit")&&(e=e&&(G()||I())),xe.canManage&&xe.requestStatuses&&(e=e&&!!xe.getStatusFromValue(xe.newStatusOnSave)),(e=e&&!!xe.period.id)&&!xe.isMode("view")}function S(){xe.isSelfRecord?xe.request.status_id=xe.requestStatuses[y.statusNames.awaitingApproval].value:xe.canManage&&(xe.request.status_id=xe.newStatusOnSave||xe.request.status_id)}function k(){if(xe.isMode("edit")&&!xe.isRole("staff")&&"toil"!==F())return xe.request.calculateBalanceChange(xe.selectedAbsenceType.calculation_unit_name).then(function(e){if(+xe.balance.change.amount!=+e.amount)return D.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function L(){xe.errors=[]}function M(){return xe.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function x(){ee()&&!xe.isRole("staff")&&(xe.request.change_balance=!0)}function $(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return xe.request.delete().then(function(){xe.dismissModal(),d.publish("LeaveRequest::delete",xe.request)})}})}function E(){r.dismiss({$value:"cancel"})}function B(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return N(xe.getStatusFromValue(xe.request.status_id).name)}function N(e){return n.map(Re[e],function(e){return xe.requestStatuses[e]})}function F(){return xe.request?xe.request.request_type:xe.leaveType||null}function j(){return!xe.request||e.equals({},xe.requestStatuses)?[]:xe.request.status_id?U():N("none")}function W(e){return n.find(xe.requestStatuses,function(t){return t.value===e})}function H(e){xe.errors=n.isArray(e)?e:[e],xe.loading.absenceTypes=!1,xe.submitting=!1}function G(){return!e.equals(we,xe.request.attributes())||xe.canManage&&xe.newStatusOnSave}function Y(){return xe.postContactSelection=!0,xe.staffMemberSelectionComplete=!1,xe.request.contact_id?o.resolve().then(re).then(ce).then(he).then(be).then(Z).then(z).then(xe.isMode("edit")?ge:n.noop).then(function(){xe.postContactSelection=!1,xe.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==ke)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Re.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Re.awaiting_approval=e,Re.more_information_required=e,Re.rejected=e,Re.approved=e,Re.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return xe.canManage?f.find(xe.request.contact_id).then(function(e){xe.contactName=e.display_name}):o.resolve()}function X(){Oe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",xe.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Ie++})),i.$on("$destroy",De),i.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function Q(){var e,t;xe.request=xe.leaveRequest||null,e=F(),t=xe.initRequestAttributes(),"leave"===e?xe.request=_.init(t):"sickness"===e?xe.request=q.init(t):"toil"===e&&(xe.request=C.init(t))}function J(){var e={};return xe.request?e=xe.request.attributes():xe.canManage||(e={contact_id:Se}),e}function K(){if(Le="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(Le="admin")}).then(function(){return"staff"===Le&&c(y.permissions.ssp.manage).then(function(e){e&&(Le="manager")})}).finally(function(){xe.canManage=xe.isRole("manager")||xe.isRole("admin")})}function Z(){(xe.isRole("admin")||xe.isMode("create")&&xe.isRole("manager"))&&(xe.newStatusOnSave=xe.requestStatuses[y.statusNames.approved].value)}function ee(){return!xe.request.status_id||!n.includes(["cancelled","rejected"],W(xe.request.status_id).name)}function te(e){var t=xe.getStatusFromValue(xe.request.status_id);return!!t&&t.name===e}function ne(e){return xe.request&&xe.request.request_type===e}function ae(e){return xe.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return Le===e}function ie(){return h.all().then(function(e){xe.absencePeriods=e})}function re(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Ae={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return xe.loading.entitlements=!0,b.all({contact_id:xe.request.contact_id,period_id:xe.period.id,type_id:{IN:Ae.ids}},!0).finally(function(){xe.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Se=e.contactId})}function le(){return xe.selectedContactId?f.find(xe.selectedContactId).then(function(e){xe.managedContacts=[e]}):xe.isRole("admin")?f.all().then(function(e){xe.managedContacts=n.remove(e.list,function(e){return e.id!==Se})}):f.find(Se).then(function(e){return e.leaveManagees()}).then(function(e){xe.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){xe.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){A(),d.publish(e,xe.request),xe.errors=[],xe.dismissModal()}function pe(){["from","to"].forEach(function(e){xe.request[e+"_date"]=we[e+"_date"]})}function he(e){if(xe.absenceTypes=me(Ae.types,e),!xe.absenceTypes.length)return o.reject(ke)}function ve(){xe.period=n.find(xe.absencePeriods,function(e){return xe.isMode("create")?e.current:oe(xe.request,e)})}function be(){xe.isMode("create")?(xe.selectedAbsenceType=xe.absenceTypes[0],xe.request.type_id=xe.selectedAbsenceType.id):xe.selectedAbsenceType=n.find(xe.absenceTypes,function(e){return e.id===xe.request.type_id})}function ge(){we=e.copy(xe.request.attributes())}function _e(){var e;xe.request.id?(e=[xe.requestStatuses[y.statusNames.approved].value,xe.requestStatuses[y.statusNames.adminApproved].value,xe.requestStatuses[y.statusNames.rejected].value,xe.requestStatuses[y.statusNames.cancelled].value],xe.mode="edit",xe.isRole("staff")&&e.indexOf(xe.request.status_id)>-1&&(xe.mode="view")):xe.mode="create"}function ye(){var e=xe.request.status_id;if(!xe.isMode("view")&&!xe.submitting)return xe.submitting=!0,S(),P(),xe.request.isValid().then(ee()&&k).then(x).then(!xe.request.change_balance&&pe).then(qe).then(function(){return xe.isMode("edit")?Pe():M()}).catch(function(t){xe.request.status_id=e,t&&H(t)}).finally(function(){xe.submitting=!1})}function qe(){return o.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===Ie&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return Ie>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function De(){Oe.forEach(function(e){e()})}function Te(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Pe(){return xe.request.update().then(Ce).then(function(){xe.isRole("manager")?fe("LeaveRequest::updatedByManager"):(xe.isRole("staff")||xe.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Ae,Re={},Ie=0,we={},Oe=[],Se="",ke="No entitlement",Le="",Me=[],xe=n.assign(this,m);xe.absencePeriods=[],xe.absenceTypes=[],xe.canManage=!1,xe.contactName=null,xe.errors=[],xe.loading={absenceTypes:!0,entitlements:!0},xe.managedContacts=[],xe.mode="",xe.newStatusOnSave=null,xe.period={},xe.postContactSelection=!1,xe.requestStatuses={},xe.selectedAbsenceType={},xe.staffMemberSelectionComplete=!1,xe.submitting=!1,xe.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},xe.canChangeAbsenceType=w,xe.canSubmit=O,xe.closeAlert=L,xe.deleteLeaveRequest=$,xe.dismissModal=E,xe.getStatuses=j,xe.getStatusFromValue=W,xe.initAfterContactSelection=Y,xe.initRequestAttributes=J,xe.isLeaveStatus=te,xe.isLeaveType=ne,xe.isMode=ae,xe.isRole=se,xe.submit=ye,xe.updateAbsenceType=Te,function(){xe.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),ie(),de()]).then(Q).then(_e).then(ve).then(function(){return xe.canManage&&!xe.isMode("edit")&&le()}).then(function(){if(xe.selectedContactId&&(xe.request.contact_id=xe.selectedContactId),xe.request.contact_id)return xe.initAfterContactSelection()}).catch(H).finally(function(){xe.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,i,r,c){function u(e){return r.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,i,r){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:i,forceRecalculateBalanceChange:r}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,i){function r(e){l.errorMessage=e}function c(){return i.get({is_active:!0}).then(function(e){l.workPatterns=e})}function u(){return o.valuesOf("hrleaveandabsences_work_pattern_change_reason").then(function(e){l.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var l=Object.create(this);return l.changeReasons=[],l.errorMessage="",l.saveInProgress=!1,l.workPatterns=[],l.loading={content:!0},l.selected={workPattern:null,effectiveDate:null,changeReason:null},l.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){n.all([c(),u()]).finally(function(){l.loading.content=!1})}(),l.closeModal=function(){l.dismiss({$value:"cancel"})},l.closeAlert=function(){l.errorMessage=""},l.save=function(){var t=e(l.selected.effectiveDate).format(s.serverDateFormat);return l.saveInProgress=!0,i.assignWorkPattern(l.contactId,l.selected.workPattern.id,t,null,l.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),l.closeModal()}).catch(r).finally(function(){l.saveInProgress=!1})},l}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrleaveandabsences_work_pattern_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf() -}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(),g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){r.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){i.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i){function r(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,i){n=o.entitlements.slice(0,i),a=e.entitlements.slice(i+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,i;return s=e.indexBy(n,"entitlement_id.type_id"),i=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:i}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t];e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,i){o.comment&&(t=s.concat(o).concat(i),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(r).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,i,r,c,u,l,d){function m(){D.absencePeriods=t.chain(D.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){D.absenceTypes=t.filter(D.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:D.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:D.contactId,returnUrl:n})}function h(){return c.all().then(function(e){D.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:D.contactId}).then(function(e){q=e})}function g(e){i.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=D.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){D.absencePeriods=t.map(D.absencePeriods,function(e){var n=t.map(D.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

    Last updated:
    By: "+e.author_name+"
    Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
    ";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],D=this;D.absencePeriods=[],D.loading={absencePeriods:!0},D.getEditEntitlementsPageURL=p,D.openAnnualEntitlementChangeLog=g,D.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){D.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i,r){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return i.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){r.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); +!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,o){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:t(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,o,s,i){return t.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return s.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,o,s){return t.debug("WorkPatternAPI.getCalendar",n,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,o){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,o,s,i){function r(t,n){return u().then(function(a){var o=this.days[c(t).valueOf()];return!!o&&e.find(a,function(e){return e.name===n}).value===o.type}.bind(this))}function c(e){return t(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[c(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,o){return t.debug("Calendar"),n.extend({get:function(n,s,i,r){return t.debug("Calendar.get"),a.getCalendar(n,s,i,r).then(function(t){var a=t.values.map(function(e){return o.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function o(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,o,s){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return o.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",t,n,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t,n,o,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var i=a.defer();t&&n||i.reject("contact_id and period_id are mandatory");var r={contact_id:t,period_id:n,statuses:o?{IN:o}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",r,!1).then(function(e){i.resolve(e.values)}),i.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?o.reject(t(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(t){return s.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,o&&(i.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return r.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),n.all(t)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(s.permissions.admin.administer).then(function(t){return t?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,o,s,i){return n.all(this.processFilters(e),t,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,o){return n.balanceChangeByAbsenceType(e,t,a,o)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/instances/work-pattern.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("WorkPatternInstance",["$log","ModelInstance",function(e,t){return e.debug("WorkPatternInstance"),t.extend({})}])}),define("leave-absences/shared/models/work-pattern.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/work-pattern.instance"],function(e,t){"use strict";t.factory("WorkPattern",["$log","Model","WorkPatternAPI","WorkPatternInstance",function(t,n,a,o){return t.debug("WorkPattern"),n.extend({assignWorkPattern:function(e,t,n,o,s,i){return a.assignWorkPattern(e,t,n,o,s,i)},default:function(){return a.get({is_default:!0}).then(function(t){return o.init(e.first(t),!0)})},unassignWorkPattern:function(e){return a.unassignWorkPattern(e)},workPatternsOf:function(e,t,n){return a.workPatternsOf(e,t,n).then(function(e){return e.map(function(e){return o.init(e,!0)})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function u(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?c():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return o.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):i.all()}function m(e){return"me"===e?o.leaveManagees(v.contactId):"unassigned"===e?o.leaveManagees(void 0,{unassigned:!0}):o.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){r.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,u()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:i.contactId}).leaveManagees().then(function(e){i.lookupContacts=e}).then(o)}}}function o(){return t.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:i.filters.userSettings.department?i.filters.userSettings.department.value:null,level_type:i.filters.userSettings.level_type?i.filters.userSettings.level_type.value:null,location:i.filters.userSettings.location?i.filters.userSettings.location.value:null,region:i.filters.userSettings.region?i.filters.userSettings.region.value:null,id:{IN:i.filters.userSettings.contact?[i.filters.userSettings.contact.id]:i.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var i;return{init:function(e){return i=e,i.showContactName=!0,i.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function o(a,o,s,i,r,c,u,l,d,m){function f(){for(var e=[],t=n(M.selectedPeriod.start_date).clone().startOf("month"),a=n(M.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(A(t)),t.add(1,"month");M.months=e}function p(){i.$new().$watch(function(){return M.selectedMonths},function(t,n){null===n||e.equals(t,n)||I()})}function h(e){M.injectMonths=!0,k("injected").then(function(){I(e)}).then(function(){M.loading.calendar=!1})}function v(){S=a("LeaveCalendar"+t.capitalize(L)+"Controller").init(M)}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function g(){return c.all().then(function(e){M.absencePeriods=t.sortBy(e,"start_date"),M.selectedPeriod=t.find(M.absencePeriods,function(e){return!!e.current})}).then(f).then(w)}function _(){return u.all().then(u.loadCalculationUnits)}function y(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return S.loadContacts().then(function(e){M.contacts=e})}function C(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){M.filters.optionValues.regions=e.hrjc_region,M.filters.optionValues.locations=e.hrjc_location,M.filters.optionValues.levelTypes=e.hrjc_level_type,M.filters.optionValues.departments=e.hrjc_department})}function D(){return l.all()}function T(){return o.all([_(),D(),y()]).then(function(e){M.supportData.absenceTypes=e[0],M.supportData.publicHolidays=e[1],M.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,M.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,M.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,M.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function P(){var e=o.resolve();return M.injectMonths&&(e=k("destroyed"),M.injectMonths=!1),e}function A(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function R(e){e=t.includes(["contacts","period"],e)?e:"period",o.resolve().then(function(){M.loading.calendar=!0}).then(P).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function I(e){var n=M.selectedMonths.length?M.months.filter(function(e){return t.includes(M.selectedMonths,e.index)}):M.months;i.$emit("LeaveCalendar::showMonths",n,!!e)}function w(){M.selectedMonths=[n().month()]}function O(){return M.roleOverride?o.resolve().then(function(){L=M.roleOverride}):o.all([m(r.permissions.admin.administer),m(r.permissions.ssp.manage)]).then(function(e){L=e[0]?"admin":e[1]?"manager":"staff"})}function k(e){return o(function(n){var a=0,o=i.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===M.months.length&&(o(),n())})})}s.debug("Component: leave-calendar");var S,L,M=this;M.absencePeriods=[],M.contacts=[],M.contactIdsToReduceTo=null,M.injectMonths=!1,M.months=[],M.selectedMonths=null,M.selectedPeriod=null,M.showContactName=!1,M.showFilters=!1,M.supportData={},M.loading={calendar:!0,page:!0},M.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},M.labelPeriod=b,M.refresh=R,function(){O().then(p).then(v).then(P).then(g).then(function(){return o.all([q(),T()])}).then(function(){return M.showFilters?C():t.noop}).then(function(){h()}).then(function(){M.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",o]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,o){"use strict";function s(){y.calculationUnit=i(y.supportData.calculationUnits,"value",b.calculation_unit)}function i(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function r(){var e,n;return n=t(y.contactData.leaveRequest.from_date).isSame(y.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+y.calculationUnit.name+"-on-"+e+"-tooltip"}function c(){b=i(y.supportData.absenceTypes,"id",y.contactData.leaveRequest.type_id),y.contactData.leaveRequest["type_id.title"]=b.title}function u(){"days"===y.calculationUnit.name&&(g=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.from_date_type),_=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.to_date_type),y.contactData.leaveRequest["from_date_type.label"]=g.label,y.contactData.leaveRequest["to_date_type.label"]=_.label)}function l(e,t,n,a,s){e.stopPropagation(),o.openModal(t,n,a,s)}function d(){y.dates.from=new Date(y.contactData.leaveRequest.from_date),y.dates.to=new Date(y.contactData.leaveRequest.to_date)}function m(){y.contactData.isAccruedTOIL?y.label="AT":"days"===y.calculationUnit.name?f():p()}function f(){y.label=y.contactData.isAM?"AM":y.contactData.isPM?"PM":""}function p(){var e=t(y.contactData.leaveRequest.from_date).isSame(y.date,"day"),n=t(y.contactData.leaveRequest.to_date).isSame(y.date,"day");y.label=e?t(y.contactData.leaveRequest.from_date).format("HH:mm"):n?t(y.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){y.tooltipTemplate=y.contactData.isAccruedTOIL?"accrued-toil-tooltip":r()}function v(){a.$watch("day.contactData.leaveRequest",function(){y.contactData&&y.contactData.leaveRequest&&(c(),s(),u(),m(),d(),h()) +})}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(e){_([e]),U(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return j[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){S(e),U(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=P(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){N.push(o.$on("LeaveCalendar::showMonths",$)),N.push(r.subscribe("LeaveRequest::new",u)),N.push(r.subscribe("LeaveRequest::edit",B)),N.push(r.subscribe("LeaveRequest::updatedByManager",B)),N.push(r.subscribe("LeaveRequest::delete",h)),N.push(r.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function D(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function T(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function P(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function A(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function R(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function I(){return[R(c.statusNames.approved),R(c.statusNames.adminApproved),R(c.statusNames.awaitingApproval),R(c.statusNames.moreInformationRequired)]}function w(){return H.month.loading=!0,a.all([k(),O()]).then(b).then(x).then(function(){F=!0}).then(function(){H.month.loading=!1})}function O(){return i.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:I()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function k(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){j=e.indexBy(t,"contact_id")})}function S(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function L(){o.$emit("LeaveCalendar::monthDestroyed"),N.map(function(e){e.remove?e.remove():e()})}function M(t,n,o){var s,i;return t.contactsData[n]=t.contactsData[n]||{},i=m(n),s=!0===o?a.resolve():a.all([i.isWeekend(p(t.date)),i.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:D(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?T(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function x(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return M(e,t.id)}))}))}function $(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!F)&&w())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=A(e);t&&(h(t),-1!==I().indexOf(e.status_id)&&u(e))}function U(e){return a.all(P(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var F=!1,N=[],j={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=L,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,i,r,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(i.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=D[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&r.publish("ManagerBadge:: Update Count"),r.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(D,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:D[e].label,isDirectAction:D[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,D={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return r.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,c.serverDateFormat).toDate()}function h(e){return t(e).format(c.serverDateFormat)}function v(e){var t;return i.resolve().then(function(){N(e),"from"===e&&F(),k("hours")&&(_(e),"from"!==e||te.uiOptions.multipleDays||_("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return i.reject("Please change date as it is not in any absence period")}).then(W).then(function(){if(t)return x()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(V(),!t)return E();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(P).finally(y)}function b(){return V(),E()}function g(){return te.uiOptions.toDate=null,N("to"),i.resolve().then(V).then(te.setDaysSelectionModeExtended).then(y).then(!te.uiOptions.multipleDays&&E)}function _(e){te.uiOptions.times[e].loading=!0}function y(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,k("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function C(){return te.request?te.request.request_type:te.leaveType||null}function D(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(j).catch(P)}function P(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function A(){return te.isMode("create")||te.forceRecalculateBalanceChange?E():T()}function R(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():i.resolve()}function I(){ee.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){Q()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){J(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",E))}function w(){te.isMode("edit")&&(te.isLeaveStatus(c.statusNames.approved)||te.isLeaveStatus(c.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function O(){o.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(K(e),V()))})}function k(e){return te.selectedAbsenceType.calculation_unit_name===e}function S(e){return te.request.request_type===e}function L(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function M(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function x(){return u.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function $(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function E(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(j).catch(P).finally(function(){te.loading.balanceChange=!1})):i.resolve()}function B(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function U(){return h(te.request.from_date)===h(te.request.to_date)}function F(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,N("to"))}function N(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),V(),z()}function j(e){te.balance.change=e,te.request.balance_change=e.amount,f(),B(),te.loading.balanceChange=!1}function W(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function H(){return!te.isMode("create")&&U()||te.isMode("create")&&(S("sickness")||k("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,i.resolve().then(te.setDaysSelectionModeExtended)}function G(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function Y(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function V(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(k("hours")||S("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function X(){e.forEach(ee,function(e){e()})}function Q(){var e,t=te.selectedAbsenceType.calculation_unit_name;return Y(),e=t!==te.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&H).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&V).then(y).then(E)}function J(e){return te.absenceTypes=e,Y(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,N("to")),G(),E()}function K(e){var t=D(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(D(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(D(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=c.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:$},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:r.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=b,te.daysSelectionModeChangeHandler=g,te.disableAndShowLoadingTimeInput=_,te.getMomentDateWithGivenTime=D,te.handleError=P,te.isCalculationUnit=k,te.isLeaveType=S,te.isNotWorkingDay=L,te.performBalanceChangeCalculation=E,te.setRequestDateTimesAndDateTypes=V,te.updateEndTimeInputMinTime=K,te.$onDestroy=X,function(){n("RequestModalDetails"+e.capitalize(C(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",te),I(),te.initChildController().then(function(){return i.all([x(),M()])}).then(!te.isMode("create")&&R).then(H).then(function(){if(!te.isMode("create"))return i.resolve().then(te.initTimesExtended).then(V)}).then(!te.isMode("create")&&W).then(w).then(G).then(A).then(O).then(!te.isMode("view")&&te.initWatchersExtended).catch(P).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l){function d(){return O.fileUploader&&O.fileUploader.queue.length>0}function m(){return O.getFilesAmount()0?R.map(function(e){return e.label}).join(", "):""}function q(){return O.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(R.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){w[e.label]=t})})).catch(function(){w=null})}function D(){return c.valuesOf("safe_file_extension").then(function(e){R=e})}function T(e){return!e.attachment_id||O.canManage}function P(){e.forEach(I,function(e){e()})}function A(e,t){O.fileUploader.queue&&O.fileUploader.queue.length>0?O.fileUploader.uploadAll({entityID:O.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var R=[],I=[],w={},O=Object.create(this);return O.filesLoaded=!1,O.fileUploader=null,O.today=Date.now(),O.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",O.userDateFormat=i.DATE_FORMAT,O.$onDestroy=P,O.canRemoveAttachment=T,O.canSubmit=d,O.canUploadMore=m,O.formatDateTime=f,O.getAuthorName=p,O.getFilesAmount=h,O.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",O),g(),a.all([D(),q()]).then(_).finally(function(){O.filesLoaded=!0})}(),O}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,o){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],s.openLeavePopup=a,function(){o=n.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,o,s,i,r,c,u,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var t=j[e.status];t?t(e.leaveRequest):W.refresh()}function b(t){t.dataIndex=e.indexBy(t.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return i.all().then(i.loadCalculationUnits).then(function(t){W.absenceTypes=t,W.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return R("approved",{status_id:N(m.statusNames.approved)})}function C(){return n.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[N(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[N(m.statusNames.awaitingApproval),N(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function D(){return r.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(t){var n=e.find(W.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function T(){return r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return M(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function P(){return n.all([r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),A({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:M(e[0]),expiredTOILS:x(e[1].list)})}).then(function(t){W.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function A(t){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function R(e,t){return A(t).then(function(t){W.sections[e].data=t.list})}function I(){return n.all(Object.values(W.sections).filter(function(e){return e.open}).map(S))}function w(){return R("other",{status_id:{in:[N(m.statusNames.rejected),N(m.statusNames.cancelled)]}})}function O(){return R("pending",{status_id:{in:[N(m.statusNames.awaitingApproval),N(m.statusNames.moreInformationRequired)]}})}function k(){return R("holidays",{public_holiday:!0})}function S(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function L(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){W.leaveRequestStatuses=e.indexBy(t,"value")})}function M(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(W.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function x(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function $(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(W.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],B(t,a))})}function B(e,t){var n=W.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function U(){W.loading.content=!0,n.all([D(),C()]).then(function(){W.loading.content=!1}).then(function(){return n.all([I(),h()])})}function F(e){var t=W.sections[e];t.open=!t.open,t.open&&!t.data.length&&S(t)}function N(t){return e.find(W.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var j={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:T},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:P},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:k},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w}},W.labelPeriod=g,W.refresh=U,W.toggleSection=F,function(){n.all([L(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return n.all([D(),C()])}).then(function(){W.loading.content=!1}),$()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report", +controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function u(){var e=i.request,t=!!e.from_date&&!!e.to_date,n=i.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return i.canCalculateChange()}function d(t,n){var a=i.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);i.uiOptions.multipleDays||("from"===t&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=i.convertDateToServerFormat(t),r.isPublicHoliday(t).then(function(n){return n?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,i.requestDayTypes).then(function(t){return t.length?t:i.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return A(n,e),e})):o.reject([])}function f(e,n){return e=t(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return o.resolve()}function v(){return C(i.uiOptions.fromDate,"from").then(function(){return C(i.uiOptions.toDate,"to")})}function b(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,t){i.isCalculationUnit("days")||+e==+t||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function g(e){var n=t(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),i.uiOptions.times[e].time=n}function _(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],t=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(T)).then(function(){["from","to"].forEach(function(e){g(e),I(e),t[e].amount=Math.min(i.request[e+"_date_amount"],t[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function y(){["from","to"].forEach(function(e){b(e),q(e)})}function q(e){s.$watch(function(){return i.uiOptions.times[e].time},function(t,n){i.isCalculationUnit("days")||t===n||(i.setRequestDateTimesAndDateTypes(),t&&I(e,!0))})}function C(e,t){return m(e,t).then(function(){i.loading[t+"DayTypes"]=!1})}function D(e){return C(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return T(e).then(function(){I(e,!0)})})}function T(e){var t=i.uiOptions[e+"Date"],n=!i.uiOptions.multipleDays;return t?i.request.getWorkDayForDate(i.convertDateToServerFormat(t)).then(function(t){k[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return k[e]={},i.handleError(t)}).finally(function(){n&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(t){var n=i.uiOptions.times[t];i["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function A(t,n){var a="request"+e.startCase(t)+"DayTypes";i[a]=n,i.isMode("create")&&(i.request[t+"_date_type"]=i[a][0].value)}function R(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),T("from").then(function(){I("from",!0)})):o.resolve()}function I(e,t){var n=i.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,c=k[a].number_of_hours?p(s,r).toString():"0";o.maxAmount=c,t&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function O(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?T("from").then(function(){I("from",!0)}):o.resolve()}var k={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=c,i.canCalculateChange=u,i.canSubmit=l,i.initChildController=h,i.initDayTypesExtended=v,i.initTimesExtended=_,i.initWatchersExtended=y,i.onAbsenceTypeUpdateExtended=O,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=R}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s,i){function r(){return!(!i.canCalculateChange()||!i.request.sickness_reason)}function c(){return a.all([d(),m(!0)])}function u(t){var n=i.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function l(t){return!!e.find(i.sicknessDocumentTypes,function(e){return e.value===t})}function d(){return s.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){i.sicknessDocumentTypes=e})}function m(t){return s.valuesOf("hrleaveandabsences_sickness_reason",t).then(function(t){i.sicknessReasons=e.indexBy(t,"name")})}function f(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){m(!1)})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:i}),i.canSubmit=r,i.initChildController=c,i.isChecked=u,i.isDocumentInRequest=l,i.openSicknessReasonOptionsEditor=f}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=t.duration(t(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,t=!c.uiOptions.multipleDays&&!!c.request.from_date,n=t||e,a=N.from_date!==c.request.from_date||N.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&n&&W.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,t=c.request;return b({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function b(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&W.hasExpirationFromAdminSettings,t=W.hasPreviousExpirationDate,n=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=n&&(a||e||t)}function _(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function y(){return W.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){W.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",y().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function D(){o.$watch(function(){return c.request.toil_to_accrue},function(e,t){+e!=+t&&c.performBalanceChangeCalculation()})}function T(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&c.isCalculationUnit("hours")&&S(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function P(){var e=c.uiOptions.times;e.from.time=t(c.request.from_date).format("HH:mm"),e.to.time=t(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function A(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,t){e!==t&&(c.setRequestDateTimesAndDateTypes(),U(),l(),L())})})}function R(){c.isMode("view")||(D(),T(),A())}function I(t){return i.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){c.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function w(){return l(),L(),U()}function O(){return x(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),j?j=!1:L(),U()}function k(e){c.uiOptions.times[e].time=""}function S(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function L(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function M(){N=e.cloneDeep(c.request.attributes())}function x(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function $(){c.setRequestDateTimesAndDateTypes(),l(),L(),c.isCalculationUnit("hours")?S():c.request.toil_to_accrue=null}function E(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){I(!1)})}function B(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function U(){return f()?d().catch(a.resolve):a.resolve()}function F(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var N,j=!c.isMode("create"),W={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=P,c.initWatchersExtended=R,c.onAbsenceTypeUpdateExtended=$,c.onDateChangeExtended=w,c.openToilInDaysAccrualOptionsEditor=E,c.resetUIInputsExtended=k,c.setDaysSelectionModeExtended=O,c.updateExpiryDate=F,function(){M(),x(),B(),!c.isMode("create")&&_()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,D){function T(e){"days"===xe.selectedAbsenceType.calculation_unit_name?delete xe.request[e+"_date_amount"]:delete xe.request[e+"_date_type"]}function P(){["from","to"].forEach(T)}function A(){var e=xe.requestStatuses[y.statusNames.awaitingApproval].value;we.status_id===e&&e!==xe.request.status_id&&d.publish("ManagerBadge:: Update Count")}function R(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!xe.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function O(){var e=R();return xe.isMode("edit")&&(e=e&&(G()||I())),xe.canManage&&xe.requestStatuses&&(e=e&&!!xe.getStatusFromValue(xe.newStatusOnSave)),(e=e&&!!xe.period.id)&&!xe.isMode("view")}function k(){xe.isSelfRecord?xe.request.status_id=xe.requestStatuses[y.statusNames.awaitingApproval].value:xe.canManage&&(xe.request.status_id=xe.newStatusOnSave||xe.request.status_id)}function S(){if(xe.isMode("edit")&&!xe.isRole("staff")&&"toil"!==N())return xe.request.calculateBalanceChange(xe.selectedAbsenceType.calculation_unit_name).then(function(e){if(+xe.balance.change.amount!=+e.amount)return D.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function L(){xe.errors=[]}function M(){return xe.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function x(){ee()&&!xe.isRole("staff")&&(xe.request.change_balance=!0)}function $(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return xe.request.delete().then(function(){xe.dismissModal(),d.publish("LeaveRequest::delete",xe.request)})}})}function E(){r.dismiss({$value:"cancel"})}function B(){var e=N();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return F(xe.getStatusFromValue(xe.request.status_id).name)}function F(e){return n.map(Re[e],function(e){return xe.requestStatuses[e]})}function N(){return xe.request?xe.request.request_type:xe.leaveType||null}function j(){return!xe.request||e.equals({},xe.requestStatuses)?[]:xe.request.status_id?U():F("none")}function W(e){return n.find(xe.requestStatuses,function(t){return t.value===e})}function H(e){xe.errors=n.isArray(e)?e:[e],xe.loading.absenceTypes=!1,xe.submitting=!1}function G(){return!e.equals(we,xe.request.attributes())||xe.canManage&&xe.newStatusOnSave}function Y(){return xe.postContactSelection=!0,xe.staffMemberSelectionComplete=!1,xe.request.contact_id?o.resolve().then(re).then(ce).then(he).then(be).then(Z).then(z).then(xe.isMode("edit")?ge:n.noop).then(function(){xe.postContactSelection=!1,xe.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Se)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Re.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Re.awaiting_approval=e,Re.more_information_required=e,Re.rejected=e,Re.approved=e,Re.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return xe.canManage?f.find(xe.request.contact_id).then(function(e){xe.contactName=e.display_name}):o.resolve()}function X(){Oe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",xe.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Ie++})),i.$on("$destroy",De),i.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function Q(){var e,t;xe.request=xe.leaveRequest||null,e=N(),t=xe.initRequestAttributes(),"leave"===e?xe.request=_.init(t):"sickness"===e?xe.request=q.init(t):"toil"===e&&(xe.request=C.init(t))}function J(){var e={};return xe.request?e=xe.request.attributes():xe.canManage||(e={contact_id:ke}),e}function K(){if(Le="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(Le="admin")}).then(function(){return"staff"===Le&&c(y.permissions.ssp.manage).then(function(e){e&&(Le="manager")})}).finally(function(){xe.canManage=xe.isRole("manager")||xe.isRole("admin")})}function Z(){(xe.isRole("admin")||xe.isMode("create")&&xe.isRole("manager"))&&(xe.newStatusOnSave=xe.requestStatuses[y.statusNames.approved].value)}function ee(){return!xe.request.status_id||!n.includes(["cancelled","rejected"],W(xe.request.status_id).name)}function te(e){var t=xe.getStatusFromValue(xe.request.status_id);return!!t&&t.name===e}function ne(e){return xe.request&&xe.request.request_type===e}function ae(e){return xe.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date)&&o.isSameOrBefore(t.end_date)}function se(e){return Le===e}function ie(){return h.all().then(function(e){xe.absencePeriods=e})}function re(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Ae={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return xe.loading.entitlements=!0,b.all({contact_id:xe.request.contact_id,period_id:xe.period.id,type_id:{IN:Ae.ids}},!0).finally(function(){xe.loading.entitlements=!1})}function ue(){return p.get().then(function(e){ke=e.contactId})}function le(){return xe.selectedContactId?f.find(xe.selectedContactId).then(function(e){xe.managedContacts=[e]}):xe.isRole("admin")?f.all().then(function(e){xe.managedContacts=n.remove(e.list,function(e){return e.id!==ke})}):f.find(ke).then(function(e){return e.leaveManagees()}).then(function(e){xe.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){xe.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){A(),d.publish(e,xe.request),xe.errors=[],xe.dismissModal()}function pe(){["from","to"].forEach(function(e){xe.request[e+"_date"]=we[e+"_date"]})}function he(e){if(xe.absenceTypes=me(Ae.types,e),!xe.absenceTypes.length)return o.reject(Se)}function ve(){xe.period=n.find(xe.absencePeriods,function(e){return xe.isMode("create")?e.current:oe(xe.request,e)})}function be(){xe.isMode("create")?(xe.selectedAbsenceType=xe.absenceTypes[0],xe.request.type_id=xe.selectedAbsenceType.id):xe.selectedAbsenceType=n.find(xe.absenceTypes,function(e){return e.id===xe.request.type_id})}function ge(){we=e.copy(xe.request.attributes())}function _e(){var e;xe.request.id?(e=[xe.requestStatuses[y.statusNames.approved].value,xe.requestStatuses[y.statusNames.adminApproved].value,xe.requestStatuses[y.statusNames.rejected].value,xe.requestStatuses[y.statusNames.cancelled].value],xe.mode="edit",xe.isRole("staff")&&e.indexOf(xe.request.status_id)>-1&&(xe.mode="view")):xe.mode="create"}function ye(){var e=xe.request.status_id;if(!xe.isMode("view")&&!xe.submitting)return xe.submitting=!0,k(),P(),xe.request.isValid().then(ee()&&S).then(x).then(!xe.request.change_balance&&pe).then(qe).then(function(){return xe.isMode("edit")?Pe():M()}).catch(function(t){xe.request.status_id=e,t&&H(t)}).finally(function(){xe.submitting=!1})}function qe(){return o.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===Ie&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return Ie>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function De(){Oe.forEach(function(e){e()})}function Te(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Pe(){return xe.request.update().then(Ce).then(function(){xe.isRole("manager")?fe("LeaveRequest::updatedByManager"):(xe.isRole("staff")||xe.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Ae,Re={},Ie=0,we={},Oe=[],ke="",Se="No entitlement",Le="",Me=[],xe=n.assign(this,m);xe.absencePeriods=[],xe.absenceTypes=[],xe.canManage=!1,xe.contactName=null,xe.errors=[],xe.loading={absenceTypes:!0,entitlements:!0},xe.managedContacts=[],xe.mode="",xe.newStatusOnSave=null,xe.period={},xe.postContactSelection=!1,xe.requestStatuses={},xe.selectedAbsenceType={},xe.staffMemberSelectionComplete=!1,xe.submitting=!1,xe.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},xe.canChangeAbsenceType=w,xe.canSubmit=O,xe.closeAlert=L,xe.deleteLeaveRequest=$,xe.dismissModal=E,xe.getStatuses=j,xe.getStatusFromValue=W,xe.initAfterContactSelection=Y,xe.initRequestAttributes=J,xe.isLeaveStatus=te,xe.isLeaveType=ne,xe.isMode=ae,xe.isRole=se,xe.submit=ye,xe.updateAbsenceType=Te,function(){xe.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),ie(),de()]).then(Q).then(_e).then(ve).then(function(){return xe.canManage&&!xe.isMode("edit")&&le()}).then(function(){if(xe.selectedContactId&&(xe.request.contact_id=xe.selectedContactId),xe.request.contact_id)return xe.initAfterContactSelection()}).catch(H).finally(function(){xe.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,i,r,c){function u(e){return r.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,i,r){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:i,forceRecalculateBalanceChange:r}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,i,r){function c(e){m.errorMessage=e}function u(){return r.get({is_active:!0}).then(function(e){m.workPatterns=e})}function l(e){return s.valuesOf("hrleaveandabsences_work_pattern_change_reason",e).then(function(e){m.changeReasons=e})}function d(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_work_pattern_change_reason?reset=1").on("crmUnload",function(){l(!1)})}t.debug("Component: absence-tab-custom-work-pattern-modal");var m=Object.create(this);return m.changeReasons=[],m.errorMessage="",m.saveInProgress=!1,m.workPatterns=[],m.loading={content:!0},m.selected={workPattern:null,effectiveDate:null,changeReason:null},m.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},m.openWorkPatternChangeReason=d,function(){n.all([u(),l(!0)]).finally(function(){m.loading.content=!1})}(),m.closeModal=function(){m.dismiss({$value:"cancel"})},m.closeAlert=function(){m.errorMessage=""},m.save=function(){var t=e(m.selected.effectiveDate).format(i.serverDateFormat);return m.saveInProgress=!0,r.assignWorkPattern(m.contactId,m.selected.workPattern.id,t,null,m.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),m.closeModal()}).catch(c).finally(function(){m.saveInProgress=!1})},m}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","crmAngService","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrleaveandabsences_work_pattern_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0, +a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(),g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){r.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){i.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i){function r(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,i){n=o.entitlements.slice(0,i),a=e.entitlements.slice(i+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,i;return s=e.indexBy(n,"entitlement_id.type_id"),i=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:i}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t];e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,i){o.comment&&(t=s.concat(o).concat(i),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(r).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,i,r,c,u,l,d){function m(){D.absencePeriods=t.chain(D.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){D.absenceTypes=t.filter(D.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:D.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:D.contactId,returnUrl:n})}function h(){return c.all().then(function(e){D.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:D.contactId}).then(function(e){q=e})}function g(e){i.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=D.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){D.absencePeriods=t.map(D.absencePeriods,function(e){var n=t.map(D.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

    Last updated:
    By: "+e.author_name+"
    Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
    ";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],D=this;D.absencePeriods=[],D.loading={absencePeriods:!0},D.getEditEntitlementsPageURL=p,D.openAnnualEntitlementChangeLog=g,D.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){D.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i,r){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return i.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){r.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js index 3f798dbed1e..20503457606 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js @@ -8,7 +8,7 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return U(e)&&e.then&&e.$$promises}if(!U(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!U(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},U(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||F(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!U(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=U(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=F(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(D.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:U(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!D[r])return m(r,t.self);for(var o in T)B(T[o])&&(t[o]=T[o](t,T.$delegates[o]));return D[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=D;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=D;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),w.current)}).then(null,function(a){return a===P?T:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=P(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function D(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=P(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function P(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function T(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:T(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function M(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,T(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return U(n)?e+G(n):(n=t.$eval(n),U(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function L(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,U=t.isObject,F=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;aWhen All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(D(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){E.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(m).then(T)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function D(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function P(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function T(){E.selectedMonths=[n().month()]}function S(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=P,function(){S().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return F[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){U.push(r.$on("LeaveCalendar::showMonths",L)),U.push(i.subscribe("LeaveRequest::new",c)),U.push(i.subscribe("LeaveRequest::edit",j)),U.push(i.subscribe("LeaveRequest::updatedByManager",j)),U.push(i.subscribe("LeaveRequest::delete",h)),U.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function D(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function P(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[P(u.statusNames.approved),P(u.statusNames.adminApproved),P(u.statusNames.awaitingApproval),P(u.statusNames.moreInformationRequired)]}function T(){return W.month.loading=!0,a.all([O(),S()]).then(g).then(M).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){F=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),U.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function M(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function L(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&T())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=D(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,U=[],F={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}), -define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){U(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,U("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(F).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function D(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function P(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function T(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function L(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(F).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,U("to"))}function U(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function F(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,U("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:L},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),E()])}).then(!te.isMode("create")&&P).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(T).then(V).then(D).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function f(){return S.getFilesAmount()0?P.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(P.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){T[e.label]=t})})).catch(function(){T=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){P=e})}function A(e){return!e.attachment_id||S.canManage}function w(){e.forEach(R,function(e){e()})}function D(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var P=[],R=[],T={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=w,S.canRemoveAttachment=A,S.canSubmit=d,S.canUploadMore=f,S.formatDateTime=m,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){F.filters.leaveRequest.contact_id=null,F.refresh()}function p(){var e=F.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?F.leaveRequests.filter.list.length:F.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(F.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(F.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(F.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(F.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){F.absencePeriods=e.sortBy(t,"start_date"),F.filters.leaveRequest.selectedPeriod=e.find(F.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){F.absenceTypes=e})}function w(e){return(F.isAdmin?r.all(p()):r.leaveManagees(F.contactId,p())).then(function(t){return F.filteredUsers=F.isAdmin?t.list:t,e?P(e):n.all([P("table"),P("filter")])}).then(function(){F.filters.leaveRequest.leaveStatus!==H&&0===F.leaveRequests.table.list.length&&F.refresh(1,!0)})}function D(){return s.valuesOf("hrjc_department").then(function(e){F.departments=e})}function P(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:F.pagination,r="filter"===e?{return:["status_id"]}:{};return F.loading[n]=!0,l.all(S(t),a,"from_date DESC",r,!1).then(function(t){F.leaveRequests[e]=t}).catch(function(){F.leaveRequests[e].list=[]}).finally(function(){F.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){F.levelTypes=e})}function T(){return s.valuesOf("hrjc_location").then(function(e){F.locations=e})}function S(t){var n=F.filters.leaveRequest;return{contact_id:E(),managed_by:F.isAdmin&&"me"!==n.assignedTo.type?void 0:F.contactId,status_id:L(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(F.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){F.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){F.leaveRequestStatuses=e.concat(F.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function E(){return F.filteredUsers.length>0&&F.filters.leaveRequest.contact_id?F.filters.leaveRequest.contact_id:{IN:F.filteredUsers.map(function(e){return e.id})}}function M(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function L(e){var t=F.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=M(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(F.filters.leaveRequest.leaveStatus=H),(e<=F.totalNoOfPages()||0===F.totalNoOfPages())&&(F.pagination.page=e,w(n))}function j(e){F.filters.leaveRequest.leaveStatus=e,F.refresh(1,!1,"table")}function B(e){F.filters.leaveRequest.assignedTo=e,F.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){F.refresh()}),f.subscribe("LeaveRequest::new",function(){F.refresh()}),f.subscribe("LeaveRequest::edit",function(){F.refresh()}),f.subscribe("LeaveRequest::delete",function(){F.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){F.refresh()})}function U(){return Math.ceil(F.leaveRequests.table.total/F.pagination.size)}t.debug("Component: manage-leave-requests");var F=this,H={name:"all",label:"All"};F.absencePeriods=[],F.absenceTypes=[],F.filteredUsers=[],F.isFilterExpanded=!1,F.isAdmin=!1,F.leaveRequests={table:{list:[]},filter:{list:[]}},F.leaveRequestStatuses=[H],F.loading={content:!0,page:!0,table:!0},F.pagination={page:1,size:7},F.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],F.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:F.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:F.filtersByAssignee[0]}},F.clearStaffSelection=m,F.countLeaveRequestByStatus=h,F.getAbsenceTypeByID=v,F.getArrayOfSize=g,F.getLeaveStatusByValue=b,F.getNavBadge=y,F.getUserNameByID=q,F.labelPeriod=$,F.openLeavePopup=x,F.refresh=k,F.refreshWithFilter=j,F.refreshWithFilterByAssignee=B,F.totalNoOfPages=U,function(){o(i.permissions.admin.administer).then(function(e){F.isAdmin=e,n.all([C(),A(),O(),D(),T(),R(),I()]).then(function(){F.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return D(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),T(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(T)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function D(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function P(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function T(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=P}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=U.from_date!==u.request.from_date||U.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&H.hasExpirationFromAdminSettings,t=H.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&u.isCalculationUnit("hours")&&I(),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function D(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),B(),l(),x())})})}function P(){u.isMode("view")||(C(),A(),D())}function R(t){ -return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function T(){return l(),x(),B()}function S(){return M(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),F?F=!1:x(),B()}function O(e){u.uiOptions.times[e].time=""}function I(){u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours}function x(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function E(){U=e.cloneDeep(u.request.attributes())}function M(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function L(){u.setRequestDateTimesAndDateTypes(),l(),x(),u.isCalculationUnit("hours")?I():u.request.toil_to_accrue=null}function k(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){R(!1)})}function j(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function B(){return m()?d().catch(a.resolve):a.resolve()}function N(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var U,F=!u.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=P,u.onAbsenceTypeUpdateExtended=L,u.onDateChangeExtended=T,u.openToilInDaysAccrualOptionsEditor=k,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=N,function(){E(),M(),j(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,r,o){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(o.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function D(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Te.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=P();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==U())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function E(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function L(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=U();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(Pe[e],function(e){return Me.requestStatuses[e]})}function U(){return Me.request?Me.request.request_type:Me.leaveType||null}function F(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Te,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Pe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Pe.awaiting_approval=e,Pe.more_information_required=e,Pe.rejected=e,Pe.approved=e,Pe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=U(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Me.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){De={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:De.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){D(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Te[e+"_date"]})}function he(e){if(Me.absenceTypes=fe(De.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function ve(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Te=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():E()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var De,Pe={},Re=0,Te={},Se=[],Oe="",Ie="No entitlement",xe="",Ee=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=T,Me.canSubmit=S,Me.closeAlert=x,Me.deleteLeaveRequest=L,Me.dismissModal=k,Me.getStatuses=F,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}), -function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(t){return t.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM),define("leave-absences/admin-dashboard/modules/config",["common/angular","leave-absences/admin-dashboard/modules/settings"],function(e){return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(e,t,n,a,r,o){var s={format:["DateFormat",function(e){return e.getDateFormat()}]};r.debugEnabled(o.debug),t.defaults.stripTrailingSlashes=!1,a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:s}).state("calendar",{url:"/calendar",template:'',resolve:s}).state("leave-balances",{url:"/leave-balances",template:"",resolve:s})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function t(e,t){e.debug("Component: admin-dashboard-container"),t.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",t]})}),define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/admin-dashboard":n+"/admin-dashboard"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); +define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){U(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,U("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(F).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function D(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function P(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function T(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function L(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(F).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,U("to"))}function U(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function F(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,U("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:L},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),E()])}).then(!te.isMode("create")&&P).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(T).then(V).then(D).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function f(){return S.getFilesAmount()0?P.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(P.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){T[e.label]=t})})).catch(function(){T=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){P=e})}function A(e){return!e.attachment_id||S.canManage}function w(){e.forEach(R,function(e){e()})}function D(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var P=[],R=[],T={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=w,S.canRemoveAttachment=A,S.canSubmit=d,S.canUploadMore=f,S.formatDateTime=m,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){F.filters.leaveRequest.contact_id=null,F.refresh()}function p(){var e=F.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?F.leaveRequests.filter.list.length:F.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(F.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(F.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(F.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(F.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){F.absencePeriods=e.sortBy(t,"start_date"),F.filters.leaveRequest.selectedPeriod=e.find(F.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){F.absenceTypes=e})}function w(e){return(F.isAdmin?r.all(p()):r.leaveManagees(F.contactId,p())).then(function(t){return F.filteredUsers=F.isAdmin?t.list:t,e?P(e):n.all([P("table"),P("filter")])}).then(function(){F.filters.leaveRequest.leaveStatus!==H&&0===F.leaveRequests.table.list.length&&F.refresh(1,!0)})}function D(){return s.valuesOf("hrjc_department").then(function(e){F.departments=e})}function P(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:F.pagination,r="filter"===e?{return:["status_id"]}:{};return F.loading[n]=!0,l.all(S(t),a,"from_date DESC",r,!1).then(function(t){F.leaveRequests[e]=t}).catch(function(){F.leaveRequests[e].list=[]}).finally(function(){F.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){F.levelTypes=e})}function T(){return s.valuesOf("hrjc_location").then(function(e){F.locations=e})}function S(t){var n=F.filters.leaveRequest;return{contact_id:E(),managed_by:F.isAdmin&&"me"!==n.assignedTo.type?void 0:F.contactId,status_id:L(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(F.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){F.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){F.leaveRequestStatuses=e.concat(F.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function E(){return F.filteredUsers.length>0&&F.filters.leaveRequest.contact_id?F.filters.leaveRequest.contact_id:{IN:F.filteredUsers.map(function(e){return e.id})}}function M(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function L(e){var t=F.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=M(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(F.filters.leaveRequest.leaveStatus=H),(e<=F.totalNoOfPages()||0===F.totalNoOfPages())&&(F.pagination.page=e,w(n))}function j(e){F.filters.leaveRequest.leaveStatus=e,F.refresh(1,!1,"table")}function B(e){F.filters.leaveRequest.assignedTo=e,F.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){F.refresh()}),f.subscribe("LeaveRequest::new",function(){F.refresh()}),f.subscribe("LeaveRequest::edit",function(){F.refresh()}),f.subscribe("LeaveRequest::delete",function(){F.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){F.refresh()})}function U(){return Math.ceil(F.leaveRequests.table.total/F.pagination.size)}t.debug("Component: manage-leave-requests");var F=this,H={name:"all",label:"All"};F.absencePeriods=[],F.absenceTypes=[],F.filteredUsers=[],F.isFilterExpanded=!1,F.isAdmin=!1,F.leaveRequests={table:{list:[]},filter:{list:[]}},F.leaveRequestStatuses=[H],F.loading={content:!0,page:!0,table:!0},F.pagination={page:1,size:7},F.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],F.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:F.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:F.filtersByAssignee[0]}},F.clearStaffSelection=m,F.countLeaveRequestByStatus=h,F.getAbsenceTypeByID=v,F.getArrayOfSize=g,F.getLeaveStatusByValue=b,F.getNavBadge=y,F.getUserNameByID=q,F.labelPeriod=$,F.openLeavePopup=x,F.refresh=k,F.refreshWithFilter=j,F.refreshWithFilterByAssignee=B,F.totalNoOfPages=U,function(){o(i.permissions.admin.administer).then(function(e){F.isAdmin=e,n.all([C(),A(),O(),D(),T(),R(),I()]).then(function(){F.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return D(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),T(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(T)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function D(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function P(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function T(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=P}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s){function i(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function u(){return a.all([d(),f(!0)])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function l(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function d(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function f(t){return o.valuesOf("hrleaveandabsences_sickness_reason",t).then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}function m(){r.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=i,s.initChildController=u,s.isChecked=c,s.isDocumentInRequest=l,s.openSicknessReasonOptionsEditor=m}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=U.from_date!==u.request.from_date||U.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&H.hasExpirationFromAdminSettings,t=H.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&u.isCalculationUnit("hours")&&I(),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function D(){["from","to"].forEach(function(e){r.$watch(function(){ +return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),B(),l(),x())})})}function P(){u.isMode("view")||(C(),A(),D())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function T(){return l(),x(),B()}function S(){return M(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),F?F=!1:x(),B()}function O(e){u.uiOptions.times[e].time=""}function I(){u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours}function x(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function E(){U=e.cloneDeep(u.request.attributes())}function M(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function L(){u.setRequestDateTimesAndDateTypes(),l(),x(),u.isCalculationUnit("hours")?I():u.request.toil_to_accrue=null}function k(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){R(!1)})}function j(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function B(){return m()?d().catch(a.resolve):a.resolve()}function N(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var U,F=!u.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=P,u.onAbsenceTypeUpdateExtended=L,u.onDateChangeExtended=T,u.openToilInDaysAccrualOptionsEditor=k,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=N,function(){E(),M(),j(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,r,o){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(o.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function D(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Te.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=P();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==U())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Me.errors=[]}function E(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function L(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=U();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(Pe[e],function(e){return Me.requestStatuses[e]})}function U(){return Me.request?Me.request.request_type:Me.leaveType||null}function F(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Te,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Pe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Pe.awaiting_approval=e,Pe.more_information_required=e,Pe.rejected=e,Pe.approved=e,Pe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=U(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Me.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){De={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:De.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){D(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Te[e+"_date"]})}function he(e){if(Me.absenceTypes=fe(De.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function ve(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Te=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():E()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var De,Pe={},Re=0,Te={},Se=[],Oe="",Ie="No entitlement",xe="",Ee=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=T,Me.canSubmit=S,Me.closeAlert=x,Me.deleteLeaveRequest=L,Me.dismissModal=k,Me.getStatuses=F,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l, +openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(t){return t.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM),define("leave-absences/admin-dashboard/modules/config",["common/angular","leave-absences/admin-dashboard/modules/settings"],function(e){return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(e,t,n,a,r,o){var s={format:["DateFormat",function(e){return e.getDateFormat()}]};r.debugEnabled(o.debug),t.defaults.stripTrailingSlashes=!1,a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:s}).state("calendar",{url:"/calendar",template:'',resolve:s}).state("leave-balances",{url:"/leave-balances",template:"",resolve:s})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function t(e,t){e.debug("Component: admin-dashboard-container"),t.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",t]})}),define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/admin-dashboard":n+"/admin-dashboard"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js index 1ae61867433..0701c352fc2 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js @@ -6,9 +6,9 @@ */ -!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return U(e)&&e.then&&e.$$promises}if(!U(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!U(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},U(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||F(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!U(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=U(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=F(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:U(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in T)B(T[o])&&(t[o]=T[o](t,T.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=L[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),w.current)}).then(null,function(a){return a===D?T:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function T(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:T(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function L(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function E(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,T(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return U(n)?e+G(n):(n=t.$eval(n),U(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,U=t.isObject,F=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n){function a(e){e.absencePeriods&&c.absencePeriods.length&&(c.filters.period_id=o().id),e.absenceTypes&&c.absenceTypes.length&&(c.filters.type_id=s().id),(e.loggedInContactId||e.userRole)&&(c.filters.managed_by="manager"===c.userRole?c.loggedInContactId:void 0),r()&&c.submitFilters()}function r(){return e.every(c.filters,function(e){return null!==e})}function o(){return e.find(c.absencePeriods,function(e){return e.current})||c.absencePeriods.reduce(function(e,n){return t(e.end_date).isAfter(n.end_date)?e:n})}function s(){return c.absenceTypes.reduce(function(e,t){return e.title.localeCompare(t.title)?e:t})}function i(e){return e.current?"Current Period ("+e.title+")":e.title}function u(){n.$emit("LeaveBalanceFilters::update",c.filters)}var c=this;c.filters={period_id:null,type_id:null,managed_by:null},c.$onChanges=a,c.labelPeriod=i,c.submitFilters=u}n.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,t){return e.extend({all:function(e,n,a,r,o){return t.getLeaveBalances(this.processFilters(e),n,a,r,o)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){return r.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function p(){return o.all().then(o.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function h(){return s.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function v(){return n.all([m(),p(),h(),g(),q()]).catch(function(e){u.error("Error",e)})}function g(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function b(){return P.loading.report=!0,i.all(w,P.pagination,void 0,void 0,!1).then(function(e){P.report=y(e.list),P.reportCount=e.total}).catch(function(e){u.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function y(n){return n.map(function(n){return n=e.copy(n),n.absence_types=t.indexBy(n.absence_types,function(e){return e.id}),n})}function _(){a.$on("LeaveBalanceFilters::update",C),c.subscribe("LeaveRequest::new",$)}function q(){return f(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function $(e){C(e,w)}function C(e,t){w=t,P.pagination.page=1,A(),P.loadReportCurrentPage()}function A(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+w.type_id})}var w={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.loadReportCurrentPage=b,function(){_(),v().then(function(){P.loading.component=!1})}()}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return f(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(m(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function f(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function m(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(L.selectedPeriod.start_date).clone().startOf("month"),a=n(L.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");L.months=e}function p(){s.$new().$watch(function(){return L.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){L.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){L.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(L)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){L.absencePeriods=t.sortBy(e,"start_date"),L.selectedPeriod=t.find(L.absencePeriods,function(e){return!!e.current})}).then(m).then(T)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){L.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){L.filters.optionValues.regions=e.hrjc_region,L.filters.optionValues.locations=e.hrjc_location,L.filters.optionValues.levelTypes=e.hrjc_level_type,L.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){L.supportData.absenceTypes=e[0],L.supportData.publicHolidays=e[1],L.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,L.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,L.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,L.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return L.injectMonths&&(e=O("destroyed"),L.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){L.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=L.selectedMonths.length?L.months.filter(function(e){return t.includes(L.selectedMonths,e.index)}):L.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function T(){L.selectedMonths=[n().month()]}function S(){return L.roleOverride?r.resolve().then(function(){x=L.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===L.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,L=this;L.absencePeriods=[],L.contacts=[],L.contactIdsToReduceTo=null,L.injectMonths=!1,L.months=[],L.selectedMonths=null,L.selectedPeriod=null,L.showContactName=!1,L.showFilters=!1,L.supportData={},L.loading={calendar:!0,page:!0},L.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},L.labelPeriod=g,L.refresh=D,function(){S().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return L.showFilters?$():t.noop}).then(function(){h()}).then(function(){L.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return F[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){U.push(r.$on("LeaveCalendar::showMonths",M)),U.push(i.subscribe("LeaveRequest::new",c)),U.push(i.subscribe("LeaveRequest::edit",j)),U.push(i.subscribe("LeaveRequest::updatedByManager",j)),U.push(i.subscribe("LeaveRequest::delete",h)),U.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function T(){return W.month.loading=!0,a.all([O(),S()]).then(g).then(E).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){F=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),U.map(function(e){e.remove?e.remove():e()})}function L(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function E(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return L(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&T())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return L(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,U=[],F={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}), -define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){U(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return E()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,U("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(F).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function T(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function L(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function E(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(F).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,U("to"))}function U(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function F(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,U("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([E(),L()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(T).then(V).then(P).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function f(){return S.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){T[e.label]=t})})).catch(function(){T=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||S.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],T={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=w,S.canRemoveAttachment=A,S.canSubmit=d,S.canUploadMore=f,S.formatDateTime=m,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){F.filters.leaveRequest.contact_id=null,F.refresh()}function p(){var e=F.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?F.leaveRequests.filter.list.length:F.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(F.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(F.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(F.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(F.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){F.absencePeriods=e.sortBy(t,"start_date"),F.filters.leaveRequest.selectedPeriod=e.find(F.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){F.absenceTypes=e})}function w(e){return(F.isAdmin?r.all(p()):r.leaveManagees(F.contactId,p())).then(function(t){return F.filteredUsers=F.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){F.filters.leaveRequest.leaveStatus!==H&&0===F.leaveRequests.table.list.length&&F.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){F.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:F.pagination,r="filter"===e?{return:["status_id"]}:{};return F.loading[n]=!0,l.all(S(t),a,"from_date DESC",r,!1).then(function(t){F.leaveRequests[e]=t}).catch(function(){F.leaveRequests[e].list=[]}).finally(function(){F.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){F.levelTypes=e})}function T(){return s.valuesOf("hrjc_location").then(function(e){F.locations=e})}function S(t){var n=F.filters.leaveRequest;return{contact_id:L(),managed_by:F.isAdmin&&"me"!==n.assignedTo.type?void 0:F.contactId,status_id:M(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(F.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){F.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){F.leaveRequestStatuses=e.concat(F.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function L(){return F.filteredUsers.length>0&&F.filters.leaveRequest.contact_id?F.filters.leaveRequest.contact_id:{IN:F.filteredUsers.map(function(e){return e.id})}}function E(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function M(e){var t=F.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=E(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(F.filters.leaveRequest.leaveStatus=H),(e<=F.totalNoOfPages()||0===F.totalNoOfPages())&&(F.pagination.page=e,w(n))}function j(e){F.filters.leaveRequest.leaveStatus=e,F.refresh(1,!1,"table")}function B(e){F.filters.leaveRequest.assignedTo=e,F.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){F.refresh()}),f.subscribe("LeaveRequest::new",function(){F.refresh()}),f.subscribe("LeaveRequest::edit",function(){F.refresh()}),f.subscribe("LeaveRequest::delete",function(){F.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){F.refresh()})}function U(){return Math.ceil(F.leaveRequests.table.total/F.pagination.size)}t.debug("Component: manage-leave-requests");var F=this,H={name:"all",label:"All"};F.absencePeriods=[],F.absenceTypes=[],F.filteredUsers=[],F.isFilterExpanded=!1,F.isAdmin=!1,F.leaveRequests={table:{list:[]},filter:{list:[]}},F.leaveRequestStatuses=[H],F.loading={content:!0,page:!0,table:!0},F.pagination={page:1,size:7},F.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],F.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:F.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:F.filtersByAssignee[0]}},F.clearStaffSelection=m,F.countLeaveRequestByStatus=h,F.getAbsenceTypeByID=v,F.getArrayOfSize=g,F.getLeaveStatusByValue=b,F.getNavBadge=y,F.getUserNameByID=q,F.labelPeriod=$,F.openLeavePopup=x,F.refresh=k,F.refreshWithFilter=j,F.refreshWithFilterByAssignee=B,F.totalNoOfPages=U,function(){o(i.permissions.admin.administer).then(function(e){F.isAdmin=e,n.all([C(),A(),O(),P(),T(),R(),I()]).then(function(){F.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),T(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(T)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function T(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){ -function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=U.from_date!==u.request.from_date||U.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&H.hasExpirationFromAdminSettings,t=H.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&u.isCalculationUnit("hours")&&I(),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),B(),l(),x())})})}function D(){u.isMode("view")||(C(),A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function T(){return l(),x(),B()}function S(){return E(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),F?F=!1:x(),B()}function O(e){u.uiOptions.times[e].time=""}function I(){u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours}function x(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function L(){U=e.cloneDeep(u.request.attributes())}function E(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function M(){u.setRequestDateTimesAndDateTypes(),l(),x(),u.isCalculationUnit("hours")?I():u.request.toil_to_accrue=null}function k(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){R(!1)})}function j(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function B(){return m()?d().catch(a.resolve):a.resolve()}function N(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var U,F=!u.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onAbsenceTypeUpdateExtended=M,u.onDateChangeExtended=T,u.openToilInDaysAccrualOptionsEditor=k,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=N,function(){L(),E(),j(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Ee.selectedAbsenceType.calculation_unit_name?delete Ee.request[e+"_date_amount"]:delete Ee.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Ee.requestStatuses[_.statusNames.awaitingApproval].value;Te.status_id===e&&e!==Ee.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Le.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Le.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return!Ee.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=D();return Ee.isMode("edit")&&(e=e&&(V()||R())),Ee.canManage&&Ee.requestStatuses&&(e=e&&!!Ee.getStatusFromValue(Ee.newStatusOnSave)),(e=e&&!!Ee.period.id)&&!Ee.isMode("view")}function O(){Ee.isSelfRecord?Ee.request.status_id=Ee.requestStatuses[_.statusNames.awaitingApproval].value:Ee.canManage&&(Ee.request.status_id=Ee.newStatusOnSave||Ee.request.status_id)}function I(){if(Ee.isMode("edit")&&!Ee.isRole("staff")&&"toil"!==U())return Ee.request.calculateBalanceChange(Ee.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ee.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Ee.errors=[]}function L(){return Ee.request.create().then($e).then(function(){me("LeaveRequest::new")})}function E(){ee()&&!Ee.isRole("staff")&&(Ee.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ee.request.delete().then(function(){Ee.dismissModal(),d.publish("LeaveRequest::delete",Ee.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=U();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Ee.getStatusFromValue(Ee.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Ee.requestStatuses[e]})}function U(){return Ee.request?Ee.request.request_type:Ee.leaveType||null}function F(){return!Ee.request||e.equals({},Ee.requestStatuses)?[]:Ee.request.status_id?B():N("none")}function H(e){return n.find(Ee.requestStatuses,function(t){return t.value===e})}function W(e){Ee.errors=n.isArray(e)?e:[e],Ee.loading.absenceTypes=!1,Ee.submitting=!1}function V(){return!e.equals(Te,Ee.request.attributes())||Ee.canManage&&Ee.newStatusOnSave}function G(){return Ee.postContactSelection=!0,Ee.staffMemberSelectionComplete=!1,Ee.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Ee.isMode("edit")?be:n.noop).then(function(){Ee.postContactSelection=!1,Ee.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Ee.canManage?m.find(Ee.request.contact_id).then(function(e){Ee.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ee.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Le.push(t)})}function K(){var e,t;Ee.request=Ee.leaveRequest||null,e=U(),t=Ee.initRequestAttributes(),"leave"===e?Ee.request=y.init(t):"sickness"===e?Ee.request=q.init(t):"toil"===e&&(Ee.request=$.init(t))}function X(){var e={};return Ee.request?e=Ee.request.attributes():Ee.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Ee.canManage=Ee.isRole("manager")||Ee.isRole("admin")})}function Z(){(Ee.isRole("admin")||Ee.isMode("create")&&Ee.isRole("manager"))&&(Ee.newStatusOnSave=Ee.requestStatuses[_.statusNames.approved].value)}function ee(){return!Ee.request.status_id||!n.includes(["cancelled","rejected"],H(Ee.request.status_id).name)}function te(e){var t=Ee.getStatusFromValue(Ee.request.status_id);return!!t&&t.name===e}function ne(e){return Ee.request&&Ee.request.request_type===e}function ae(e){return Ee.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Ee.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Ee.loading.entitlements=!0,g.all({contact_id:Ee.request.contact_id,period_id:Ee.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Ee.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Ee.selectedContactId?m.find(Ee.selectedContactId).then(function(e){Ee.managedContacts=[e]}):Ee.isRole("admin")?m.all().then(function(e){Ee.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Ee.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ee.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Ee.request),Ee.errors=[],Ee.dismissModal()}function pe(){["from","to"].forEach(function(e){Ee.request[e+"_date"]=Te[e+"_date"]})}function he(e){if(Ee.absenceTypes=fe(Pe.types,e),!Ee.absenceTypes.length)return r.reject(Ie)}function ve(){Ee.period=n.find(Ee.absencePeriods,function(e){return Ee.isMode("create")?e.current:re(Ee.request,e)})}function ge(){Ee.isMode("create")?(Ee.selectedAbsenceType=Ee.absenceTypes[0],Ee.request.type_id=Ee.selectedAbsenceType.id):Ee.selectedAbsenceType=n.find(Ee.absenceTypes,function(e){return e.id===Ee.request.type_id})}function be(){Te=e.copy(Ee.request.attributes())}function ye(){var e;Ee.request.id?(e=[Ee.requestStatuses[_.statusNames.approved].value,Ee.requestStatuses[_.statusNames.adminApproved].value,Ee.requestStatuses[_.statusNames.rejected].value,Ee.requestStatuses[_.statusNames.cancelled].value],Ee.mode="edit",Ee.isRole("staff")&&e.indexOf(Ee.request.status_id)>-1&&(Ee.mode="view")):Ee.mode="create"}function _e(){var e=Ee.request.status_id;if(!Ee.isMode("view")&&!Ee.submitting)return Ee.submitting=!0,O(),w(),Ee.request.isValid().then(ee()&&I).then(E).then(!Ee.request.change_balance&&pe).then(qe).then(function(){return Ee.isMode("edit")?we():L()}).catch(function(t){Ee.request.status_id=e,t&&W(t)}).finally(function(){Ee.submitting=!1})}function qe(){return r.all(Le.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Ee.request.update().then($e).then(function(){Ee.isRole("manager")?me("LeaveRequest::updatedByManager"):(Ee.isRole("staff")||Ee.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Te={},Se=[],Oe="",Ie="No entitlement",xe="",Le=[],Ee=n.assign(this,f);Ee.absencePeriods=[],Ee.absenceTypes=[],Ee.canManage=!1,Ee.contactName=null,Ee.errors=[],Ee.loading={absenceTypes:!0,entitlements:!0},Ee.managedContacts=[],Ee.mode="",Ee.newStatusOnSave=null,Ee.period={},Ee.postContactSelection=!1,Ee.requestStatuses={},Ee.selectedAbsenceType={},Ee.staffMemberSelectionComplete=!1,Ee.submitting=!1,Ee.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ee.canChangeAbsenceType=T,Ee.canSubmit=S,Ee.closeAlert=x,Ee.deleteLeaveRequest=M,Ee.dismissModal=k,Ee.getStatuses=F,Ee.getStatusFromValue=H,Ee.initAfterContactSelection=G,Ee.initRequestAttributes=X,Ee.isLeaveStatus=te,Ee.isLeaveType=ne,Ee.isMode=ae,Ee.isRole=oe,Ee.submit=_e,Ee.updateAbsenceType=Ae,function(){Ee.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Ee.canManage&&!Ee.isMode("edit")&&le()}).then(function(){if(Ee.selectedContactId&&(Ee.request.contact_id=Ee.selectedContactId),Ee.request.contact_id)return Ee.initAfterContactSelection()}).catch(W).finally(function(){Ee.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){ -return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e){define("leave-absences/manager-leave/modules/config",["common/angular","leave-absences/manager-leave/modules/settings"],function(t){return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/manager-leave/requests"),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","common/services/crm-ang.service","leave-absences/shared/ui-router","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); +!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return U(e)&&e.then&&e.$$promises}if(!U(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!U(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},U(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||F(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!U(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=U(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=F(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:U(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in T)B(T[o])&&(t[o]=T[o](t,T.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),w.current)}).then(null,function(a){return a===D?T:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function T(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:T(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function L(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,T(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return U(n)?e+G(n):(n=t.$eval(n),U(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,U=t.isObject,F=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n){function a(e){e.absencePeriods&&c.absencePeriods.length&&(c.filters.period_id=o().id),e.absenceTypes&&c.absenceTypes.length&&(c.filters.type_id=s().id),(e.loggedInContactId||e.userRole)&&(c.filters.managed_by="manager"===c.userRole?c.loggedInContactId:void 0),r()&&c.submitFilters()}function r(){return e.every(c.filters,function(e){return null!==e})}function o(){return e.find(c.absencePeriods,function(e){return e.current})||c.absencePeriods.reduce(function(e,n){return t(e.end_date).isAfter(n.end_date)?e:n})}function s(){return c.absenceTypes.reduce(function(e,t){return e.title.localeCompare(t.title)?e:t})}function i(e){return e.current?"Current Period ("+e.title+")":e.title}function u(){n.$emit("LeaveBalanceFilters::update",c.filters)}var c=this;c.filters={period_id:null,type_id:null,managed_by:null},c.$onChanges=a,c.labelPeriod=i,c.submitFilters=u}n.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,t){return e.extend({all:function(e,n,a,r,o){return t.getLeaveBalances(this.processFilters(e),n,a,r,o)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){return r.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function p(){return o.all().then(o.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function h(){return s.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function v(){return n.all([m(),p(),h(),g(),q()]).catch(function(e){u.error("Error",e)})}function g(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function b(){return P.loading.report=!0,i.all(w,P.pagination,void 0,void 0,!1).then(function(e){P.report=y(e.list),P.reportCount=e.total}).catch(function(e){u.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function y(n){return n.map(function(n){return n=e.copy(n),n.absence_types=t.indexBy(n.absence_types,function(e){return e.id}),n})}function _(){a.$on("LeaveBalanceFilters::update",C),c.subscribe("LeaveRequest::new",$)}function q(){return f(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function $(e){C(e,w)}function C(e,t){w=t,P.pagination.page=1,A(),P.loadReportCurrentPage()}function A(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+w.type_id})}var w={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.loadReportCurrentPage=b,function(){_(),v().then(function(){P.loading.component=!1})}()}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return f(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(m(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function f(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function m(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){E.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(m).then(T)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function T(){E.selectedMonths=[n().month()]}function S(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=D,function(){S().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return F[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){U.push(r.$on("LeaveCalendar::showMonths",M)),U.push(i.subscribe("LeaveRequest::new",c)),U.push(i.subscribe("LeaveRequest::edit",j)),U.push(i.subscribe("LeaveRequest::updatedByManager",j)),U.push(i.subscribe("LeaveRequest::delete",h)),U.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function T(){return W.month.loading=!0,a.all([O(),S()]).then(g).then(L).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){F=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),U.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function L(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&T())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,U=[],F={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}), +define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){U(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return L()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,U("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(F).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function T(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function L(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(F).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,U("to"))}function U(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function F(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,U("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([L(),E()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(T).then(V).then(P).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function f(){return S.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){T[e.label]=t})})).catch(function(){T=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||S.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],T={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=w,S.canRemoveAttachment=A,S.canSubmit=d,S.canUploadMore=f,S.formatDateTime=m,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){F.filters.leaveRequest.contact_id=null,F.refresh()}function p(){var e=F.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?F.leaveRequests.filter.list.length:F.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(F.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(F.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(F.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(F.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){F.absencePeriods=e.sortBy(t,"start_date"),F.filters.leaveRequest.selectedPeriod=e.find(F.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){F.absenceTypes=e})}function w(e){return(F.isAdmin?r.all(p()):r.leaveManagees(F.contactId,p())).then(function(t){return F.filteredUsers=F.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){F.filters.leaveRequest.leaveStatus!==H&&0===F.leaveRequests.table.list.length&&F.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){F.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:F.pagination,r="filter"===e?{return:["status_id"]}:{};return F.loading[n]=!0,l.all(S(t),a,"from_date DESC",r,!1).then(function(t){F.leaveRequests[e]=t}).catch(function(){F.leaveRequests[e].list=[]}).finally(function(){F.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){F.levelTypes=e})}function T(){return s.valuesOf("hrjc_location").then(function(e){F.locations=e})}function S(t){var n=F.filters.leaveRequest;return{contact_id:E(),managed_by:F.isAdmin&&"me"!==n.assignedTo.type?void 0:F.contactId,status_id:M(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(F.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){F.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){F.leaveRequestStatuses=e.concat(F.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function E(){return F.filteredUsers.length>0&&F.filters.leaveRequest.contact_id?F.filters.leaveRequest.contact_id:{IN:F.filteredUsers.map(function(e){return e.id})}}function L(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function M(e){var t=F.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=L(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(F.filters.leaveRequest.leaveStatus=H),(e<=F.totalNoOfPages()||0===F.totalNoOfPages())&&(F.pagination.page=e,w(n))}function j(e){F.filters.leaveRequest.leaveStatus=e,F.refresh(1,!1,"table")}function B(e){F.filters.leaveRequest.assignedTo=e,F.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){F.refresh()}),f.subscribe("LeaveRequest::new",function(){F.refresh()}),f.subscribe("LeaveRequest::edit",function(){F.refresh()}),f.subscribe("LeaveRequest::delete",function(){F.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){F.refresh()})}function U(){return Math.ceil(F.leaveRequests.table.total/F.pagination.size)}t.debug("Component: manage-leave-requests");var F=this,H={name:"all",label:"All"};F.absencePeriods=[],F.absenceTypes=[],F.filteredUsers=[],F.isFilterExpanded=!1,F.isAdmin=!1,F.leaveRequests={table:{list:[]},filter:{list:[]}},F.leaveRequestStatuses=[H],F.loading={content:!0,page:!0,table:!0},F.pagination={page:1,size:7},F.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],F.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:F.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:F.filtersByAssignee[0]}},F.clearStaffSelection=m,F.countLeaveRequestByStatus=h,F.getAbsenceTypeByID=v,F.getArrayOfSize=g,F.getLeaveStatusByValue=b,F.getNavBadge=y,F.getUserNameByID=q,F.labelPeriod=$,F.openLeavePopup=x,F.refresh=k,F.refreshWithFilter=j,F.refreshWithFilterByAssignee=B,F.totalNoOfPages=U,function(){o(i.permissions.admin.administer).then(function(e){F.isAdmin=e,n.all([C(),A(),O(),P(),T(),R(),I()]).then(function(){F.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):m(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return P(n,e),e})):r.reject([])}function m(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),T(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(A)).then(function(){["from","to"].forEach(function(e){b(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(T)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function $(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return A(e).then(function(){R(e,!0)})})}function A(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function w(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function P(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function D(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),A("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function T(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?A("from").then(function(){R("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=w,s.setDaysSelectionModeExtended=D}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){ +function n(t,n,a,r,o,s){function i(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function u(){return a.all([d(),f(!0)])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function l(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function d(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function f(t){return o.valuesOf("hrleaveandabsences_sickness_reason",t).then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}function m(){r.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=i,s.initChildController=u,s.isChecked=c,s.isDocumentInRequest=l,s.openSicknessReasonOptionsEditor=m}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=U.from_date!==u.request.from_date||U.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&H.hasExpirationFromAdminSettings,t=H.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&u.isCalculationUnit("hours")&&I(),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),B(),l(),x())})})}function D(){u.isMode("view")||(C(),A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function T(){return l(),x(),B()}function S(){return L(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),F?F=!1:x(),B()}function O(e){u.uiOptions.times[e].time=""}function I(){u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours}function x(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function E(){U=e.cloneDeep(u.request.attributes())}function L(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function M(){u.setRequestDateTimesAndDateTypes(),l(),x(),u.isCalculationUnit("hours")?I():u.request.toil_to_accrue=null}function k(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){R(!1)})}function j(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function B(){return m()?d().catch(a.resolve):a.resolve()}function N(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var U,F=!u.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onAbsenceTypeUpdateExtended=M,u.onDateChangeExtended=T,u.openToilInDaysAccrualOptionsEditor=k,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=N,function(){E(),L(),j(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Te.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=D();return Le.isMode("edit")&&(e=e&&(V()||R())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function O(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function I(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==U())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){me("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=U();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Le.requestStatuses[e]})}function U(){return Le.request?Le.request.request_type:Le.leaveType||null}function F(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Te,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?m.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=U(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return xe===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Le.selectedContactId?m.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?m.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Te[e+"_date"]})}function he(e){if(Le.absenceTypes=fe(Pe.types,e),!Le.absenceTypes.length)return r.reject(Ie)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Te=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,O(),w(),Le.request.isValid().then(ee()&&I).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?we():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?me("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Te={},Se=[],Oe="",Ie="No entitlement",xe="",Ee=[],Le=n.assign(this,f);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=T,Le.canSubmit=S,Le.closeAlert=x,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=F,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=Ae,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n), +n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e){define("leave-absences/manager-leave/modules/config",["common/angular","leave-absences/manager-leave/modules/settings"],function(t){return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/manager-leave/requests"),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","common/services/crm-ang.service","leave-absences/shared/ui-router","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js index 0228c260520..7d052a0dac6 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js @@ -9,6 +9,6 @@ !function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[m]),c[r[m]]=e[r[m]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&f(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,f),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),f.$$values=b,f.$$promises=f.$$promises||!0,delete f.$$inheritedValues,c.resolve(b))}function u(e){f.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),f=c.promise,g=f.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),f;o.$$inheritedValues&&r(b,m(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,m(o.$$values,h)),f.$$inheritedValues=m(o.$$values,h),i()):(o.$$inheritedValues&&(f.$$inheritedValues=m(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(f.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),m=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(m++,g[e].then(function(t){b[e]=t,--m||l()},c))}),m||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return f}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(m,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",m=0,f=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),f.push(g.segment),m=c.lastIndex;y=e.substring(m);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,m+_),q.length>0)for(m=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),m=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",f.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=f[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:m}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,m=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(m=e),m},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(f(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function m(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),f(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:m})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(D.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!D[r])return f(r,t.self);for(var o in R)B(R[o])&&(t[o]=R[o](t,R.$delegates[o]));return D[n]=t,!t[T]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){A.$current.navigable==t&&c(e,n)||A.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=A.$current.name.split("."),a=0,r=t.length;a=D;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=D;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.$current=t,A.current=t.self,A.params=n,V(A.params,f),A.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),A.current)}).then(null,function(a){return a===P?R:A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},A.is=function(e,t,a){a=W({relative:A.$current},a||{});var r=m(e,a.relative);return j(r)?A.$current===r&&(!t||c(r.params.$$values(t),f)):n},A.includes=function(e,t,a){if(a=W({relative:A.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=A.$current.name}var r=m(e,a.relative);if(!j(r))return n;if(!j(A.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(m&&(m.remove(),m=null),p&&(p.$destroy(),p=null),f){var e=f.data("$uiViewAnim");b.leave(f,function(){e.$$animLeave.resolve(),m=null}),m=f,f=null}}function d(s){var d,m=P(n,c,i,r),y=m&&e.$current&&e.$current.locals[m];if(s||y!==h){d=n.$new(),h=e.$current.locals[m],d.$emit("$viewContentLoading",m);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});f=_,p=d,p.$emit("$viewContentLoaded",m),p.$eval(v)}}var m,f,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function D(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=P(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var m=t.extend({},d);o[d.$$resolveAs]=m;var f=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=m),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}f(o)}}}}}function P(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function T(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function R(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function x(e,t){return{relative:R(e)||t.$current,inherit:!0}}function I(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=T(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],m=null;c.options=W(x(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var f=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),m&&m(),d&&(m=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&f(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),f(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){m.state=t[0],m.params=t[1],m.options=t[2],m.href=e.href(m.state,m.params,m.options),f&&f(),c&&(f=c.$$addStateInfo(m.state,m.params)),m.href&&r.$set(u.attr,m.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",m={state:null,params:null,options:null,href:null},f=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return m}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function L(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,R(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function m(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,m){function f(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(D(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||T()})}function h(e){E.injectMonths=!0,O("injected").then(function(){T(e)}).then(function(){E.loading.calendar=!1})}function v(){x=a("LeaveCalendar"+t.capitalize(I)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(f).then(R)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return x.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function w(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function D(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function P(e){ e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(A).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function T(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function R(){E.selectedMonths=[n().month()]}function S(){return E.roleOverride?r.resolve().then(function(){I=E.roleOverride}):r.all([m(i.permissions.admin.administer),m(i.permissions.ssp.manage)]).then(function(e){I=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var x,I,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=P,function(){S().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),w()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function m(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?f():p()}function f(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),m(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function m(e){return U[e]}function f(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){x(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",M)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function w(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function D(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function P(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function T(){return[P(u.statusNames.approved),P(u.statusNames.adminApproved),P(u.statusNames.awaitingApproval),P(u.statusNames.moreInformationRequired)]}function R(){return W.month.loading=!0,a.all([O(),S()]).then(g).then(L).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:T()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function x(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function I(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=m(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?w(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function L(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&R())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=D(e);t&&(h(t),-1!==T().indexOf(e.status_id)&&c(e))}function B(e){return a.all(A(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=I,W.contactsList=f,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return L()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(A).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function w(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(A)}function A(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function D(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():w()}function P(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function T(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function R(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function x(e){return te.request.request_type===e}function I(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function L(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(A).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,f(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(x("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||x("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=A,te.isCalculationUnit=O,te.isLeaveType=x,te.isNotWorkingDay=I,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),T(),te.initChildController().then(function(){return s.all([L(),E()])}).then(!te.isMode("create")&&P).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(R).then(V).then(D).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(A).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function m(){return S.getFilesAmount()0?P.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(P.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){R[e.label]=t})})).catch(function(){R=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){P=e})}function w(e){return!e.attachment_id||S.canManage}function A(){e.forEach(T,function(e){e()})}function D(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var P=[],T=[],R={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=A,S.canRemoveAttachment=w,S.canSubmit=d,S.canUploadMore=m,S.formatDateTime=f,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,r,o,s,i,u,c,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){k(e),H.sections.other.open&&f(e,H.sections.other)}function h(){Object.values(H.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):H.refresh()}function g(t){t.dataIndex=e.indexBy(t.data,"id")}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function y(){return o.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.selectedPeriod=e.find(H.absencePeriods,function(e){return!0===e.current})})}function _(){return s.all().then(s.loadCalculationUnits).then(function(t){H.absenceTypes=t,H.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return P("approved",{status_id:F(m.statusNames.approved)})}function $(){return n.all([u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,null,!0),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.approved)]),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){H.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function C(){return i.all({contact_id:H.contactId,period_id:H.selectedPeriod.id},!0).then(function(e){H.entitlements=e}).then(function(){H.absenceTypesFiltered=H.absenceTypes.filter(function(t){var n=e.find(H.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function w(){return i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id},H.entitlements).then(function(){return E(H.entitlements)}).then(function(e){H.sections.entitlements.data=e})}function A(){return n.all([i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id,expired:!0}),D({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:E(e[0]),expiredTOILS:L(e[1].list)})}).then(function(t){ -H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function D(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function P(e,t){return D(t).then(function(t){H.sections[e].data=t.list})}function T(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(x))}function R(){return P("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function S(){return P("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function O(){return P("holidays",{public_holiday:!0})}function x(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function I(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function E(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function L(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){k(e)})}function k(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([C(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([T(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&x(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:k,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([I(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([C(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return D(n,e),e})):r.reject([])}function f(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),R(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(w)).then(function(){["from","to"].forEach(function(e){b(e),T(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(R)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&T(e,!0))})}function $(e,t){return m(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return w(e).then(function(){T(e,!0)})})}function w(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function A(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function D(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function P(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),w("from").then(function(){T("from",!0)})):r.resolve()}function T(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function R(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?w("from").then(function(){T("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=A,s.setDaysSelectionModeExtended=P}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o){function s(){return!(!o.canCalculateChange()||!o.request.sickness_reason)}function i(){return a.all([l(),d()])}function u(t){var n=o.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(o.sicknessDocumentTypes,function(e){return e.value===t})}function l(){return r.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){o.sicknessDocumentTypes=e})}function d(){return r.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){o.sicknessReasons=e.indexBy(t,"name")})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:o}),o.canSubmit=s,o.initChildController=i,o.isChecked=u,o.isDocumentInRequest=c}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function m(){return!!u.request.toil_to_accrue}function f(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=F.from_date!==u.request.from_date||F.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&H.hasExpirationFromAdminSettings,t=H.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(T)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function w(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&u.isCalculationUnit("hours")&&x(),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function A(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function D(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),B(),l(),I())})})}function P(){u.isMode("view")||(C(),w(),D())}function T(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function R(){return l(),I(),B()}function S(){return L(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),U?U=!1:I(),B()}function O(e){u.uiOptions.times[e].time=""}function x(){u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours}function I(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function E(){F=e.cloneDeep(u.request.attributes())}function L(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function M(){u.setRequestDateTimesAndDateTypes(),l(),I(),u.isCalculationUnit("hours")?x():u.request.toil_to_accrue=null}function k(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){T(!1)})}function j(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function B(){return f()?d().catch(a.resolve):a.resolve()}function N(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var F,U=!u.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=m,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=A,u.initWatchersExtended=P,u.onAbsenceTypeUpdateExtended=M,u.onDateChangeExtended=R,u.openToilInDaysAccrualOptionsEditor=k,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=N,function(){E(),L(),j(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,m,f,p,h,v,g,b,y,_,q,$,C){function w(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function A(){["from","to"].forEach(w)}function D(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Re.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=P();return Le.isMode("edit")&&(e=e&&(V()||T())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function O(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function x(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==F())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function I(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){fe("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(Pe[e],function(e){return Le.requestStatuses[e]})}function F(){return Le.request?Le.request.request_type:Le.leaveType||null}function U(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Re,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==xe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Pe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Pe.awaiting_approval=e,Pe.more_information_required=e,Pe.rejected=e,Pe.approved=e,Pe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?f.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Te++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=F(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:Oe}),e}function Q(){if(Ie="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Ie="admin")}).then(function(){return"staff"===Ie&&u(_.permissions.ssp.manage).then(function(e){e&&(Ie="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Ie===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){De={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:De.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Le.selectedContactId?f.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?f.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):f.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){D(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Re[e+"_date"]})}function he(e){if(Le.absenceTypes=me(De.types,e),!Le.absenceTypes.length)return r.reject(xe)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Re=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,O(),A(),Le.request.isValid().then(ee()&&x).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?Ae():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Te&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Te>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function we(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?fe("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var De,Pe={},Te=0,Re={},Se=[],Oe="",xe="No entitlement",Ie="",Ee=[],Le=n.assign(this,m);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=R,Le.canSubmit=S,Le.closeAlert=I,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=U,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=we,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM), +H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function D(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function P(e,t){return D(t).then(function(t){H.sections[e].data=t.list})}function T(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(x))}function R(){return P("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function S(){return P("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function O(){return P("holidays",{public_holiday:!0})}function x(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function I(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function E(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function L(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){k(e)})}function k(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([C(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([T(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&x(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:k,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([I(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([C(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function c(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function l(){return s.canCalculateChange()}function d(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=s.convertDateToServerFormat(t),i.isPublicHoliday(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):f(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return D(n,e),e})):r.reject([])}function f(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function p(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(){return r.resolve()}function v(){return $(s.uiOptions.fromDate,"from").then(function(){return $(s.uiOptions.toDate,"to")})}function g(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),R(),s.performBalanceChangeCalculation())})}function b(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(p(a.min,n)<=0||p(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function y(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(w)).then(function(){["from","to"].forEach(function(e){b(e),T(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(R)}function _(){["from","to"].forEach(function(e){g(e),q(e)})}function q(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&T(e,!0))})}function $(e,t){return m(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function C(e){return $(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return w(e).then(function(){T(e,!0)})})}function w(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){O[e]=t,d(e,t),n&&"from"===e&&d("to",t)}).catch(function(t){return O[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function A(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function D(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function P(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),w("from").then(function(){T("from",!0)})):r.resolve()}function T(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=O[a].number_of_hours?p(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function R(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?w("from").then(function(){T("from",!0)}):r.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=u,s.canCalculateChange=c,s.canSubmit=l,s.initChildController=h,s.initDayTypesExtended=v,s.initTimesExtended=y,s.initWatchersExtended=_,s.onAbsenceTypeUpdateExtended=S,s.onDateChangeExtended=C,s.resetUIInputsExtended=A,s.setDaysSelectionModeExtended=P}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s){function i(){return!(!s.canCalculateChange()||!s.request.sickness_reason)}function u(){return a.all([d(),m(!0)])}function c(t){var n=s.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function l(t){return!!e.find(s.sicknessDocumentTypes,function(e){return e.value===t})}function d(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){s.sicknessDocumentTypes=e})}function m(t){return o.valuesOf("hrleaveandabsences_sickness_reason",t).then(function(t){s.sicknessReasons=e.indexBy(t,"name")})}function f(){r.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){m(!1)})}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:s}),s.canSubmit=i,s.initChildController=u,s.isChecked=c,s.isDocumentInRequest=l,s.openSicknessReasonOptionsEditor=f}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function m(){return!!u.request.toil_to_accrue}function f(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=F.from_date!==u.request.from_date||F.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&H.hasExpirationFromAdminSettings,t=H.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(T)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function w(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&u.isCalculationUnit("hours")&&x(),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function A(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function D(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),B(),l(),I())})})}function P(){u.isMode("view")||(C(),w(),D())}function T(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function R(){return l(),I(),B()}function S(){return L(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),U?U=!1:I(),B()}function O(e){u.uiOptions.times[e].time=""}function x(){u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours}function I(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function E(){F=e.cloneDeep(u.request.attributes())}function L(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function M(){u.setRequestDateTimesAndDateTypes(),l(),I(),u.isCalculationUnit("hours")?x():u.request.toil_to_accrue=null}function k(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){T(!1)})}function j(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function B(){return f()?d().catch(a.resolve):a.resolve()}function N(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var F,U=!u.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=m,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=A,u.initWatchersExtended=P,u.onAbsenceTypeUpdateExtended=M,u.onDateChangeExtended=R,u.openToilInDaysAccrualOptionsEditor=k,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=N,function(){E(),L(),j(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,m,f,p,h,v,g,b,y,_,q,$,C){function w(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function A(){["from","to"].forEach(w)}function D(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Re.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=P();return Le.isMode("edit")&&(e=e&&(V()||T())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function O(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function x(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==F())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function I(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){fe("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(Pe[e],function(e){return Le.requestStatuses[e]})}function F(){return Le.request?Le.request.request_type:Le.leaveType||null}function U(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Re,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==xe)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Pe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Pe.awaiting_approval=e,Pe.more_information_required=e,Pe.rejected=e,Pe.approved=e,Pe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?f.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Te++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=F(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:Oe}),e}function Q(){if(Ie="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Ie="admin")}).then(function(){return"staff"===Ie&&u(_.permissions.ssp.manage).then(function(e){e&&(Ie="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date)&&r.isSameOrBefore(t.end_date)}function oe(e){return Ie===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){De={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:De.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Le.selectedContactId?f.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?f.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):f.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){D(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Re[e+"_date"]})}function he(e){if(Le.absenceTypes=me(De.types,e),!Le.absenceTypes.length)return r.reject(xe)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Re=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,O(),A(),Le.request.isValid().then(ee()&&x).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?Ae():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Te&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Te>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function we(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?fe("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var De,Pe={},Te=0,Re={},Se=[],Oe="",xe="No entitlement",Ie="",Ee=[],Le=n.assign(this,m);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=R,Le.canSubmit=S,Le.closeAlert=I,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=U,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=we,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM), define("leave-absences/my-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/models/option-group","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/my-leave/components/my-leave-container.component","leave-absences/my-leave/modules/config"],function(e){return e.module("my-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.mocks","common.models","common.services","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","my-leave.components","my-leave.config"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/my-leave":n+"/my-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/my-leave/app"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-my-leave]"),["my-leave"])})})}(CRM,require),define("my-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component.js index d24c0f46db8..15f03698260 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component.js @@ -13,10 +13,10 @@ define([ return settings.pathTpl + 'components/absence-tab-custom-work-pattern-modal.html'; }], controllerAs: 'workPatternModal', - controller: ['$log', '$q', '$rootScope', 'OptionGroup', 'shared-settings', 'WorkPatternAPI', controller] + controller: ['$log', '$q', '$rootScope', 'crmAngService', 'OptionGroup', 'shared-settings', 'WorkPatternAPI', controller] }); - function controller ($log, $q, $rootScope, OptionGroup, sharedSettings, WorkPatternAPI) { + function controller ($log, $q, $rootScope, crmAngService, OptionGroup, sharedSettings, WorkPatternAPI) { $log.debug('Component: absence-tab-custom-work-pattern-modal'); var vm = Object.create(this); @@ -40,11 +40,12 @@ define([ } } }; + vm.openWorkPatternChangeReason = openWorkPatternChangeReason; (function init () { return $q.all([ loadWorkPatterns(), - loadJobContractRevisionChangeReasons() + loadJobContractRevisionChangeReasons(true) ]) .finally(function () { vm.loading.content = false; @@ -109,15 +110,26 @@ define([ /** * Loads the Leave and Absences Work Pattern Change Reasons * + * @param {Boolean} cache if to cache results of the API call, cache by default * @return {Promise} resolves with {Array} */ - function loadJobContractRevisionChangeReasons () { - return OptionGroup.valuesOf('hrleaveandabsences_work_pattern_change_reason') + function loadJobContractRevisionChangeReasons (cache) { + return OptionGroup.valuesOf('hrleaveandabsences_work_pattern_change_reason', cache) .then(function (reasons) { vm.changeReasons = reasons; }); } + /** + * Opens the work pattern change reasons for editing + */ + function openWorkPatternChangeReason () { + crmAngService.loadForm('/civicrm/admin/options/hrleaveandabsences_work_pattern_change_reason?reset=1') + .on('crmUnload', function () { + loadJobContractRevisionChangeReasons(false); + }); + } + return vm; } }); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller.js index e7d812099d5..be74e5a369a 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller.js @@ -6,9 +6,11 @@ define([ ], function (_, controllers) { controllers.controller('RequestModalDetailsSicknessController', RequestModalDetailsSicknessController); - RequestModalDetailsSicknessController.$inject = ['$controller', '$log', '$q', 'api.optionGroup', 'detailsController']; + RequestModalDetailsSicknessController.$inject = ['$controller', '$log', '$q', 'crmAngService', 'api.optionGroup', + 'detailsController']; - function RequestModalDetailsSicknessController ($controller, $log, $q, OptionGroup, detailsController) { + function RequestModalDetailsSicknessController ($controller, $log, $q, crmAngService, + OptionGroup, detailsController) { $log.debug('RequestModalDetailsSicknessController'); // Shares basic logic with the the leave controller $controller('RequestModalDetailsLeaveController', { detailsController: detailsController }); @@ -17,6 +19,7 @@ define([ detailsController.initChildController = initChildController; detailsController.isChecked = isChecked; detailsController.isDocumentInRequest = isDocumentInRequest; + detailsController.openSicknessReasonOptionsEditor = openSicknessReasonOptionsEditor; /** * Checks if submit button can be enabled for user and returns true if successful @@ -35,7 +38,7 @@ define([ function initChildController () { return $q.all([ loadDocuments(), - loadReasons() + loadReasons(true) ]); } @@ -84,11 +87,21 @@ define([ * * @return {Promise} */ - function loadReasons () { - return OptionGroup.valuesOf('hrleaveandabsences_sickness_reason') + function loadReasons (cache) { + return OptionGroup.valuesOf('hrleaveandabsences_sickness_reason', cache) .then(function (reasons) { detailsController.sicknessReasons = _.indexBy(reasons, 'name'); }); } + + /** + * Opens editor for sickness reason options editing + */ + function openSicknessReasonOptionsEditor () { + crmAngService.loadForm('/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1') + .on('crmUnload', function () { + loadReasons(false); + }); + } } }); diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/absence-tab/components/absence-tab-custom-work-pattern-modal.component.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/absence-tab/components/absence-tab-custom-work-pattern-modal.component.spec.js index ab1035522cb..5219edc4aaa 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/absence-tab/components/absence-tab-custom-work-pattern-modal.component.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/absence-tab/components/absence-tab-custom-work-pattern-modal.component.spec.js @@ -8,7 +8,7 @@ 'leave-absences/mocks/data/work-pattern.data', 'leave-absences/mocks/apis/work-pattern-api-mock', 'leave-absences/absence-tab/app' - ], function (angular, _, optionGroupMock, workPatternData) { + ], function (angular, _, optionGroupMock, workPatternData, crmAngService) { 'use strict'; describe('absenceTabWorkPatterns', function () { @@ -22,12 +22,13 @@ beforeEach(inject(function (WorkPatternAPIMock) { $provide.value('WorkPatternAPI', WorkPatternAPIMock); })); - beforeEach(inject(function (_$componentController_, _$log_, _$q_, _$rootScope_, _OptionGroup_, _WorkPatternAPI_) { + beforeEach(inject(function (_$componentController_, _$log_, _$q_, _$rootScope_, _OptionGroup_, _WorkPatternAPI_, _crmAngService_) { $componentController = _$componentController_; $log = _$log_; $q = _$q_; $rootScope = _$rootScope_; OptionGroup = _OptionGroup_; + crmAngService = _crmAngService_; WorkPatternAPI = _WorkPatternAPI_; @@ -50,7 +51,7 @@ describe('init()', function () { it('fetches values of the Work Pattern Change Reason option group', function () { - expect(OptionGroup.valuesOf).toHaveBeenCalledWith('hrleaveandabsences_work_pattern_change_reason'); + expect(OptionGroup.valuesOf).toHaveBeenCalledWith('hrleaveandabsences_work_pattern_change_reason', true); }); it('loads change reasons', function () { @@ -141,6 +142,28 @@ }); }); + describe('when users click on the reason for change wrench icon', function () { + var onPopupFormSuccess; + var url = '/civicrm/admin/options/hrleaveandabsences_work_pattern_change_reason?reset=1'; + + beforeEach(function () { + spyOn(crmAngService, 'loadForm').and.callFake(function () { + return { + on: function (event, callback) { + if (event === 'crmUnload') { + onPopupFormSuccess = callback; + } + } + }; + }); + controller.openWorkPatternChangeReason(); + }); + + it('calls the crmAngService with the requested url', function () { + expect(crmAngService.loadForm).toHaveBeenCalledWith(url); + }); + }); + function compileComponent () { controller = $componentController('absenceTabCustomWorkPatternModal', null, { contactId: CRM.vars.leaveAndAbsences.contactId, diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-sickness.controller.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-sickness.controller.spec.js index 7be8861140c..1f9371268d2 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-sickness.controller.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-sickness.controller.spec.js @@ -11,8 +11,9 @@ define([ 'leave-absences/mocks/helpers/helper', 'leave-absences/mocks/helpers/request-modal-helper', 'leave-absences/mocks/apis/option-group-api-mock', - 'leave-absences/manager-leave/app' -], function (angular, _, moment, absencePeriodData, absenceTypeData, leaveRequestData, optionGroupMock, helper, requestModalHelper) { + 'leave-absences/manager-leave/app', + 'leave-absences/shared/modules/shared-settings' +], function (angular, _, moment, absencePeriodData, absenceTypeData, leaveRequestData, optionGroupMock, helper, requestModalHelper, crmAngService) { 'use strict'; describe('RequestModalDetailsSicknessController', function () { @@ -40,10 +41,11 @@ define([ }])); beforeEach(inject(function ( - _$componentController_, _$log_, _$rootScope_, _SicknessRequestInstance_) { + _$componentController_, _$log_, _$rootScope_, _crmAngService_, _SicknessRequestInstance_) { $componentController = _$componentController_; $log = _$log_; $rootScope = _$rootScope_; + crmAngService = _crmAngService_; SicknessRequestInstance = _SicknessRequestInstance_; spyOn($log, 'debug'); @@ -110,6 +112,36 @@ define([ }); }); + describe('when users click on the sick reason wrench icon', function () { + var onPopupFormSuccess; + var url; + var sicknessReasons; + + beforeEach(function () { + url = '/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1'; + sicknessReasons = optionGroupMock.getCollection('hrleaveandabsences_sickness_reason'); + + spyOn(crmAngService, 'loadForm').and.callFake(function () { + return { + on: function (event, callback) { + if (event === 'crmUnload') { + onPopupFormSuccess = callback; + } + } + }; + }); + controller.openSicknessReasonOptionsEditor(); + }); + + it('calls the crmAngService with the requested url', function () { + expect(crmAngService.loadForm).toHaveBeenCalledWith(url); + }); + + it('loads the sickness reasons', function () { + expect(controller.sicknessReasons).toEqual(_.indexBy(sicknessReasons, 'name')); + }); + }); + describe('open sickness request in edit mode', function () { var sicknessRequest; diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Form/WorkPattern/Calendar.tpl b/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Form/WorkPattern/Calendar.tpl index d9f262e6ac8..62d46a13190 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Form/WorkPattern/Calendar.tpl +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/templates/CRM/HRLeaveAndAbsences/Form/WorkPattern/Calendar.tpl @@ -78,7 +78,16 @@
    {$form.weeks[$smarty.section.i.index].days.6.number_of_hours.html}
    {ts}Leave days{/ts} {help id="id-leave-days"} + {ts}Leave days{/ts} {help id="id-leave-days"} + + + + {$form.weeks[$smarty.section.i.index].days.0.leave_days.html} {$form.weeks[$smarty.section.i.index].days.1.leave_days.html} {$form.weeks[$smarty.section.i.index].days.2.leave_days.html}
    - - From 4439171bba379721bc3bc95e681361d3bffa0fa8 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Fri, 27 Apr 2018 10:51:54 +0100 Subject: [PATCH 179/203] PCHR-3581: Improve code --- .../leave-calendar-day.component.js | 176 ++++++++---------- .../leave-calendar-month.component.js | 2 - 2 files changed, 76 insertions(+), 102 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-day.component.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-day.component.js index 61e80aba389..ce9d96bfc1c 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-day.component.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-day.component.js @@ -29,33 +29,9 @@ define([ vm.openLeavePopup = openLeavePopup; (function init () { - watchForLeaveRequestReady(); + watchLeaveRequests(); })(); - /** - * Given an array of records, finds and returns the one that matches the - * id field with the comparison value. - * - * @param {Array} records - An array of objects to filter. - * @param {String} idFieldName - the name for the ID field. - * @param {any} value - The comparison value to match against the ID. - * - * @return {Object} - */ - function findRecordByIdFieldValue (records, idFieldName, value) { - return _.find(records, function (record) { - return +record[idFieldName] === +value; - }); - } - - /** - * Gets the absence type for the leave request. - */ - function getLeaveRequestAbsenceType (leaveRequest) { - return findRecordByIdFieldValue(vm.supportData.absenceTypes, - 'id', leaveRequest.type_id); - } - /** * Opens the leave request popup * @@ -85,8 +61,10 @@ define([ * @return {String} */ function resolveDayLabelForDaysCalculationUnit (leaveRequestAttributes) { - return leaveRequestAttributes.isAM ? 'AM' - : leaveRequestAttributes.isPM ? 'PM' + return leaveRequestAttributes.isAM + ? 'AM' + : leaveRequestAttributes.isPM + ? 'PM' : ''; } @@ -115,96 +93,98 @@ define([ : ''; } - /** - * Determines a label for the leave request depending on the calculation unit - * or if it's an accrued TOIL request. - * - * @param {LeaveRequestInstance} leaveRequest - * @param {Object} leaveRequestAttributes - * @return {String} - */ - function resolveLeaveRequestLabel (leaveRequest, leaveRequestAttributes) { - if (leaveRequestAttributes.isAccruedTOIL) { - return 'AT'; - } else if (leaveRequestAttributes.unit === 'days') { - return resolveDayLabelForDaysCalculationUnit(leaveRequestAttributes); - } else { - return resolveDayLabelForHoursCalculationUnit(leaveRequest); - } - } - /** * Sets absence types titles to leave requests attributes + * + * @param {LeaveRequestInstance} leaveRequest + * @param {Object} leaveRequestAttributes */ - function resolveLeaveRequestsAbsenceTypesTitles () { - vm.contactData.leaveRequests.forEach(function (leaveRequest) { - vm.contactData.leaveRequestsAttributes[leaveRequest.id].absenceTypeTitle = - getLeaveRequestAbsenceType(leaveRequest).title; - }); + function resolveLeaveRequestAbsenceTypeTitle (leaveRequest, leaveRequestAttributes) { + vm.contactData.leaveRequestsAttributes[leaveRequest.id].absenceTypeTitle = + _.find(vm.supportData.absenceTypes, { id: leaveRequest.type_id }).title; } /** - * Determines labels for each leave request depending on the calculation unit - * or if it's an accrued TOIL request and sets them to leave requests attributes. + * Sets a unit name to the leave requests attributes + * + * @param {LeaveRequestInstance} leaveRequest + * @param {Object} leaveRequestAttributes */ - function resolveLeaveRequestsLabels () { - var leaveRequestAttributes; + function resolveLeaveRequestCalculationUnit (leaveRequest, leaveRequestAttributes) { + var absenceType = _.find(vm.supportData.absenceTypes, { id: leaveRequest.type_id }); + var calculationUnit = _.find(vm.supportData.calculationUnits, { 'value': absenceType.calculation_unit }); - vm.contactData.leaveRequests.forEach(function (leaveRequest) { - leaveRequestAttributes = vm.contactData.leaveRequestsAttributes[leaveRequest.id]; - leaveRequestAttributes.label = - resolveLeaveRequestLabel(leaveRequest, leaveRequestAttributes); - }); + leaveRequestAttributes.unit = calculationUnit.name; } /** - * Sets a unit name to the leave requests attributes + * Sets dates from leave requests to leave requests attributes + * by converting them from String to Date type. + * + * @param {LeaveRequestInstance} leaveRequest + * @param {Object} leaveRequestAttributes */ - function resolveLeaveRequestsCalculationUnits () { - var leaveRequestAttributes, absenceType, calculationUnit; - - vm.contactData.leaveRequests.forEach(function (leaveRequest) { - leaveRequestAttributes = vm.contactData.leaveRequestsAttributes[leaveRequest.id]; - absenceType = _.find(vm.supportData.absenceTypes, { id: leaveRequest.type_id }); - calculationUnit = _.find(vm.supportData.calculationUnits, { 'value': absenceType.calculation_unit }); - leaveRequestAttributes.unit = calculationUnit.name; - }); + function resolveLeaveRequestDates (leaveRequest, leaveRequestAttributes) { + leaveRequestAttributes.from_date = new Date(leaveRequest.from_date); + leaveRequestAttributes.to_date = new Date(leaveRequest.to_date); } /** - * Sets dates from leave requests to leave requests attributes - * by converting them from String to Date type. + * Sets the from and to date type labels to the leave requests attributes. + * + * @param {LeaveRequestInstance} leaveRequest + * @param {Object} leaveRequestAttributes */ - function resolveLeaveRequestsDates () { - var leaveRequestAttributes; - - vm.contactData.leaveRequests.forEach(function (leaveRequest) { - leaveRequestAttributes = vm.contactData.leaveRequestsAttributes[leaveRequest.id]; - leaveRequestAttributes.from_date = - new Date(leaveRequest.from_date); - leaveRequestAttributes.to_date = - new Date(leaveRequest.to_date); - }); + function resolveLeaveRequestDateTypes (leaveRequest, leaveRequestAttributes) { + if (leaveRequestAttributes.unit !== 'days') { + return; + } + + leaveRequestAttributes['from_date_type'] = + _.find(vm.supportData.dayTypes, { value: leaveRequest.from_date_type }).label; + leaveRequestAttributes['to_date_type'] = + _.find(vm.supportData.dayTypes, { value: leaveRequest.to_date_type }).label; } /** - * Sets the from and to date type labels to the leave requests attributes. + * Determines a label for the leave request depending on the calculation unit + * or if it's an accrued TOIL request. + * + * @param {LeaveRequestInstance} leaveRequest + * @param {Object} leaveRequestAttributes */ - function resolveLeaveRequestsTypes () { - var leaveRequestAttributes, fromDateType, toDateType; + function resolveLeaveRequestLabel (leaveRequest, leaveRequestAttributes) { + var label = ''; - vm.contactData.leaveRequests.forEach(function (leaveRequest) { - leaveRequestAttributes = vm.contactData.leaveRequestsAttributes[leaveRequest.id]; + if (leaveRequestAttributes.isAccruedTOIL) { + label = 'AT'; + } else if (leaveRequestAttributes.unit === 'days') { + label = resolveDayLabelForDaysCalculationUnit(leaveRequestAttributes); + } else { + label = resolveDayLabelForHoursCalculationUnit(leaveRequest); + } - if (leaveRequestAttributes.unit === 'days') { - fromDateType = findRecordByIdFieldValue(vm.supportData.dayTypes, - 'value', leaveRequest.from_date_type); - toDateType = findRecordByIdFieldValue(vm.supportData.dayTypes, - 'value', leaveRequest.to_date_type); + leaveRequestAttributes.label = label; + } - leaveRequestAttributes['from_date_type'] = fromDateType.label; - leaveRequestAttributes['to_date_type'] = toDateType.label; - } + /** + * Sets additional data needed for UI to leave requests attributes + * + * @param {LeaveRequestInstance} leaveRequest + */ + function resolveLeaveRequestsAdditionalUIData (leaveRequest) { + var leaveRequestAttributes = + vm.contactData.leaveRequestsAttributes[leaveRequest.id]; + var resolvingFunctions = [ + resolveLeaveRequestCalculationUnit, + resolveLeaveRequestDateTypes, + resolveLeaveRequestLabel, + resolveLeaveRequestDates, + resolveLeaveRequestAbsenceTypeTitle + ]; + + resolvingFunctions.forEach(function (resolvingFunction) { + resolvingFunction.call(this, leaveRequest, leaveRequestAttributes); }); } @@ -212,14 +192,10 @@ define([ * Waits for the leave request to be accesible before mapping the necessary * leave request fields to it. */ - function watchForLeaveRequestReady () { + function watchLeaveRequests () { $scope.$watch('day.contactData.leaveRequests', function () { if (vm.contactData && vm.contactData.leaveRequests) { - resolveLeaveRequestsCalculationUnits(); - resolveLeaveRequestsTypes(); - resolveLeaveRequestsLabels(); - resolveLeaveRequestsDates(); - resolveLeaveRequestsAbsenceTypesTitles(); + vm.contactData.leaveRequests.forEach(resolveLeaveRequestsAdditionalUIData); } }, true); } diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-month.component.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-month.component.js index 1ceaa3a1982..381f5b58990 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-month.component.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-month.component.js @@ -362,8 +362,6 @@ define([ .then(setMonthDaysContactData) .then(function () { dataLoaded = true; - }) - .then(function () { vm.month.loading = false; }); } From 3e7e2cfbb4c020521262983dab34b0e9a3102d9b Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Fri, 27 Apr 2018 11:20:05 +0100 Subject: [PATCH 180/203] PCHR-3581: Add missing tests and improve tests --- .../leave-calendar-month.component.spec.js | 105 ++++++++++++++---- 1 file changed, 82 insertions(+), 23 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-month.component.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-month.component.spec.js index cb0ae0e6258..f6d567818ac 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-month.component.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-month.component.spec.js @@ -23,7 +23,7 @@ describe('leaveCalendarMonth', function () { var $componentController, $log, $provide, $q, $rootScope, Calendar, LeaveRequest, OptionGroup, controller, daysInFebruary, february, leaveRequestInFebruary, - period2016, publicHolidays, pubSub, contactData, leaveRequestAttributes; + period2016, publicHolidays, pubSub, contactData, leaveRequest, leaveRequestAttributes; var currentContactId = CRM.vars.leaveAndAbsences.contactId; var contactIdsToReduceTo = null; @@ -445,8 +445,52 @@ }); }); + describe('when the contact has multiple leave requests on the same day', function () { + var leaveRequest1, leaveRequest2; + + describe('basic tests', function () { + beforeEach(function () { + leaveRequest1 = _.clone(LeaveRequestData.singleDataSuccess().values[0]); + leaveRequest2 = _.clone(LeaveRequestData.singleDataSuccess().values[0]); + + commonSetup([leaveRequest1, leaveRequest2]); + }); + + it('has leave requests references in the contact data', function () { + expect(contactData.leaveRequests.length).toBe(2); + expect(contactData.leaveRequests[0]).toBe(leaveRequest1); + expect(contactData.leaveRequests[1]).toBe(leaveRequest2); + }); + + it('keeps references to leave requests to show in day cell', function () { + expect(contactData.leaveRequestsToShowInCell.length).toBe(2); + expect(contactData.leaveRequestsToShowInCell[0]).toBe(leaveRequest1); + expect(contactData.leaveRequestsToShowInCell[1]).toBe(leaveRequest2); + }); + }); + + describe('when day contains a mix of TOIL and non-TOIL requests', function () { + beforeEach(function () { + leaveRequest1 = _.clone(LeaveRequestData.singleDataSuccess().values[0]); + leaveRequest2 = _.clone(LeaveRequestData.singleDataSuccess().values[0]); + leaveRequest2.request_type = 'toil'; + + commonSetup([leaveRequest1, leaveRequest2]); + }); + + it('only shows toil requests in the day cell', function () { + expect(contactData.leaveRequestsToShowInCell.length).toBe(1); + expect(contactData.leaveRequestsToShowInCell[0]).toBe(leaveRequest2); + }); + + it('still has all leave request references', function () { + expect(contactData.leaveRequests.length).toBe(2); + }); + }); + }); + describe('when the contact has recorded a leave request on the day', function () { - var leaveRequest, workPattern; + var workPattern; beforeEach(function () { leaveRequest = _.clone(LeaveRequestData.singleDataSuccess().values[0]); @@ -470,6 +514,10 @@ expect(contactData.leaveRequests[0]).toBe(leaveRequest); }); + it('adds a reference to the leave request to show it in the day cell', function () { + expect(contactData.leaveRequestsToShowInCell[0]).toBe(leaveRequest); + }); + it('assigns it the colors of its absence type', function () { var absenceTypeColor = _.find(controller.supportData.absenceTypes, function (absenceType) { return absenceType.id === leaveRequest.type_id; @@ -535,27 +583,6 @@ expect(leaveRequestAttributes.isAccruedTOIL).toBe(true); }); }); - - function commonSetup () { - var day; - - LeaveRequest.all.and.callFake(function () { - return $q.resolve({ list: [leaveRequest] }); - }); - - compileComponent(true); - - controller.month.days.forEach(function (dayObj) { - if (moment(dayObj.date).isSame(leaveRequest.from_date, 'day')) { - day = dayObj; - } - }); - - contactData = day.contactsData[currentContactId]; - leaveRequestAttributes = contactData.leaveRequestsAttributes[leaveRequest.id]; - - return day.contactsData[currentContactId]; - } }); function getDayWithType (dayType, returnContactData) { @@ -822,6 +849,38 @@ }); }); + /** + * Initializes controller with default or given leave requests + * and caches day, contact data and leave request attributes + * for the first leave request in the list for testing convenience + * + * @param {Array} leaveRequests - optional array of {LeaveRequestInstance} + */ + function commonSetup (leaveRequests) { + var day; + var leaveRequestsToUse = leaveRequests || [leaveRequest]; + + LeaveRequest.all.and.callFake(function () { + return $q.resolve({ list: leaveRequestsToUse }); + }); + + compileComponent(true); + + controller.month.days.forEach(function (dayObj) { + if (moment(dayObj.date).isSame(leaveRequestsToUse[0].from_date, 'day')) { + day = dayObj; + } + }); + + contactData = day.contactsData[currentContactId]; + leaveRequestAttributes = contactData.leaveRequestsAttributes[leaveRequestsToUse[0].id]; + } + + /** + * Compiles component + * + * @param {Boolean} sendSignal - if to send a month signal or not + */ function compileComponent (sendSignal) { controller = $componentController('leaveCalendarMonth', null, { contacts: ContactData.all.values, From d1f364f44c92826e075af0ab5dd63d8defef2c7e Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Fri, 27 Apr 2018 11:35:33 +0100 Subject: [PATCH 181/203] PCHR-3581: Add dist files --- .../css/leaveandabsence.css | 2 +- .../js/angular/dist/absence-tab.min.js | 8 ++++---- .../js/angular/dist/admin-dashboard.min.js | 10 +++++----- .../js/angular/dist/manager-leave.min.js | 10 +++++----- .../js/angular/dist/my-leave.min.js | 8 ++++---- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/css/leaveandabsence.css b/uk.co.compucorp.civicrm.hrleaveandabsences/css/leaveandabsence.css index d90e0be7d4b..5b4f9a9ae65 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/css/leaveandabsence.css +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/css/leaveandabsence.css @@ -1 +1 @@ -#bootstrap-theme .chr_disabled{opacity:0.5;pointer-events:none}#bootstrap-theme .table-condensed>thead>tr>th{background:#fff !important;padding:8px 5px}#bootstrap-theme .table-condensed-mixed>thead>tr>th,#bootstrap-theme .table-condensed-mixed>thead>tr>td,#bootstrap-theme .table-condensed-mixed>tbody>tr>th,#bootstrap-theme .table-condensed-mixed>tbody>tr>td{padding-left:5px;padding-right:5px}#bootstrap-theme .table-condensed>tbody>tr>td:first-child,#bootstrap-theme .table-condensed>tbody>tr>th:first-child,#bootstrap-theme .table-condensed>thead>tr>td:first-child,#bootstrap-theme .table-condensed>thead>tr>th:first-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>td:first-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>th:first-child,#bootstrap-theme .table-condensed-mixed>thead>tr>td:first-child,#bootstrap-theme .table-condensed-mixed>thead>tr>th:first-child{padding-left:20px}#bootstrap-theme .table-condensed>tbody>tr>td:last-child,#bootstrap-theme .table-condensed>tbody>tr>th:last-child,#bootstrap-theme .table-condensed>thead>tr>td:last-child,#bootstrap-theme .table-condensed>thead>tr>th:last-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>td:last-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>th:last-child,#bootstrap-theme .table-condensed-mixed>thead>tr>td:last-child,#bootstrap-theme .table-condensed-mixed>thead>tr>th:last-child{padding-right:20px}#bootstrap-theme .table-nested{overflow-y:hidden;position:relative}#bootstrap-theme .table-nested:before{box-shadow:inset 0px 6px 9px -6px rgba(0,0,0,0.2);content:'';display:block;height:10px;left:0;position:absolute;top:0;width:100%;z-index:10}#bootstrap-theme .table-nested:after{box-shadow:inset 0px -4px 9px -6px rgba(0,0,0,0.2);content:'';display:block;height:10px;left:0;position:absolute;bottom:0;width:100%;z-index:10}#bootstrap-theme .table-nested>table,#bootstrap-theme .table-nested>.table{background-color:#fff}#bootstrap-theme .table-nested>table>tbody>tr>td:first-child,#bootstrap-theme .table-nested>table>tbody>tr>th:first-child,#bootstrap-theme .table-nested>table>thead>tr>td:first-child,#bootstrap-theme .table-nested>table>thead>tr>th:first-child,#bootstrap-theme .table-nested>.table>tbody>tr>td:first-child,#bootstrap-theme .table-nested>.table>tbody>tr>th:first-child,#bootstrap-theme .table-nested>.table>thead>tr>td:first-child,#bootstrap-theme .table-nested>.table>thead>tr>th:first-child{padding-left:30px;position:relative}#bootstrap-theme .table-nested>table>tbody>tr>td:first-child:before,#bootstrap-theme .table-nested>table>tbody>tr>th:first-child:before,#bootstrap-theme .table-nested>table>thead>tr>td:first-child:before,#bootstrap-theme .table-nested>table>thead>tr>th:first-child:before,#bootstrap-theme .table-nested>.table>tbody>tr>td:first-child:before,#bootstrap-theme .table-nested>.table>tbody>tr>th:first-child:before,#bootstrap-theme .table-nested>.table>thead>tr>td:first-child:before,#bootstrap-theme .table-nested>.table>thead>tr>th:first-child:before{background:#c2cfd8;content:'';display:block;height:110%;left:0;position:absolute;top:0;width:10px;z-index:2}#bootstrap-theme .table-nested>table>tbody>tr>td:last-child,#bootstrap-theme .table-nested>table>tbody>tr>th:last-child,#bootstrap-theme .table-nested>table>thead>tr>td:last-child,#bootstrap-theme .table-nested>table>thead>tr>th:last-child,#bootstrap-theme .table-nested>.table>tbody>tr>td:last-child,#bootstrap-theme .table-nested>.table>tbody>tr>th:last-child,#bootstrap-theme .table-nested>.table>thead>tr>td:last-child,#bootstrap-theme .table-nested>.table>thead>tr>th:last-child{padding-right:30px;position:relative}#bootstrap-theme .table-nested>table>tbody>tr>td:last-child:after,#bootstrap-theme .table-nested>table>tbody>tr>th:last-child:after,#bootstrap-theme .table-nested>table>thead>tr>td:last-child:after,#bootstrap-theme .table-nested>table>thead>tr>th:last-child:after,#bootstrap-theme .table-nested>.table>tbody>tr>td:last-child:after,#bootstrap-theme .table-nested>.table>tbody>tr>th:last-child:after,#bootstrap-theme .table-nested>.table>thead>tr>td:last-child:after,#bootstrap-theme .table-nested>.table>thead>tr>th:last-child:after{background:#c2cfd8;content:'';display:block;height:110%;right:0;position:absolute;top:0;width:10px;z-index:2}@media screen and (max-width: 767px){#bootstrap-theme .table-nested.table-responsive{border:0;margin-bottom:0}}#bootstrap-theme .table-nested-cell{padding:0 !important}#bootstrap-theme .chr_absence-work-pattern__add-custom{margin-bottom:20px}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(1){width:40%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(2){width:15%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(3){width:35%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(4){width:10%}#bootstrap-theme .chr_absence-work-pattern__work-pattern-listing{display:inline-block}#bootstrap-theme .chr_absence-work-pattern__alert{margin-bottom:0 !important}#bootstrap-theme .annual-entitlement-change-log-component thead td{min-width:100px}#bootstrap-theme .annual-entitlement-change-log-component thead .annual-entitlement-change-log-component__comments{min-width:300px}#bootstrap-theme .chr_annual-entitlements__period{width:130px}#bootstrap-theme .chr_annual-entitlements__edit-entitlements{width:150px}#bootstrap-theme .chr_contract-entitlements__position{width:140px}@media (max-width: 992px){#bootstrap-theme .chr_leave-balance-tab .chr_leave-balance-tab__filter:not(:last-child){padding-bottom:15px}}#bootstrap-theme .chr_leave-balance-tab__body{padding:0}@media (min-width: 1200px){#bootstrap-theme .chr_leave-calendar__dates-container .chr_leave-calendar{table-layout:fixed}}#bootstrap-theme .chr_leave-calendar__names-container .chr_leave-calendar{table-layout:fixed}#bootstrap-theme .chr_leave-calendar__day{font-size:10px !important;line-height:1.4em !important;padding:10px !important;text-align:center !important}@media (min-width: 1200px){#bootstrap-theme .chr_leave-calendar__day{padding:10px 0 !important}}#bootstrap-theme .chr_leave-calendar__day--disabled{opacity:0.5}#bootstrap-theme .chr_leave-calendar__day--current{color:#0071bd !important}#bootstrap-theme .chr_leave-calendar__item{color:#FFF;display:block;font-size:10px;height:100%;position:relative;text-align:center;text-transform:uppercase;width:100%}#bootstrap-theme .chr_leave-calendar__item>span{bottom:0;left:0;margin:auto;position:absolute;right:0;top:0;height:1.2em}#bootstrap-theme .chr_leave-calendar__item>.chr_leave-calendar__time-unit{font-size:7px;height:1em;margin-left:-1px}#bootstrap-theme .chr_leave-calendar__item>a{cursor:pointer;bottom:0;left:0;margin:auto;position:absolute;right:0;top:0}#bootstrap-theme .chr_leave-calendar__item--disabled{cursor:not-allowed;opacity:0.5}#bootstrap-theme .chr_leave-calendar__item--type--late{background-color:#eca67e;border-color:#eca67e}#bootstrap-theme .chr_leave-calendar__item--type--non-working{background-color:#41afcb !important;border-color:#41afcb}#bootstrap-theme .chr_leave-calendar__item--type--public-holiday{background-color:#8ec68a !important;border-color:#8ec68a}#bootstrap-theme .chr_leave-calendar__item--type--weekend{background-color:#c7cbd0 !important;border-color:#c7cbd0}#bootstrap-theme .chr_leave-calendar__item--alt{background:#FFF !important;border:1px solid transparent;color:#464354}#bootstrap-theme .chr_leave-calendar__item--requested:before{background:#c7cbd0;content:'';display:block;height:.5em;position:absolute;width:100%;top:0}#bootstrap-theme .chr_leave-calendar__item--toil-requested:before{background:red;content:'';display:block;height:.5em;left:-1px;position:absolute;width:calc(100% + 2px);top:-1px}#bootstrap-theme .chr_leave-calendar__items>td{overflow:hidden;height:35px;padding:0 !important}#bootstrap-theme .chr_leave-calendar__items leave-calendar-day{display:block;height:100%}#bootstrap-theme .chr_leave-calendar__legend__title{font-size:12px}#bootstrap-theme .chr_leave-calendar__legend>.row:not(:first-child){margin-top:20px}#bootstrap-theme .chr_leave-calendar__legend .chr_leave-calendar__legend__entry{margin-top:10px}@media (min-width: 768px){#bootstrap-theme .chr_leave-calendar__legend .chr_leave-calendar__legend__entry{margin-top:0}}#bootstrap-theme .chr_leave-calendar__legend__entry{overflow:auto}#bootstrap-theme .chr_leave-calendar__legend__entry+#bootstrap-theme .chr_leave-calendar__legend__entry{margin-top:10px}#bootstrap-theme .chr_leave-calendar__legend__entry>.chr_leave-calendar__item{font-size:8px;height:20px;margin-right:10px;position:absolute;width:20px}#bootstrap-theme .chr_leave-calendar__legend__label{display:inline-block;font-size:12px;margin-left:26px}#bootstrap-theme .chr_leave-calendar__month-header{background:#f3f6f7}#bootstrap-theme .chr_leave-calendar__month-header .panel-title{font-size:16px}#bootstrap-theme td.chr_leave-calendar__name,#bootstrap-theme th.chr_leave-calendar__name{font-size:12px !important;line-height:100%;padding:0 20px !important;text-align:left;text-overflow:ellipsis;width:100%}#bootstrap-theme th.chr_leave-calendar__name,#bootstrap-theme th.chr_leave-calendar__day{height:49px}#bootstrap-theme th.chr_leave-calendar__name{padding-bottom:10px !important}#bootstrap-theme td.chr_leave-calendar__name{vertical-align:middle !important}#bootstrap-theme .chr_leave-calendar__pagination{font-size:10px;text-align:center}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"]{outline:none;padding:0;line-height:1em}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"] .fa{color:#555}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"][disabled] .fa{opacity:0.5}#bootstrap-theme .chr_leave-calendar__pagination [class*="btn"]:hover:not([disabled]) .fa{color:#464354}#bootstrap-theme .chr_leave-calendar__pagination-next{border-top:none}#bootstrap-theme .chr_leave-calendar__pagination-next th{height:24px;padding:4px 0 6px !important}#bootstrap-theme .chr_leave-calendar__pagination-next .chr_leave-calendar__pagination{padding-right:3px !important}#bootstrap-theme .chr_leave-calendar__month-container{margin:0}#bootstrap-theme .chr_leave-calendar__month-container>div{padding:0}#bootstrap-theme .chr_leave-calendar__dates-container{overflow-x:auto}#bootstrap-theme .chr_leave-calendar__admin-filters-hint{display:inline-block;font-size:20px;vertical-align:middle}#bootstrap-theme .chr_leave-calendar__admin-filters-select{width:calc(100% - 50px);display:inline-block;margin-right:20px}#bootstrap-theme .chr_leave-report .dropdown-toggle{color:#464354;padding:0 10px}#bootstrap-theme .chr_leave-report .dropdown-toggle:hover{background:#e6e6e6}#bootstrap-theme .chr_leave-report table{table-layout:fixed}#bootstrap-theme .chr_leave-report table thead th,#bootstrap-theme .chr_leave-report table tbody td{padding:8px 5px}#bootstrap-theme .chr_leave-report__label{color:#464354;font-weight:700}#bootstrap-theme .chr_leave-report__label>.fa{margin-right:5px}#bootstrap-theme .chr_leave-report__label--toggle{cursor:pointer;user-select:none}#bootstrap-theme .chr_leave-report__heading{background-color:#f3f6f7;border-bottom:1px solid #dadcde}#bootstrap-theme .chr_leave-report__heading .chr_leave-report__export-button{line-height:2.4}#bootstrap-theme .chr_leave-report__table table,#bootstrap-theme .chr_leave-report__table .table{border-collapse:separate}#bootstrap-theme .chr_leave-report__table table>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>tbody>tr:first-child>td{border-top-width:0}#bootstrap-theme .chr_leave-report__table table>thead+tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>thead+tbody>tr:first-child>td{border-top-width:1px}#bootstrap-theme .chr_leave-report__table table:not(.table-bordered):not(.table-condensed)>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table:not(.table-bordered):not(.table-condensed)>tbody>tr:first-child>td{border-color:#f3f6f7}#bootstrap-theme .chr_leave-report__table table>thead>tr>th,#bootstrap-theme .chr_leave-report__table .table>thead>tr>th{background:#f3f6f7;border-bottom:0;color:#464354;text-transform:capitalize}#bootstrap-theme .chr_leave-report__table table>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>tbody>tr:first-child>td{border-color:#e8eef0 !important}#bootstrap-theme .chr_leave-report__table table>tfoot>tr,#bootstrap-theme .chr_leave-report__table .table>tfoot>tr{background:#f3f6f7}#bootstrap-theme .chr_leave-report__table>table>thead>tr>th,#bootstrap-theme .chr_leave-report__table>.table>thead>tr>th{padding-bottom:13px;padding-top:13px}#bootstrap-theme .chr_leave-report__table-container{overflow:auto}#bootstrap-theme .chr_leave-report__table-container .panel{display:inline-block;min-width:100%}#bootstrap-theme .chr_leave-report__table__heading--action{width:45px}#bootstrap-theme .chr_leave-report__table__heading--label{width:280px}#bootstrap-theme .chr_leave-report__table__heading--dates{width:170px}#bootstrap-theme .chr_leave-report__table__heading--status{width:180px}#bootstrap-theme .chr_leave-report__table__heading--type{width:65px;word-break:break-word}#bootstrap-theme .chr_leave-request-comment{margin-top:10px}#bootstrap-theme .chr_leave-request-comment__text{border-bottom:1px solid #e8eef0;color:#c2cfd8;margin-right:10px;padding-bottom:20px}#bootstrap-theme .chr_leave-request-files_list{height:150px;overflow-y:auto;margin-top:20px;margin-bottom:20px}#bootstrap-theme .chr_leave-request-files_meta{margin-bottom:10px}#bootstrap-theme .chr_leave-request-files_upload{border:dashed 1px #464354;padding:20px}#bootstrap-theme .chr_leave-request-files_upload_action{padding:5px}#bootstrap-theme .chr_leave-request-files_file-name{display:inline-block;max-width:240px;overflow:hidden;text-overflow:ellipsis;vertical-align:bottom}#bootstrap-theme .chr_leave-request-files_delete{margin-top:-7px}#bootstrap-theme .chr_leave-request-modal .modal-title{font-size:18px !important}#bootstrap-theme .chr_leave-request-modal .table-responsive{border:0}#bootstrap-theme .chr_leave-request-modal .chr_leave-request-date-picker-container .input-group{width:100%}@media screen and (max-width: 767px){#bootstrap-theme .chr_leave-request-modal .chr_leave-request-date-picker-container{margin-bottom:10px}}#bootstrap-theme .chr_leave-request-modal__chevron{font-size:0.6em;margin-right:5px;vertical-align:middle}#bootstrap-theme .chr_leave-request-modal__comments{height:230px;margin-bottom:20px;overflow:auto}#bootstrap-theme .chr_leave-request-modal__comments_empty{margin-bottom:20px}#bootstrap-theme .chr_leave-request-modal__footer{margin:0}#bootstrap-theme .chr_leave-request-modal__delete{margin-left:15px;margin-top:8px}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container{margin-bottom:20px}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container ul{opacity:1 !important}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container:not(.ui-select-multiple) input{width:100% !important}#bootstrap-theme .chr_leave-request-modal__form-group,#bootstrap-theme .chr_leave-request-modal__required-documents>div{margin-bottom:15px}#bootstrap-theme .chr_leave-request-modal__response{padding:20px 20px 0}#bootstrap-theme .chr_leave-request-modal__response label{font-size:17px;margin-top:-3px}#bootstrap-theme .chr_leave-request-modal__response .chr_wysiwyg{margin-top:15px}#bootstrap-theme .chr_leave-request-modal__required-documents input{margin-right:5px}#bootstrap-theme .chr_leave-request-modal__small_spinner>div.chr_spinner{margin-top:18px;min-height:initial}#bootstrap-theme .chr_leave-request-modal__tab input[uib-datepicker-popup]{font-size:13px}#bootstrap-theme .chr_leave-request-modal__table{border:1px solid #f3f6f7;margin-bottom:15px !important}#bootstrap-theme .chr_leave-request-modal__user-info{font-size:17px;padding:20px}#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(1){color:#464354}#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(2){color:#555}@media screen and (min-width: 480px){#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(2){border-left:1px solid #e8eef0}}#bootstrap-theme .chr_leave-request-modal__span-expiry{display:inline-block;margin-top:7px}#bootstrap-theme .chr_leave-request-modal__expiry-clear{position:absolute;right:3.5em;top:0.6em;z-index:2}#bootstrap-theme .chr_leave-request-modal__small-text{font-size:80%}#bootstrap-theme .chr_leave-request-modal__custom-deduction-toggling-row{margin-top:-5px}@media screen and (min-width: 768px){#bootstrap-theme .chr_leave-request-modal__custom-deduction-label{text-align:right}}@media screen and (max-width: 767px){#bootstrap-theme .chr_leave-request-modal__custom-deduction-label{margin-bottom:10px}}#bootstrap-theme .chr_leave-request-modal .form-group{overflow:inherit !important}#bootstrap-theme .chr_leave-request-modal .alert{margin-bottom:0 !important}#bootstrap-theme .chr_leave-request-modal input[uib-datepicker-popup]{box-shadow:none !important;background-color:inherit !important;color:inherit !important;cursor:pointer !important;border-right:none}#bootstrap-theme leave-request-record-actions{display:block}#bootstrap-theme leave-request-record-actions .btn-group{float:left}#bootstrap-theme leave-request-record-actions .btn-group:first-child{margin-right:8px}#bootstrap-theme leave-request-record-actions .btn-group:first-child .dropdown-menu{left:auto;right:0}@media screen and (max-width: 767px){#bootstrap-theme leave-request-record-actions .btn-group{width:calc((100% - 8px) / 2)}#bootstrap-theme leave-request-record-actions .btn{padding-left:0;padding-right:0;width:100%}#bootstrap-theme leave-request-record-actions .btn-group:first-child .dropdown-menu{left:0;right:auto}}#bootstrap-theme .leave-widget h4{color:#4d4d69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px}#bootstrap-theme .leave-widget__types>table,#bootstrap-theme .leave-widget__sickness>table,#bootstrap-theme .leave-widget__next-leave>table{border:none}#bootstrap-theme .leave-widget__types>table thead tr th,#bootstrap-theme .leave-widget__sickness>table thead tr th,#bootstrap-theme .leave-widget__next-leave>table thead tr th{color:#4d4d69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px;background:none;width:35%}#bootstrap-theme .leave-widget__types>table thead tr th:first-child,#bootstrap-theme .leave-widget__sickness>table thead tr th:first-child,#bootstrap-theme .leave-widget__next-leave>table thead tr th:first-child{width:65%}#bootstrap-theme .leave-widget__types>table tbody tr td,#bootstrap-theme .leave-widget__sickness>table tbody tr td,#bootstrap-theme .leave-widget__next-leave>table tbody tr td{color:#0071bd;font-size:16px;font-weight:600;padding-bottom:9px}#bootstrap-theme .leave-widget__types>table tbody tr td:first-child,#bootstrap-theme .leave-widget__sickness>table tbody tr td:first-child,#bootstrap-theme .leave-widget__next-leave>table tbody tr td:first-child{color:#464354}#bootstrap-theme .leave-widget hr{border-color:#DEE4ED;margin-bottom:25px;margin-top:25px}#bootstrap-theme .leave-widget__sickness h4{margin-top:18px}#bootstrap-theme .leave-widget__next-leave h3{font-size:16px;margin-bottom:16px;margin-top:0}#bootstrap-theme .leave-widget__next-leave__deduction{font-size:16px;font-weight:600;color:#464354}#bootstrap-theme .chr_leave__page-selector-dropdown{margin-right:5px;position:relative;top:1px;width:100%}#bootstrap-theme .chr_leave__page-selector-dropdown select{height:40px}#bootstrap-theme .chr_leave__page-selector-dropdown .crm_custom-select__arrow{line-height:40px;width:40px}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;border-bottom:1px solid #dadcde;margin:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header .panel-title{margin-top:7px;display:inline-block}@media screen and (max-width: 992px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header>div:not(:last-child),#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header .panel-title{padding-bottom:20px}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter{display:inline-block;margin-top:7px;white-space:nowrap}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter .fa{font-size:0.6em;margin-right:5px;margin-top:-2px;vertical-align:middle}@media screen and (max-width: 991px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter{margin-top:15px}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;border-bottom:1px solid #dadcde;margin:0;padding-top:15px}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>*{padding-left:10px !important;padding-right:10px !important}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>div:not(:last-child){padding-bottom:20px}}@media screen and (min-width: 992px) and (max-width: 1199px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>.no_gutter{padding-bottom:0 !important}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body{margin:0;padding:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body [class^="col-"],#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body [class*=" col-"]{padding:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body a{cursor:pointer}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container{padding-left:10px;padding-right:10px;background-color:#f7f7f9}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container>div{padding-left:15px;padding-right:15px}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .form-group{overflow:inherit !important}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .panel{background-image:none !important}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .panel-body,#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .chr_vertical_tabs{background-color:#f7f7f9}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] input[type="search"]{width:100% !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header .checkbox{margin-top:5px}#bootstrap-theme .page-manager-leave .chr_manage_leave_requests .btn-sm{font-size:100% !important}#bootstrap-theme .chr_manager_calendar__header{padding-left:10px;padding-right:10px;padding-top:15px;margin:0;background-color:#f7f7f9;border-bottom:1px solid #dadcde}#bootstrap-theme .chr_manager_calendar__header>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manager_calendar__header .checkbox{margin:0}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manager_calendar__header>div:not(:last-child){padding-bottom:20px}}#bootstrap-theme .chr_manager_calendar__sub-header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;margin:0}#bootstrap-theme .chr_manager_calendar__sub-header>*{padding-left:10px !important;padding-right:10px !important}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manager_calendar__sub-header>div:not(:last-child){padding-bottom:20px}#bootstrap-theme .chr_manager_calendar__sub-header .ui-select-container{height:auto}}#bootstrap-theme .time-amount-picker .crm_custom-select{display:inline-block;margin-right:2px}#bootstrap-theme .time-amount-picker .crm_custom-select:nth-child(2){margin-left:10px}#bootstrap-theme .absence-tab-page .tab-pane{padding:0 !important}#bootstrap-theme .absence-tab-page .tab-content{background-color:transparent !important}#bootstrap-theme .absence-tab-page leave-request-record-actions{margin-bottom:20px}#bootstrap-theme .crm-absence_type-form-block .crm-section .label{width:35%}#bootstrap-theme .crm-absence_type-form-block .crm-section .content{margin-left:40%}#bootstrap-theme .crm-absence_type-form-block .toil-option,#bootstrap-theme .crm-absence_type-form-block .carry-forward-option,#bootstrap-theme .crm-absence_type-form-block .toil-expiration,#bootstrap-theme .crm-absence_type-form-block .carry-forward-expiration-duration,#bootstrap-theme .crm-absence_type-form-block .carry-forward-expiration-date{display:none}#bootstrap-theme .crm-absence_type-form-block .sp-replacer{padding:2px}#bootstrap-theme .crm-absence_type-form-block .sp-preview{height:15px;width:15px}#bootstrap-theme .crm-absence_type-form-block .sp-dd{height:0;line-height:15px;font-size:9px}.page-civicrm-leaveandabsences-dashboard .page-title,.page-civicrm-leaveandabsences-dashboard #branding{display:none !important}.page-civicrm-leaveandabsences-dashboard #page{margin:0;padding:0}.admin-dashboard-page{position:relative}.admin-dashboard-page .crm_page__topbar{height:65px}.admin-dashboard-page leave-request-record-actions{margin:12px 16px 0 0}.admin-dashboard-page .chr_admin-dashboard_side-nav{background-color:#fff;height:calc(100% - 12px);overflow:hidden;position:absolute;width:170px}.admin-dashboard-page .chr_admin-dashboard_side-nav .active{background:#e8eef0}.admin-dashboard-page .chr_admin-dashboard_content{float:right;margin:16px;margin-bottom:0;width:calc(100% - 170px - 16px * 2)}#bootstrap-theme #calculation-details{background:#fff}#bootstrap-theme #calculation-details .base-contractual-entitlement{color:#0071bd}#bootstrap-theme #calculation-details .working-days-to-work{color:#44cb7e}#bootstrap-theme #calculation-details .working-days-in-period{color:#e6ab5e}#bootstrap-theme #calculation-details .contract-1-pro-rata{color:#E6807F}#bootstrap-theme #calculation-details .contract-2-pro-rata{color:#797300}#bootstrap-theme #calculation-details .contract-3-pro-rata{color:#904E1E}#bootstrap-theme #calculation-details .contract-4-pro-rata{color:#0511B1}#bootstrap-theme #calculation-details .contract-5-pro-rata{color:#4B9609}#bootstrap-theme #calculation-details .calculation-pro-rata{color:#95c0ff}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body{padding-top:20px;padding-bottom:20px}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body .row:first-child h3{margin-top:0}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body h3{margin-bottom:20px}#bootstrap-theme .crm-leave-and-absences-form-block .panel-footer .crm-button:last-child{margin-right:0}#bootstrap-theme.crm-leave-and-balance-import .panel{background-color:#fff}#bootstrap-theme.crm-leave-and-balance-import .panel-header{position:relative}#bootstrap-theme.crm-leave-and-balance-import .panel-header h2{padding:10px 20px}#bootstrap-theme.crm-leave-and-balance-import .panel-body .row:not(:last-child){padding-bottom:2em}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats .label{display:none}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats label{font-weight:normal !important}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats td{border:0;padding:0}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block{box-shadow:none;padding:0}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table{margin-bottom:2em;width:100%}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table th{padding:10px 20px;border-right:none}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table th,#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table td{padding:5px}#bootstrap-theme.crm-leave-and-balance-import #preview-counts,#bootstrap-theme.crm-leave-and-balance-import #summary-counts{box-shadow:none;margin-bottom:2em;width:100%}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td{background-color:#f2dede !important;color:#cf3458}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td a,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td a{color:#bd2d4e;font-weight:bold}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td a:hover,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td a:hover{color:#0062a4}#bootstrap-theme.manage-entitlements-form .wider-hr{margin-left:-20px;margin-right:-20px;border-width:2px}#bootstrap-theme.manage-entitlements-form .wider-row{margin-left:-20px;margin-right:-20px}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters{padding:15px 0;text-align:center}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .override-filters label{display:inline-block}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .override-filters label:before{display:none}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .absence-type-filter{margin-right:10px}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .col-sm-4:last-child{text-align:right}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list{margin-bottom:0}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement-header .title{float:left;width:65%}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement-header .actions{float:right}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list tr.hidden{display:none}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .absence-type{color:#fff;display:inline-block;padding:5px}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement .overridden-proposed-entitlement,#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement .calculation-unit{display:none}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .borderless-button{background-color:transparent;border:0;cursor:pointer}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .add-comment{font-size:1.1em}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .comment-text{display:none}#bootstrap-theme.manage-entitlements-form .manage-entitlements-form__filters{padding-bottom:1em}#bootstrap-theme.manage-entitlements-form .table{background:#f9f9f9;border-top:1px solid #e8eef0;border-bottom:1px solid #e8eef0;margin-bottom:2em}#bootstrap-theme.manage-entitlements-form .table th{background:#f3f6f7 !important}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header{border-left:1px solid #e8eef0;border-right:1px solid #e8eef0;background:#e4ebed !important;min-width:200px}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .row>div{display:table-cell;float:none;vertical-align:bottom}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .fa{color:#4d4d69}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .action-button-container{padding:0}#bootstrap-theme.manage-entitlements-form .table td.proposed-entitlement{border-left:1px solid #e8eef0;border-right:1px solid #e8eef0;background:white}#bootstrap-theme.manage-entitlements-form .table span.absence-type{border-radius:3px;padding:0 5px}#bootstrap-theme.manage-entitlements-form .table tbody .fa{color:#0071bd}#bootstrap-theme.manage-entitlements-form .crm-container .CRM_HRLeaveAndAbsences_Form_ManageEntitlements .crm-button-type-next{float:right !important}#bootstrap-theme.manage-entitlements-form .panel-footer{border-top:none}#add-comment-dialog{display:none}#add-comment-dialog .calculation_comment{box-sizing:border-box;padding:10px;width:100%}#bootstrap-theme .crm-work-pattern-form-block .ui-tabs.ui-widget-content{background:none}#bootstrap-theme .work-pattern-calendar .number-of-weeks{padding:15px 0 15px 0}#bootstrap-theme .work-pattern-calendar .work-pattern-week{border-top:1px solid rgba(0,0,0,0.2);padding:15px 0 15px 0;margin-bottom:15px}#bootstrap-theme .work-pattern-calendar .work-pattern-week.hidden-week{display:none}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-number{float:left;font-weight:bold;padding:5px 0 15px 5px}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days{table-layout:fixed}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-hours{float:right;padding:5px 5px 15px 0}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-hours .number-of-hours{font-weight:bold}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days td{padding:5px 10px 5px 10px}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days input{min-width:0;text-align:center}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days select{min-width:0;width:100% !important}#bootstrap-theme .work-pattern-calendar .work-pattern-week .hours-row td{padding-top:15px;padding-bottom:15px;border-top:1px solid rgba(0,0,0,0.2);border-bottom:1px solid rgba(0,0,0,0.2)}.caret{display:inline-block;width:0;height:0;margin-left:2px;vertical-align:middle;border-top:4px dashed;border-top:4px solid \9;border-right:4px solid transparent;border-left:4px solid transparent}.dropup,.dropdown{position:relative}.dropdown-toggle:focus{outline:0}.dropdown-menu{position:absolute;top:100%;left:0;z-index:1000;display:none;float:left;min-width:160px;padding:5px 0;margin:2px 0 0;list-style:none;font-size:13px;text-align:left;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.15);border-radius:2px;-webkit-box-shadow:0 6px 12px rgba(0,0,0,0.175);box-shadow:0 6px 12px rgba(0,0,0,0.175);background-clip:padding-box}.dropdown-menu.pull-right{right:0;left:auto}.dropdown-menu .divider{height:1px;margin:9px 0;overflow:hidden;background-color:#e5e5e5}.dropdown-menu>li>a{display:block;padding:3px 20px;clear:both;font-weight:normal;line-height:1.5384615385;color:#4d4d69;white-space:nowrap}.dropdown-menu>li>a:hover,.dropdown-menu>li>a:focus{text-decoration:none;color:#42425a;background-color:#f3f6f7}.dropdown-menu>.active>a,.dropdown-menu>.active>a:hover,.dropdown-menu>.active>a:focus{color:#fff;text-decoration:none;outline:0;background-color:#0071bd}.dropdown-menu>.disabled>a,.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{color:#e8eef0}.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{text-decoration:none;background-color:transparent;background-image:none;filter:progid:DXImageTransform.Microsoft.gradient(enabled = false);cursor:not-allowed}.open>.dropdown-menu{display:block}.open>a{outline:0}.dropdown-menu-right{left:auto;right:0}.dropdown-menu-left{left:0;right:auto}.dropdown-header{display:block;padding:3px 20px;font-size:12px;line-height:1.5384615385;color:#464354;white-space:nowrap}.dropdown-backdrop{position:fixed;left:0;right:0;bottom:0;top:0;z-index:990}.pull-right>.dropdown-menu{right:0;left:auto}.dropup .caret,.navbar-fixed-bottom .dropdown .caret{border-top:0;border-bottom:4px dashed;border-bottom:4px solid \9;content:""}.dropup .dropdown-menu,.navbar-fixed-bottom .dropdown .dropdown-menu{top:auto;bottom:100%;margin-bottom:2px}@media (min-width: 768px){.navbar-right .dropdown-menu{right:0;left:auto}.navbar-right .dropdown-menu-left{left:0;right:auto}}.dropdown-header{padding:11px 20px}.dropdown-menu{-webkit-box-shadow:0 3px 18px 0 rgba(48,40,40,0.25);box-shadow:0 3px 18px 0 rgba(48,40,40,0.25);border:0;margin:0;padding:0}.dropdown-menu>li{border:0;margin:0;padding:0}.dropdown-menu>li>a{padding:11px 20px} +#bootstrap-theme .chr_disabled{opacity:0.5;pointer-events:none}#bootstrap-theme .table-condensed>thead>tr>th{background:#fff !important;padding:8px 5px}#bootstrap-theme .table-condensed-mixed>thead>tr>th,#bootstrap-theme .table-condensed-mixed>thead>tr>td,#bootstrap-theme .table-condensed-mixed>tbody>tr>th,#bootstrap-theme .table-condensed-mixed>tbody>tr>td{padding-left:5px;padding-right:5px}#bootstrap-theme .table-condensed>tbody>tr>td:first-child,#bootstrap-theme .table-condensed>tbody>tr>th:first-child,#bootstrap-theme .table-condensed>thead>tr>td:first-child,#bootstrap-theme .table-condensed>thead>tr>th:first-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>td:first-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>th:first-child,#bootstrap-theme .table-condensed-mixed>thead>tr>td:first-child,#bootstrap-theme .table-condensed-mixed>thead>tr>th:first-child{padding-left:20px}#bootstrap-theme .table-condensed>tbody>tr>td:last-child,#bootstrap-theme .table-condensed>tbody>tr>th:last-child,#bootstrap-theme .table-condensed>thead>tr>td:last-child,#bootstrap-theme .table-condensed>thead>tr>th:last-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>td:last-child,#bootstrap-theme .table-condensed-mixed>tbody>tr>th:last-child,#bootstrap-theme .table-condensed-mixed>thead>tr>td:last-child,#bootstrap-theme .table-condensed-mixed>thead>tr>th:last-child{padding-right:20px}#bootstrap-theme .table-nested{overflow-y:hidden;position:relative}#bootstrap-theme .table-nested:before{box-shadow:inset 0px 6px 9px -6px rgba(0,0,0,0.2);content:'';display:block;height:10px;left:0;position:absolute;top:0;width:100%;z-index:10}#bootstrap-theme .table-nested:after{box-shadow:inset 0px -4px 9px -6px rgba(0,0,0,0.2);content:'';display:block;height:10px;left:0;position:absolute;bottom:0;width:100%;z-index:10}#bootstrap-theme .table-nested>table,#bootstrap-theme .table-nested>.table{background-color:#fff}#bootstrap-theme .table-nested>table>tbody>tr>td:first-child,#bootstrap-theme .table-nested>table>tbody>tr>th:first-child,#bootstrap-theme .table-nested>table>thead>tr>td:first-child,#bootstrap-theme .table-nested>table>thead>tr>th:first-child,#bootstrap-theme .table-nested>.table>tbody>tr>td:first-child,#bootstrap-theme .table-nested>.table>tbody>tr>th:first-child,#bootstrap-theme .table-nested>.table>thead>tr>td:first-child,#bootstrap-theme .table-nested>.table>thead>tr>th:first-child{padding-left:30px;position:relative}#bootstrap-theme .table-nested>table>tbody>tr>td:first-child:before,#bootstrap-theme .table-nested>table>tbody>tr>th:first-child:before,#bootstrap-theme .table-nested>table>thead>tr>td:first-child:before,#bootstrap-theme .table-nested>table>thead>tr>th:first-child:before,#bootstrap-theme .table-nested>.table>tbody>tr>td:first-child:before,#bootstrap-theme .table-nested>.table>tbody>tr>th:first-child:before,#bootstrap-theme .table-nested>.table>thead>tr>td:first-child:before,#bootstrap-theme .table-nested>.table>thead>tr>th:first-child:before{background:#c2cfd8;content:'';display:block;height:110%;left:0;position:absolute;top:0;width:10px;z-index:2}#bootstrap-theme .table-nested>table>tbody>tr>td:last-child,#bootstrap-theme .table-nested>table>tbody>tr>th:last-child,#bootstrap-theme .table-nested>table>thead>tr>td:last-child,#bootstrap-theme .table-nested>table>thead>tr>th:last-child,#bootstrap-theme .table-nested>.table>tbody>tr>td:last-child,#bootstrap-theme .table-nested>.table>tbody>tr>th:last-child,#bootstrap-theme .table-nested>.table>thead>tr>td:last-child,#bootstrap-theme .table-nested>.table>thead>tr>th:last-child{padding-right:30px;position:relative}#bootstrap-theme .table-nested>table>tbody>tr>td:last-child:after,#bootstrap-theme .table-nested>table>tbody>tr>th:last-child:after,#bootstrap-theme .table-nested>table>thead>tr>td:last-child:after,#bootstrap-theme .table-nested>table>thead>tr>th:last-child:after,#bootstrap-theme .table-nested>.table>tbody>tr>td:last-child:after,#bootstrap-theme .table-nested>.table>tbody>tr>th:last-child:after,#bootstrap-theme .table-nested>.table>thead>tr>td:last-child:after,#bootstrap-theme .table-nested>.table>thead>tr>th:last-child:after{background:#c2cfd8;content:'';display:block;height:110%;right:0;position:absolute;top:0;width:10px;z-index:2}@media screen and (max-width: 767px){#bootstrap-theme .table-nested.table-responsive{border:0;margin-bottom:0}}#bootstrap-theme .table-nested-cell{padding:0 !important}#bootstrap-theme .chr_absence-work-pattern__add-custom{margin-bottom:20px}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(1){width:40%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(2){width:15%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(3){width:35%}#bootstrap-theme .chr_absence-work-pattern__custom-work-pattern td:nth-child(4){width:10%}#bootstrap-theme .chr_absence-work-pattern__work-pattern-listing{display:inline-block}#bootstrap-theme .chr_absence-work-pattern__alert{margin-bottom:0 !important}#bootstrap-theme .annual-entitlement-change-log-component thead td{min-width:100px}#bootstrap-theme .annual-entitlement-change-log-component thead .annual-entitlement-change-log-component__comments{min-width:300px}#bootstrap-theme .chr_annual-entitlements__period{width:130px}#bootstrap-theme .chr_annual-entitlements__edit-entitlements{width:150px}#bootstrap-theme .chr_contract-entitlements__position{width:140px}@media (max-width: 992px){#bootstrap-theme .chr_leave-balance-tab .chr_leave-balance-tab__filter:not(:last-child){padding-bottom:15px}}#bootstrap-theme .chr_leave-balance-tab__body{padding:0}#bootstrap-theme .chr_leave-calendar__dates-container{overflow-x:auto}@media (min-width: 1200px){#bootstrap-theme .chr_leave-calendar__dates-container .chr_leave-calendar{table-layout:fixed}}#bootstrap-theme .chr_leave-calendar__names-container .chr_leave-calendar{table-layout:fixed}#bootstrap-theme .chr_leave-calendar__day{font-size:10px !important;line-height:1.4em !important;padding:10px !important;text-align:center !important}@media (min-width: 1200px){#bootstrap-theme .chr_leave-calendar__day{padding:10px 0 !important}}#bootstrap-theme .chr_leave-calendar__day--disabled{opacity:0.5}#bootstrap-theme .chr_leave-calendar__day--current{color:#0071bd !important}#bootstrap-theme .chr_leave-calendar__item{color:#fff;display:block;font-size:10px;height:100%;position:relative;text-align:center;text-transform:uppercase;width:100%}#bootstrap-theme .chr_leave-calendar__item>span{bottom:0;left:0;margin:auto;position:absolute;right:0;top:0;height:1.2em}#bootstrap-theme .chr_leave-calendar__item>.chr_leave-calendar__time-unit{font-size:7px;height:1em;margin-left:-1px}#bootstrap-theme .chr_leave-calendar__item>a{bottom:0;left:0;margin:auto;position:absolute;right:0;top:0;cursor:pointer}#bootstrap-theme .chr_leave-calendar__item--half{height:50%}#bootstrap-theme .chr_leave-calendar__item--half:not(:first-child){height:calc(50% - 1px);margin-top:1px}#bootstrap-theme .chr_leave-calendar__item--more{border:2px solid #d3dee2}#bootstrap-theme .chr_leave-calendar__item--more .chr_leave-calendar__item__label{color:#4d4d69}#bootstrap-theme .chr_leave-calendar__item--disabled{cursor:not-allowed;opacity:0.5}#bootstrap-theme .chr_leave-calendar__item--type--late{background-color:#eca67e;border-color:#eca67e}#bootstrap-theme .chr_leave-calendar__day-container--type--non-working{background-color:#41afcb}#bootstrap-theme .chr_leave-calendar__day-container--type--public-holiday{background-color:#8ec68a}#bootstrap-theme .chr_leave-calendar__day-container--type--weekend{background-color:#c7cbd0}#bootstrap-theme .chr_leave-calendar__item--alt{background-color:#fff !important;border:1px solid transparent;color:#464354}#bootstrap-theme .chr_leave-calendar__item--requested{background:repeating-linear-gradient(45deg, rgba(255,255,255,0.3), rgba(255,255,255,0.3) 5px, transparent 5px, transparent 8px)}#bootstrap-theme .chr_leave-calendar__item--requested.chr_leave-calendar__item--alt{background:repeating-linear-gradient(45deg, rgba(0,0,0,0.1), rgba(0,0,0,0.1) 5px, transparent 5px, transparent 8px)}#bootstrap-theme .chr_leave-calendar__items>td{height:35px;overflow:hidden;padding:0 !important}#bootstrap-theme .chr_leave-calendar__items leave-calendar-day{display:block;height:100%}#bootstrap-theme .chr_leave-calendar__day-container{height:100%}#bootstrap-theme .chr_leave-calendar__legend__title{font-size:12px}#bootstrap-theme .chr_leave-calendar__legend>.row:not(:first-child){margin-top:20px}#bootstrap-theme .chr_leave-calendar__legend .chr_leave-calendar__legend__entry{margin-top:10px}@media (min-width: 768px){#bootstrap-theme .chr_leave-calendar__legend .chr_leave-calendar__legend__entry{margin-top:0}}#bootstrap-theme .chr_leave-calendar__legend__entry{overflow:auto}#bootstrap-theme .chr_leave-calendar__legend__entry+#bootstrap-theme .chr_leave-calendar__legend__entry{margin-top:10px}#bootstrap-theme .chr_leave-calendar__legend__entry>.chr_leave-calendar__item{font-size:8px;height:20px;margin-right:10px;position:absolute;width:20px}#bootstrap-theme .chr_leave-calendar__legend__label{display:inline-block;font-size:12px;margin-left:26px}#bootstrap-theme .chr_leave-calendar__month-header{background:#f3f6f7}#bootstrap-theme .chr_leave-calendar__month-header .panel-title{font-size:16px}#bootstrap-theme .chr_leave-calendar__name{font-size:12px !important;line-height:100%;padding:0 20px !important;text-align:left;text-overflow:ellipsis;width:100%}#bootstrap-theme .chr_leave-calendar__name_header,#bootstrap-theme .chr_leave-calendar__day{height:49px}#bootstrap-theme .chr_leave-calendar__name_header{padding-bottom:10px !important;vertical-align:middle !important}#bootstrap-theme .chr_leave-calendar__pagination{font-size:10px;text-align:center}#bootstrap-theme .chr_leave-calendar__pagination [class*='btn']{line-height:1em;outline:none;padding:0}#bootstrap-theme .chr_leave-calendar__pagination [class*='btn'] .fa{color:#555}#bootstrap-theme .chr_leave-calendar__pagination [class*='btn'][disabled] .fa{opacity:0.5}#bootstrap-theme .chr_leave-calendar__pagination [class*='btn']:hover:not([disabled]) .fa{color:#464354}#bootstrap-theme .chr_leave-calendar__pagination-next{border-top:0}#bootstrap-theme .chr_leave-calendar__pagination-next th{height:24px;padding:4px 0 6px !important}#bootstrap-theme .chr_leave-calendar__pagination-next .chr_leave-calendar__pagination{padding-right:3px !important}#bootstrap-theme .chr_leave-calendar__month-container{margin:0}#bootstrap-theme .chr_leave-calendar__month-container>div{padding:0}#bootstrap-theme .chr_leave-calendar__admin-filters-hint{display:inline-block;font-size:20px;vertical-align:middle}#bootstrap-theme .chr_leave-calendar__admin-filters-select{display:inline-block;margin-right:20px;width:calc(100% - 50px)}#bootstrap-theme .chr_leave-report .dropdown-toggle{color:#464354;padding:0 10px}#bootstrap-theme .chr_leave-report .dropdown-toggle:hover{background:#e6e6e6}#bootstrap-theme .chr_leave-report table{table-layout:fixed}#bootstrap-theme .chr_leave-report table thead th,#bootstrap-theme .chr_leave-report table tbody td{padding:8px 5px}#bootstrap-theme .chr_leave-report__label{color:#464354;font-weight:700}#bootstrap-theme .chr_leave-report__label>.fa{margin-right:5px}#bootstrap-theme .chr_leave-report__label--toggle{cursor:pointer;user-select:none}#bootstrap-theme .chr_leave-report__heading{background-color:#f3f6f7;border-bottom:1px solid #dadcde}#bootstrap-theme .chr_leave-report__heading .chr_leave-report__export-button{line-height:2.4}#bootstrap-theme .chr_leave-report__table table,#bootstrap-theme .chr_leave-report__table .table{border-collapse:separate}#bootstrap-theme .chr_leave-report__table table>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>tbody>tr:first-child>td{border-top-width:0}#bootstrap-theme .chr_leave-report__table table>thead+tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>thead+tbody>tr:first-child>td{border-top-width:1px}#bootstrap-theme .chr_leave-report__table table:not(.table-bordered):not(.table-condensed)>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table:not(.table-bordered):not(.table-condensed)>tbody>tr:first-child>td{border-color:#f3f6f7}#bootstrap-theme .chr_leave-report__table table>thead>tr>th,#bootstrap-theme .chr_leave-report__table .table>thead>tr>th{background:#f3f6f7;border-bottom:0;color:#464354;text-transform:capitalize}#bootstrap-theme .chr_leave-report__table table>tbody>tr:first-child>td,#bootstrap-theme .chr_leave-report__table .table>tbody>tr:first-child>td{border-color:#e8eef0 !important}#bootstrap-theme .chr_leave-report__table table>tfoot>tr,#bootstrap-theme .chr_leave-report__table .table>tfoot>tr{background:#f3f6f7}#bootstrap-theme .chr_leave-report__table>table>thead>tr>th,#bootstrap-theme .chr_leave-report__table>.table>thead>tr>th{padding-bottom:13px;padding-top:13px}#bootstrap-theme .chr_leave-report__table-container{overflow:auto}#bootstrap-theme .chr_leave-report__table-container .panel{display:inline-block;min-width:100%}#bootstrap-theme .chr_leave-report__table__heading--action{width:45px}#bootstrap-theme .chr_leave-report__table__heading--label{width:280px}#bootstrap-theme .chr_leave-report__table__heading--dates{width:170px}#bootstrap-theme .chr_leave-report__table__heading--status{width:180px}#bootstrap-theme .chr_leave-report__table__heading--type{width:65px;word-break:break-word}#bootstrap-theme .chr_leave-request-comment{margin-top:10px}#bootstrap-theme .chr_leave-request-comment__text{border-bottom:1px solid #e8eef0;color:#c2cfd8;margin-right:10px;padding-bottom:20px}#bootstrap-theme .chr_leave-request-files_list{height:150px;overflow-y:auto;margin-top:20px;margin-bottom:20px}#bootstrap-theme .chr_leave-request-files_meta{margin-bottom:10px}#bootstrap-theme .chr_leave-request-files_upload{border:dashed 1px #464354;padding:20px}#bootstrap-theme .chr_leave-request-files_upload_action{padding:5px}#bootstrap-theme .chr_leave-request-files_file-name{display:inline-block;max-width:240px;overflow:hidden;text-overflow:ellipsis;vertical-align:bottom}#bootstrap-theme .chr_leave-request-files_delete{margin-top:-7px}#bootstrap-theme .chr_leave-request-modal .modal-title{font-size:18px !important}#bootstrap-theme .chr_leave-request-modal .table-responsive{border:0}#bootstrap-theme .chr_leave-request-modal .chr_leave-request-date-picker-container .input-group{width:100%}@media screen and (max-width: 767px){#bootstrap-theme .chr_leave-request-modal .chr_leave-request-date-picker-container{margin-bottom:10px}}#bootstrap-theme .chr_leave-request-modal__chevron{font-size:0.6em;margin-right:5px;vertical-align:middle}#bootstrap-theme .chr_leave-request-modal__comments{height:230px;margin-bottom:20px;overflow:auto}#bootstrap-theme .chr_leave-request-modal__comments_empty{margin-bottom:20px}#bootstrap-theme .chr_leave-request-modal__footer{margin:0}#bootstrap-theme .chr_leave-request-modal__delete{margin-left:15px;margin-top:8px}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container{margin-bottom:20px}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container ul{opacity:1 !important}#bootstrap-theme .chr_leave-request-modal__form .ui-select-container:not(.ui-select-multiple) input{width:100% !important}#bootstrap-theme .chr_leave-request-modal__form-group,#bootstrap-theme .chr_leave-request-modal__required-documents>div{margin-bottom:15px}#bootstrap-theme .chr_leave-request-modal__response{padding:20px 20px 0}#bootstrap-theme .chr_leave-request-modal__response label{font-size:17px;margin-top:-3px}#bootstrap-theme .chr_leave-request-modal__response .chr_wysiwyg{margin-top:15px}#bootstrap-theme .chr_leave-request-modal__required-documents input{margin-right:5px}#bootstrap-theme .chr_leave-request-modal__small_spinner>div.chr_spinner{margin-top:18px;min-height:initial}#bootstrap-theme .chr_leave-request-modal__tab input[uib-datepicker-popup]{font-size:13px}#bootstrap-theme .chr_leave-request-modal__table{border:1px solid #f3f6f7;margin-bottom:15px !important}#bootstrap-theme .chr_leave-request-modal__user-info{font-size:17px;padding:20px}#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(1){color:#464354}#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(2){color:#555}@media screen and (min-width: 480px){#bootstrap-theme .chr_leave-request-modal__user-info>span:nth-child(2){border-left:1px solid #e8eef0}}#bootstrap-theme .chr_leave-request-modal__span-expiry{display:inline-block;margin-top:7px}#bootstrap-theme .chr_leave-request-modal__expiry-clear{position:absolute;right:3.5em;top:0.6em;z-index:2}#bootstrap-theme .chr_leave-request-modal__small-text{font-size:80%}#bootstrap-theme .chr_leave-request-modal__custom-deduction-toggling-row{margin-top:-5px}@media screen and (min-width: 768px){#bootstrap-theme .chr_leave-request-modal__custom-deduction-label{text-align:right}}@media screen and (max-width: 767px){#bootstrap-theme .chr_leave-request-modal__custom-deduction-label{margin-bottom:10px}}#bootstrap-theme .chr_leave-request-modal .form-group{overflow:inherit !important}#bootstrap-theme .chr_leave-request-modal .alert{margin-bottom:0 !important}#bootstrap-theme .chr_leave-request-modal input[uib-datepicker-popup]{box-shadow:none !important;background-color:inherit !important;color:inherit !important;cursor:pointer !important;border-right:none}#bootstrap-theme leave-request-record-actions{display:block}#bootstrap-theme leave-request-record-actions .btn-group{float:left}#bootstrap-theme leave-request-record-actions .btn-group:first-child{margin-right:8px}#bootstrap-theme leave-request-record-actions .btn-group:first-child .dropdown-menu{left:auto;right:0}@media screen and (max-width: 767px){#bootstrap-theme leave-request-record-actions .btn-group{width:calc((100% - 8px) / 2)}#bootstrap-theme leave-request-record-actions .btn{padding-left:0;padding-right:0;width:100%}#bootstrap-theme leave-request-record-actions .btn-group:first-child .dropdown-menu{left:0;right:auto}}#bootstrap-theme .leave-widget h4{color:#4d4d69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px}#bootstrap-theme .leave-widget__types>table,#bootstrap-theme .leave-widget__sickness>table,#bootstrap-theme .leave-widget__next-leave>table{border:none}#bootstrap-theme .leave-widget__types>table thead tr th,#bootstrap-theme .leave-widget__sickness>table thead tr th,#bootstrap-theme .leave-widget__next-leave>table thead tr th{color:#4d4d69;font-size:13px;font-weight:normal;margin-bottom:0;padding-bottom:13px;background:none;width:35%}#bootstrap-theme .leave-widget__types>table thead tr th:first-child,#bootstrap-theme .leave-widget__sickness>table thead tr th:first-child,#bootstrap-theme .leave-widget__next-leave>table thead tr th:first-child{width:65%}#bootstrap-theme .leave-widget__types>table tbody tr td,#bootstrap-theme .leave-widget__sickness>table tbody tr td,#bootstrap-theme .leave-widget__next-leave>table tbody tr td{color:#0071bd;font-size:16px;font-weight:600;padding-bottom:9px}#bootstrap-theme .leave-widget__types>table tbody tr td:first-child,#bootstrap-theme .leave-widget__sickness>table tbody tr td:first-child,#bootstrap-theme .leave-widget__next-leave>table tbody tr td:first-child{color:#464354}#bootstrap-theme .leave-widget hr{border-color:#DEE4ED;margin-bottom:25px;margin-top:25px}#bootstrap-theme .leave-widget__sickness h4{margin-top:18px}#bootstrap-theme .leave-widget__next-leave h3{font-size:16px;margin-bottom:16px;margin-top:0}#bootstrap-theme .leave-widget__next-leave__deduction{font-size:16px;font-weight:600;color:#464354}#bootstrap-theme .chr_leave__page-selector-dropdown{margin-right:5px;position:relative;top:1px;width:100%}#bootstrap-theme .chr_leave__page-selector-dropdown select{height:40px}#bootstrap-theme .chr_leave__page-selector-dropdown .crm_custom-select__arrow{line-height:40px;width:40px}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;border-bottom:1px solid #dadcde;margin:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header .panel-title{margin-top:7px;display:inline-block}@media screen and (max-width: 992px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header>div:not(:last-child),#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__header .panel-title{padding-bottom:20px}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter{display:inline-block;margin-top:7px;white-space:nowrap}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter .fa{font-size:0.6em;margin-right:5px;margin-top:-2px;vertical-align:middle}@media screen and (max-width: 991px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__filter{margin-top:15px}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;border-bottom:1px solid #dadcde;margin:0;padding-top:15px}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>*{padding-left:10px !important;padding-right:10px !important}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>div:not(:last-child){padding-bottom:20px}}@media screen and (min-width: 992px) and (max-width: 1199px){#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header>.no_gutter{padding-bottom:0 !important}}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body{margin:0;padding:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body [class^="col-"],#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body [class*=" col-"]{padding:0}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__panel_body a{cursor:pointer}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container{padding-left:10px;padding-right:10px;background-color:#f7f7f9}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__status_container>div{padding-left:15px;padding-right:15px}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .form-group{overflow:inherit !important}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .panel{background-image:none !important}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .panel-body,#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] .chr_vertical_tabs{background-color:#f7f7f9}#bootstrap-theme .chr_manage_leave_requests[data-role="admin"] input[type="search"]{width:100% !important}#bootstrap-theme .chr_manage_leave_requests .chr_manage_leave_requests__sub-header .checkbox{margin-top:5px}#bootstrap-theme .page-manager-leave .chr_manage_leave_requests .btn-sm{font-size:100% !important}#bootstrap-theme .chr_manager_calendar__header{padding-left:10px;padding-right:10px;padding-top:15px;margin:0;background-color:#f7f7f9;border-bottom:1px solid #dadcde}#bootstrap-theme .chr_manager_calendar__header>*{padding-left:10px !important;padding-right:10px !important}#bootstrap-theme .chr_manager_calendar__header .checkbox{margin:0}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manager_calendar__header>div:not(:last-child){padding-bottom:20px}}#bootstrap-theme .chr_manager_calendar__sub-header{padding-left:10px;padding-right:10px;background-color:#f7f7f9;margin:0}#bootstrap-theme .chr_manager_calendar__sub-header>*{padding-left:10px !important;padding-right:10px !important}@media screen and (max-width: 1199px){#bootstrap-theme .chr_manager_calendar__sub-header>div:not(:last-child){padding-bottom:20px}#bootstrap-theme .chr_manager_calendar__sub-header .ui-select-container{height:auto}}#bootstrap-theme .time-amount-picker .crm_custom-select{display:inline-block;margin-right:2px}#bootstrap-theme .time-amount-picker .crm_custom-select:nth-child(2){margin-left:10px}#bootstrap-theme .absence-tab-page .tab-pane{padding:0 !important}#bootstrap-theme .absence-tab-page .tab-content{background-color:transparent !important}#bootstrap-theme .absence-tab-page leave-request-record-actions{margin-bottom:20px}#bootstrap-theme .crm-absence_type-form-block .crm-section .label{width:35%}#bootstrap-theme .crm-absence_type-form-block .crm-section .content{margin-left:40%}#bootstrap-theme .crm-absence_type-form-block .toil-option,#bootstrap-theme .crm-absence_type-form-block .carry-forward-option,#bootstrap-theme .crm-absence_type-form-block .toil-expiration,#bootstrap-theme .crm-absence_type-form-block .carry-forward-expiration-duration,#bootstrap-theme .crm-absence_type-form-block .carry-forward-expiration-date{display:none}#bootstrap-theme .crm-absence_type-form-block .sp-replacer{padding:2px}#bootstrap-theme .crm-absence_type-form-block .sp-preview{height:15px;width:15px}#bootstrap-theme .crm-absence_type-form-block .sp-dd{height:0;line-height:15px;font-size:9px}.page-civicrm-leaveandabsences-dashboard .page-title,.page-civicrm-leaveandabsences-dashboard #branding{display:none !important}.page-civicrm-leaveandabsences-dashboard #page{margin:0;padding:0}.admin-dashboard-page{position:relative}.admin-dashboard-page .crm_page__topbar{height:65px}.admin-dashboard-page leave-request-record-actions{margin:12px 16px 0 0}.admin-dashboard-page .chr_admin-dashboard_side-nav{background-color:#fff;height:calc(100% - 12px);overflow:hidden;position:absolute;width:170px}.admin-dashboard-page .chr_admin-dashboard_side-nav .active{background:#e8eef0}.admin-dashboard-page .chr_admin-dashboard_content{float:right;margin:16px;margin-bottom:0;width:calc(100% - 170px - 16px * 2)}#bootstrap-theme #calculation-details{background:#fff}#bootstrap-theme #calculation-details .base-contractual-entitlement{color:#0071bd}#bootstrap-theme #calculation-details .working-days-to-work{color:#44cb7e}#bootstrap-theme #calculation-details .working-days-in-period{color:#e6ab5e}#bootstrap-theme #calculation-details .contract-1-pro-rata{color:#E6807F}#bootstrap-theme #calculation-details .contract-2-pro-rata{color:#797300}#bootstrap-theme #calculation-details .contract-3-pro-rata{color:#904E1E}#bootstrap-theme #calculation-details .contract-4-pro-rata{color:#0511B1}#bootstrap-theme #calculation-details .contract-5-pro-rata{color:#4B9609}#bootstrap-theme #calculation-details .calculation-pro-rata{color:#95c0ff}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body{padding-top:20px;padding-bottom:20px}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body .row:first-child h3{margin-top:0}#bootstrap-theme .crm-leave-and-absences-form-block .panel-body h3{margin-bottom:20px}#bootstrap-theme .crm-leave-and-absences-form-block .panel-footer .crm-button:last-child{margin-right:0}#bootstrap-theme.crm-leave-and-balance-import .panel{background-color:#fff}#bootstrap-theme.crm-leave-and-balance-import .panel-header{position:relative}#bootstrap-theme.crm-leave-and-balance-import .panel-header h2{padding:10px 20px}#bootstrap-theme.crm-leave-and-balance-import .panel-body .row:not(:last-child){padding-bottom:2em}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats .label{display:none}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats label{font-weight:normal !important}#bootstrap-theme.crm-leave-and-balance-import .table.date-formats td{border:0;padding:0}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block{box-shadow:none;padding:0}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table{margin-bottom:2em;width:100%}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table th{padding:10px 20px;border-right:none}#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table th,#bootstrap-theme.crm-leave-and-balance-import .crm-activity_map_table-form-block #map-field table td{padding:5px}#bootstrap-theme.crm-leave-and-balance-import #preview-counts,#bootstrap-theme.crm-leave-and-balance-import #summary-counts{box-shadow:none;margin-bottom:2em;width:100%}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td{background-color:#f2dede !important;color:#cf3458}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td a,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td a{color:#bd2d4e;font-weight:bold}#bootstrap-theme.crm-leave-and-balance-import #preview-counts tr.danger td a:hover,#bootstrap-theme.crm-leave-and-balance-import #summary-counts tr.danger td a:hover{color:#0062a4}#bootstrap-theme.manage-entitlements-form .wider-hr{margin-left:-20px;margin-right:-20px;border-width:2px}#bootstrap-theme.manage-entitlements-form .wider-row{margin-left:-20px;margin-right:-20px}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters{padding:15px 0;text-align:center}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .override-filters label{display:inline-block}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .override-filters label:before{display:none}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .absence-type-filter{margin-right:10px}#bootstrap-theme.manage-entitlements-form .entitlement-calculation-filters .col-sm-4:last-child{text-align:right}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list{margin-bottom:0}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement-header .title{float:left;width:65%}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement-header .actions{float:right}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list tr.hidden{display:none}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .absence-type{color:#fff;display:inline-block;padding:5px}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement .overridden-proposed-entitlement,#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .proposed-entitlement .calculation-unit{display:none}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .borderless-button{background-color:transparent;border:0;cursor:pointer}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .add-comment{font-size:1.1em}#bootstrap-theme.manage-entitlements-form .table.entitlement-calculation-list .comment-text{display:none}#bootstrap-theme.manage-entitlements-form .manage-entitlements-form__filters{padding-bottom:1em}#bootstrap-theme.manage-entitlements-form .table{background:#f9f9f9;border-top:1px solid #e8eef0;border-bottom:1px solid #e8eef0;margin-bottom:2em}#bootstrap-theme.manage-entitlements-form .table th{background:#f3f6f7 !important}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header{border-left:1px solid #e8eef0;border-right:1px solid #e8eef0;background:#e4ebed !important;min-width:200px}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .row>div{display:table-cell;float:none;vertical-align:bottom}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .fa{color:#4d4d69}#bootstrap-theme.manage-entitlements-form .table th.proposed-entitlement-header .action-button-container{padding:0}#bootstrap-theme.manage-entitlements-form .table td.proposed-entitlement{border-left:1px solid #e8eef0;border-right:1px solid #e8eef0;background:white}#bootstrap-theme.manage-entitlements-form .table span.absence-type{border-radius:3px;padding:0 5px}#bootstrap-theme.manage-entitlements-form .table tbody .fa{color:#0071bd}#bootstrap-theme.manage-entitlements-form .crm-container .CRM_HRLeaveAndAbsences_Form_ManageEntitlements .crm-button-type-next{float:right !important}#bootstrap-theme.manage-entitlements-form .panel-footer{border-top:none}#add-comment-dialog{display:none}#add-comment-dialog .calculation_comment{box-sizing:border-box;padding:10px;width:100%}#bootstrap-theme .crm-work-pattern-form-block .ui-tabs.ui-widget-content{background:none}#bootstrap-theme .work-pattern-calendar .number-of-weeks{padding:15px 0 15px 0}#bootstrap-theme .work-pattern-calendar .work-pattern-week{border-top:1px solid rgba(0,0,0,0.2);padding:15px 0 15px 0;margin-bottom:15px}#bootstrap-theme .work-pattern-calendar .work-pattern-week.hidden-week{display:none}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-number{float:left;font-weight:bold;padding:5px 0 15px 5px}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days{table-layout:fixed}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-hours{float:right;padding:5px 5px 15px 0}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-hours .number-of-hours{font-weight:bold}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days td{padding:5px 10px 5px 10px}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days input{min-width:0;text-align:center}#bootstrap-theme .work-pattern-calendar .work-pattern-week .week-days select{min-width:0;width:100% !important}#bootstrap-theme .work-pattern-calendar .work-pattern-week .hours-row td{padding-top:15px;padding-bottom:15px;border-top:1px solid rgba(0,0,0,0.2);border-bottom:1px solid rgba(0,0,0,0.2)}.caret{display:inline-block;width:0;height:0;margin-left:2px;vertical-align:middle;border-top:4px dashed;border-top:4px solid \9;border-right:4px solid transparent;border-left:4px solid transparent}.dropup,.dropdown{position:relative}.dropdown-toggle:focus{outline:0}.dropdown-menu{position:absolute;top:100%;left:0;z-index:1000;display:none;float:left;min-width:160px;padding:5px 0;margin:2px 0 0;list-style:none;font-size:13px;text-align:left;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.15);border-radius:2px;-webkit-box-shadow:0 6px 12px rgba(0,0,0,0.175);box-shadow:0 6px 12px rgba(0,0,0,0.175);background-clip:padding-box}.dropdown-menu.pull-right{right:0;left:auto}.dropdown-menu .divider{height:1px;margin:9px 0;overflow:hidden;background-color:#e5e5e5}.dropdown-menu>li>a{display:block;padding:3px 20px;clear:both;font-weight:normal;line-height:1.5384615385;color:#4d4d69;white-space:nowrap}.dropdown-menu>li>a:hover,.dropdown-menu>li>a:focus{text-decoration:none;color:#42425a;background-color:#f3f6f7}.dropdown-menu>.active>a,.dropdown-menu>.active>a:hover,.dropdown-menu>.active>a:focus{color:#fff;text-decoration:none;outline:0;background-color:#0071bd}.dropdown-menu>.disabled>a,.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{color:#e8eef0}.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{text-decoration:none;background-color:transparent;background-image:none;filter:progid:DXImageTransform.Microsoft.gradient(enabled = false);cursor:not-allowed}.open>.dropdown-menu{display:block}.open>a{outline:0}.dropdown-menu-right{left:auto;right:0}.dropdown-menu-left{left:0;right:auto}.dropdown-header{display:block;padding:3px 20px;font-size:12px;line-height:1.5384615385;color:#464354;white-space:nowrap}.dropdown-backdrop{position:fixed;left:0;right:0;bottom:0;top:0;z-index:990}.pull-right>.dropdown-menu{right:0;left:auto}.dropup .caret,.navbar-fixed-bottom .dropdown .caret{border-top:0;border-bottom:4px dashed;border-bottom:4px solid \9;content:""}.dropup .dropdown-menu,.navbar-fixed-bottom .dropdown .dropdown-menu{top:auto;bottom:100%;margin-bottom:2px}@media (min-width: 768px){.navbar-right .dropdown-menu{right:0;left:auto}.navbar-right .dropdown-menu-left{left:0;right:auto}}.dropdown-header{padding:11px 20px}.dropdown-menu{-webkit-box-shadow:0 3px 18px 0 rgba(48,40,40,0.25);box-shadow:0 3px 18px 0 rgba(48,40,40,0.25);border:0;margin:0;padding:0}.dropdown-menu>li{border:0;margin:0;padding:0}.dropdown-menu>li>a{padding:11px 20px} diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js index 7cb75525582..17524a89cac 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.min.js @@ -1,5 +1,5 @@ -!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,o){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:t(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,o,s,i){return t.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return s.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,o,s){return t.debug("WorkPatternAPI.getCalendar",n,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,o){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,o,s,i){function r(t,n){return u().then(function(a){var o=this.days[c(t).valueOf()];return!!o&&e.find(a,function(e){return e.name===n}).value===o.type}.bind(this))}function c(e){return t(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[c(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,o){return t.debug("Calendar"),n.extend({get:function(n,s,i,r){return t.debug("Calendar.get"),a.getCalendar(n,s,i,r).then(function(t){var a=t.values.map(function(e){return o.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function o(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,o,s){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return o.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",t,n,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t,n,o,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var i=a.defer();t&&n||i.reject("contact_id and period_id are mandatory");var r={contact_id:t,period_id:n,statuses:o?{IN:o}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",r,!1).then(function(e){i.resolve(e.values)}),i.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?o.reject(t(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(t){return s.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,o&&(i.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return r.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),n.all(t)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(s.permissions.admin.administer).then(function(t){return t?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,o,s,i){return n.all(this.processFilters(e),t,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,o){return n.balanceChangeByAbsenceType(e,t,a,o)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/instances/work-pattern.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("WorkPatternInstance",["$log","ModelInstance",function(e,t){return e.debug("WorkPatternInstance"),t.extend({})}])}),define("leave-absences/shared/models/work-pattern.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/work-pattern.instance"],function(e,t){"use strict";t.factory("WorkPattern",["$log","Model","WorkPatternAPI","WorkPatternInstance",function(t,n,a,o){return t.debug("WorkPattern"),n.extend({assignWorkPattern:function(e,t,n,o,s,i){return a.assignWorkPattern(e,t,n,o,s,i)},default:function(){return a.get({is_default:!0}).then(function(t){return o.init(e.first(t),!0)})},unassignWorkPattern:function(e){return a.unassignWorkPattern(e)},workPatternsOf:function(e,t,n){return a.workPatternsOf(e,t,n).then(function(e){return e.map(function(e){return o.init(e,!0)})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,o,s,i,r){function c(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function u(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?c():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return o.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):i.all()}function m(e){return"me"===e?o.leaveManagees(v.contactId):"unassigned"===e?o.leaveManagees(void 0,{unassigned:!0}):o.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){r.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,u()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:i.contactId}).leaveManagees().then(function(e){i.lookupContacts=e}).then(o)}}}function o(){return t.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:i.filters.userSettings.department?i.filters.userSettings.department.value:null,level_type:i.filters.userSettings.level_type?i.filters.userSettings.level_type.value:null,location:i.filters.userSettings.location?i.filters.userSettings.location.value:null,region:i.filters.userSettings.region?i.filters.userSettings.region.value:null,id:{IN:i.filters.userSettings.contact?[i.filters.userSettings.contact.id]:i.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var i;return{init:function(e){return i=e,i.showContactName=!0,i.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function o(a,o,s,i,r,c,u,l,d,m){function f(){for(var e=[],t=n(M.selectedPeriod.start_date).clone().startOf("month"),a=n(M.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(R(t)),t.add(1,"month");M.months=e}function p(){i.$new().$watch(function(){return M.selectedMonths},function(t,n){null===n||e.equals(t,n)||I()})}function h(e){M.injectMonths=!0,S("injected").then(function(){I(e)}).then(function(){M.loading.calendar=!1})}function v(){k=a("LeaveCalendar"+t.capitalize(L)+"Controller").init(M)}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function g(){return c.all().then(function(e){M.absencePeriods=t.sortBy(e,"start_date"),M.selectedPeriod=t.find(M.absencePeriods,function(e){return!!e.current})}).then(f).then(w)}function _(){return u.all().then(u.loadCalculationUnits)}function y(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return k.loadContacts().then(function(e){M.contacts=e})}function C(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){M.filters.optionValues.regions=e.hrjc_region,M.filters.optionValues.locations=e.hrjc_location,M.filters.optionValues.levelTypes=e.hrjc_level_type,M.filters.optionValues.departments=e.hrjc_department})}function D(){return l.all()}function T(){return o.all([_(),D(),y()]).then(function(e){M.supportData.absenceTypes=e[0],M.supportData.publicHolidays=e[1],M.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,M.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,M.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,M.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function P(){var e=o.resolve();return M.injectMonths&&(e=S("destroyed"),M.injectMonths=!1),e}function R(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function A(e){e=t.includes(["contacts","period"],e)?e:"period",o.resolve().then(function(){M.loading.calendar=!0}).then(P).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function I(e){var n=M.selectedMonths.length?M.months.filter(function(e){return t.includes(M.selectedMonths,e.index)}):M.months;i.$emit("LeaveCalendar::showMonths",n,!!e)}function w(){M.selectedMonths=[n().month()]}function O(){return M.roleOverride?o.resolve().then(function(){L=M.roleOverride}):o.all([m(r.permissions.admin.administer),m(r.permissions.ssp.manage)]).then(function(e){L=e[0]?"admin":e[1]?"manager":"staff"})}function S(e){return o(function(n){var a=0,o=i.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===M.months.length&&(o(),n())})})}s.debug("Component: leave-calendar");var k,L,M=this;M.absencePeriods=[],M.contacts=[],M.contactIdsToReduceTo=null,M.injectMonths=!1,M.months=[],M.selectedMonths=null,M.selectedPeriod=null,M.showContactName=!1,M.showFilters=!1,M.supportData={},M.loading={calendar:!0,page:!0},M.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},M.labelPeriod=b,M.refresh=A,function(){O().then(p).then(v).then(P).then(g).then(function(){return o.all([q(),T()])}).then(function(){return M.showFilters?C():t.noop}).then(function(){h()}).then(function(){M.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",o]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,o){"use strict";function s(){y.calculationUnit=i(y.supportData.calculationUnits,"value",b.calculation_unit)}function i(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function r(){var e,n;return n=t(y.contactData.leaveRequest.from_date).isSame(y.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+y.calculationUnit.name+"-on-"+e+"-tooltip"}function c(){b=i(y.supportData.absenceTypes,"id",y.contactData.leaveRequest.type_id),y.contactData.leaveRequest["type_id.title"]=b.title}function u(){"days"===y.calculationUnit.name&&(g=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.from_date_type),_=i(y.supportData.dayTypes,"value",y.contactData.leaveRequest.to_date_type),y.contactData.leaveRequest["from_date_type.label"]=g.label,y.contactData.leaveRequest["to_date_type.label"]=_.label)}function l(e,t,n,a,s){e.stopPropagation(),o.openModal(t,n,a,s)}function d(){y.dates.from=new Date(y.contactData.leaveRequest.from_date),y.dates.to=new Date(y.contactData.leaveRequest.to_date)}function m(){y.contactData.isAccruedTOIL?y.label="AT":"days"===y.calculationUnit.name?f():p()}function f(){y.label=y.contactData.isAM?"AM":y.contactData.isPM?"PM":""}function p(){var e=t(y.contactData.leaveRequest.from_date).isSame(y.date,"day"),n=t(y.contactData.leaveRequest.to_date).isSame(y.date,"day");y.label=e?t(y.contactData.leaveRequest.from_date).format("HH:mm"):n?t(y.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){y.tooltipTemplate=y.contactData.isAccruedTOIL?"accrued-toil-tooltip":r()}function v(){a.$watch("day.contactData.leaveRequest",function(){y.contactData&&y.contactData.leaveRequest&&(c(),s(),u(),m(),d(),h()) -})}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(e){_([e]),U(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return j[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){k(e),U(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=P(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){N.push(o.$on("LeaveCalendar::showMonths",$)),N.push(r.subscribe("LeaveRequest::new",u)),N.push(r.subscribe("LeaveRequest::edit",B)),N.push(r.subscribe("LeaveRequest::updatedByManager",B)),N.push(r.subscribe("LeaveRequest::delete",h)),N.push(r.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function D(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function T(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function P(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function R(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function A(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function I(){return[A(c.statusNames.approved),A(c.statusNames.adminApproved),A(c.statusNames.awaitingApproval),A(c.statusNames.moreInformationRequired)]}function w(){return H.month.loading=!0,a.all([S(),O()]).then(b).then(x).then(function(){F=!0}).then(function(){H.month.loading=!1})}function O(){return i.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:I()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function S(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){j=e.indexBy(t,"contact_id")})}function k(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function L(){o.$emit("LeaveCalendar::monthDestroyed"),N.map(function(e){e.remove?e.remove():e()})}function M(t,n,o){var s,i;return t.contactsData[n]=t.contactsData[n]||{},i=m(n),s=!0===o?a.resolve():a.all([i.isWeekend(p(t.date)),i.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:D(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?T(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function x(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return M(e,t.id)}))}))}function $(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!F)&&w())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=R(e);t&&(h(t),-1!==I().indexOf(e.status_id)&&u(e))}function U(e){return a.all(P(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var F=!1,N=[],j={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=L,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,i,r,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(i.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=D[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&r.publish("ManagerBadge:: Update Count"),r.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(D,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:D[e].label,isDirectAction:D[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,D={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return r.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,c.serverDateFormat).toDate()}function h(e){return t(e).format(c.serverDateFormat)}function v(e){var t;return i.resolve().then(function(){N(e),"from"===e&&F(),S("hours")&&(_(e),"from"!==e||te.uiOptions.multipleDays||_("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return i.reject("Please change date as it is not in any absence period")}).then(W).then(function(){if(t)return x()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(V(),!t)return E();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(P).finally(y)}function b(){return V(),E()}function g(){return te.uiOptions.toDate=null,N("to"),i.resolve().then(V).then(te.setDaysSelectionModeExtended).then(y).then(!te.uiOptions.multipleDays&&E)}function _(e){te.uiOptions.times[e].loading=!0}function y(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,S("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function C(){return te.request?te.request.request_type:te.leaveType||null}function D(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(j).catch(P)}function P(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function R(){return te.isMode("create")||te.forceRecalculateBalanceChange?E():T()}function A(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():i.resolve()}function I(){ee.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){Q()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){J(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",E))}function w(){te.isMode("edit")&&(te.isLeaveStatus(c.statusNames.approved)||te.isLeaveStatus(c.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function O(){o.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(K(e),V()))})}function S(e){return te.selectedAbsenceType.calculation_unit_name===e}function k(e){return te.request.request_type===e}function L(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function M(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function x(){return u.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function $(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function E(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(j).catch(P).finally(function(){te.loading.balanceChange=!1})):i.resolve()}function B(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function U(){return h(te.request.from_date)===h(te.request.to_date)}function F(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,N("to"))}function N(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),V(),z()}function j(e){te.balance.change=e,te.request.balance_change=e.amount,f(),B(),te.loading.balanceChange=!1}function W(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function H(){return!te.isMode("create")&&U()||te.isMode("create")&&(k("sickness")||S("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,i.resolve().then(te.setDaysSelectionModeExtended)}function G(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function Y(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function V(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(S("hours")||k("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function X(){e.forEach(ee,function(e){e()})}function Q(){var e,t=te.selectedAbsenceType.calculation_unit_name;return Y(),e=t!==te.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&H).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&V).then(y).then(E)}function J(e){return te.absenceTypes=e,Y(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,N("to")),G(),E()}function K(e){var t=D(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(D(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(D(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=c.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:$},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:r.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=b,te.daysSelectionModeChangeHandler=g,te.disableAndShowLoadingTimeInput=_,te.getMomentDateWithGivenTime=D,te.handleError=P,te.isCalculationUnit=S,te.isLeaveType=k,te.isNotWorkingDay=L,te.performBalanceChangeCalculation=E,te.setRequestDateTimesAndDateTypes=V,te.updateEndTimeInputMinTime=K,te.$onDestroy=X,function(){n("RequestModalDetails"+e.capitalize(C(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",te),I(),te.initChildController().then(function(){return i.all([x(),M()])}).then(!te.isMode("create")&&A).then(H).then(function(){if(!te.isMode("create"))return i.resolve().then(te.initTimesExtended).then(V)}).then(!te.isMode("create")&&W).then(w).then(G).then(R).then(O).then(!te.isMode("view")&&te.initWatchersExtended).catch(P).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l){function d(){return O.fileUploader&&O.fileUploader.queue.length>0}function m(){return O.getFilesAmount()0?A.map(function(e){return e.label}).join(", "):""}function q(){return O.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(A.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){w[e.label]=t})})).catch(function(){w=null})}function D(){return c.valuesOf("safe_file_extension").then(function(e){A=e})}function T(e){return!e.attachment_id||O.canManage}function P(){e.forEach(I,function(e){e()})}function R(e,t){O.fileUploader.queue&&O.fileUploader.queue.length>0?O.fileUploader.uploadAll({entityID:O.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var A=[],I=[],w={},O=Object.create(this);return O.filesLoaded=!1,O.fileUploader=null,O.today=Date.now(),O.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",O.userDateFormat=i.DATE_FORMAT,O.$onDestroy=P,O.canRemoveAttachment=T,O.canSubmit=d,O.canUploadMore=m,O.formatDateTime=f,O.getAuthorName=p,O.getFilesAmount=h,O.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",O),g(),a.all([D(),q()]).then(_).finally(function(){O.filesLoaded=!0})}(),O}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,o){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],s.openLeavePopup=a,function(){o=n.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,o,s,i,r,c,u,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var t=j[e.status];t?t(e.leaveRequest):W.refresh()}function b(t){t.dataIndex=e.indexBy(t.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return i.all().then(i.loadCalculationUnits).then(function(t){W.absenceTypes=t,W.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return A("approved",{status_id:N(m.statusNames.approved)})}function C(){return n.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[N(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[N(m.statusNames.awaitingApproval),N(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function D(){return r.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(t){var n=e.find(W.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function T(){return r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return M(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function P(){return n.all([r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),R({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:M(e[0]),expiredTOILS:x(e[1].list)})}).then(function(t){W.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function R(t){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function A(e,t){return R(t).then(function(t){W.sections[e].data=t.list})}function I(){return n.all(Object.values(W.sections).filter(function(e){return e.open}).map(k))}function w(){return A("other",{status_id:{in:[N(m.statusNames.rejected),N(m.statusNames.cancelled)]}})}function O(){return A("pending",{status_id:{in:[N(m.statusNames.awaitingApproval),N(m.statusNames.moreInformationRequired)]}})}function S(){return A("holidays",{public_holiday:!0})}function k(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function L(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){W.leaveRequestStatuses=e.indexBy(t,"value")})}function M(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(W.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function x(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function $(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(t){e.forEach(W.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],B(t,a))})}function B(e,t){var n=W.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function U(){W.loading.content=!0,n.all([D(),C()]).then(function(){W.loading.content=!1}).then(function(){return n.all([I(),h()])})}function F(e){var t=W.sections[e];t.open=!t.open,t.open&&!t.data.length&&k(t)}function N(t){return e.find(W.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var j={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:T},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:P},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w}},W.labelPeriod=g,W.refresh=U,W.toggleSection=F,function(){n.all([L(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return n.all([D(),C()])}).then(function(){W.loading.content=!1}),$()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report", -controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function l(){var e=i.request,t=!!e.from_date&&!!e.to_date,n=i.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function d(){return i.canCalculateChange()}function m(t,n){var a=i.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);i.uiOptions.multipleDays||("from"===t&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=i.convertDateToServerFormat(t),v(t).then(function(n){return n?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(t,i.requestDayTypes).then(function(t){return t.length?t:i.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return I(n,e),e})):o.reject([])}function p(e,n){return e=t(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function h(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function v(e){return c.all({public_holiday:1,contact_id:i.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function b(){return o.resolve()}function g(){return T(i.uiOptions.fromDate,"from").then(function(){return T(i.uiOptions.toDate,"to")})}function _(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,t){i.isCalculationUnit("days")||+e==+t||(i.isRole("staff")&&(i.request.change_balance=!0),S(),i.performBalanceChangeCalculation())})}function y(e){var n=t(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(h(a.min,n)<=0||h(a.max,n)>=0)&&(n="from"===e?a.min:a.max),i.uiOptions.times[e].time=n}function q(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],t=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(R)).then(function(){["from","to"].forEach(function(e){y(e),O(e),t[e].amount=Math.min(i.request[e+"_date_amount"],t[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(S)}function C(){["from","to"].forEach(function(e){_(e),D(e)})}function D(e){s.$watch(function(){return i.uiOptions.times[e].time},function(t,n){i.isCalculationUnit("days")||t===n||(i.setRequestDateTimesAndDateTypes(),t&&O(e,!0))})}function T(e,t){return f(e,t).then(function(){i.loading[t+"DayTypes"]=!1})}function P(e){return T(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return R(e).then(function(){O(e,!0)})})}function R(e){var t=i.uiOptions[e+"Date"],n=!i.uiOptions.multipleDays;return t?i.request.getWorkDayForDate(i.convertDateToServerFormat(t)).then(function(t){L[e]=t,m(e,t),n&&"from"===e&&m("to",t)}).catch(function(t){return L[e]={},i.handleError(t)}).finally(function(){n&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function A(t){var n=i.uiOptions.times[t];i["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function I(t,n){var a="request"+e.startCase(t)+"DayTypes";i[a]=n,i.isMode("create")&&(i.request[t+"_date_type"]=i[a][0].value)}function w(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),R("from").then(function(){O("from",!0)})):o.resolve()}function O(e,t){var n=i.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,c=L[a].number_of_hours?h(s,r).toString():"0";o.maxAmount=c,t&&(o.amount=o.maxAmount)}function S(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function k(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?R("from").then(function(){O("from",!0)}):o.resolve()}var L={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=u,i.canCalculateChange=l,i.canSubmit=d,i.initChildController=b,i.initDayTypesExtended=g,i.initTimesExtended=q,i.initWatchersExtended=C,i.onAbsenceTypeUpdateExtended=k,i.onDateChangeExtended=P,i.resetUIInputsExtended=A,i.setDaysSelectionModeExtended=w}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s,i,r){function c(){return!(!r.canCalculateChange()||!r.request.sickness_reason)}function u(){return a.all([m(),h(),f(!0)])}function l(t){var n=r.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function d(t){return!!e.find(r.sicknessDocumentTypes,function(e){return e.value===t})}function m(){return i.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){r.sicknessDocumentTypes=e})}function f(t){return i.valuesOf("hrleaveandabsences_sickness_reason",t).then(function(t){r.sicknessReasons=e.indexBy(t,"name")})}function p(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}function h(){r.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:r}),r.canSubmit=c,r.initChildController=u,r.isChecked=l,r.isDocumentInRequest=d,r.openSicknessReasonOptionsEditor=p}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=t.duration(t(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,t=!c.uiOptions.multipleDays&&!!c.request.from_date,n=t||e,a=N.from_date!==c.request.from_date||N.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&n&&W.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,t=c.request;return b({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function b(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&W.hasExpirationFromAdminSettings,t=W.hasPreviousExpirationDate,n=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=n&&(a||e||t)}function _(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function y(){return W.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){W.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",y().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function D(){o.$watch(function(){return c.request.toil_to_accrue},function(e,t){+e!=+t&&c.performBalanceChangeCalculation()})}function T(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&c.isCalculationUnit("hours")&&k(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function P(){var e=c.uiOptions.times;e.from.time=t(c.request.from_date).format("HH:mm"),e.to.time=t(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,t){e!==t&&(c.setRequestDateTimesAndDateTypes(),U(),l(),L())})})}function A(){c.isMode("view")||(D(),T(),R())}function I(t){return i.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){c.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function w(){return l(),L(),U()}function O(){return x(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),j?j=!1:L(),U()}function S(e){c.uiOptions.times[e].time=""}function k(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function L(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function M(){N=e.cloneDeep(c.request.attributes())}function x(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function $(){c.setRequestDateTimesAndDateTypes(),l(),L(),c.isCalculationUnit("hours")?k():c.request.toil_to_accrue=null}function E(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){I(!1)})}function B(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function U(){return f()?d().catch(a.resolve):a.resolve()}function F(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var N,j=!c.isMode("create"),W={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=P,c.initWatchersExtended=A,c.onAbsenceTypeUpdateExtended=$,c.onDateChangeExtended=w,c.openToilInDaysAccrualOptionsEditor=E,c.resetUIInputsExtended=S,c.setDaysSelectionModeExtended=O,c.updateExpiryDate=F,function(){M(),x(),B(),!c.isMode("create")&&_()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,D){function T(e){"days"===xe.selectedAbsenceType.calculation_unit_name?delete xe.request[e+"_date_amount"]:delete xe.request[e+"_date_type"]}function P(){["from","to"].forEach(T)}function R(){var e=xe.requestStatuses[y.statusNames.awaitingApproval].value;we.status_id===e&&e!==xe.request.status_id&&d.publish("ManagerBadge:: Update Count")}function A(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!xe.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function O(){var e=A();return xe.isMode("edit")&&(e=e&&(G()||I())),xe.canManage&&xe.requestStatuses&&(e=e&&!!xe.getStatusFromValue(xe.newStatusOnSave)),(e=e&&!!xe.period.id)&&!xe.isMode("view")}function S(){xe.isSelfRecord?xe.request.status_id=xe.requestStatuses[y.statusNames.awaitingApproval].value:xe.canManage&&(xe.request.status_id=xe.newStatusOnSave||xe.request.status_id)}function k(){if(xe.isMode("edit")&&!xe.isRole("staff")&&"toil"!==N())return xe.request.calculateBalanceChange(xe.selectedAbsenceType.calculation_unit_name).then(function(e){if(+xe.balance.change.amount!=+e.amount)return D.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function L(){xe.errors=[]}function M(){return xe.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function x(){ee()&&!xe.isRole("staff")&&(xe.request.change_balance=!0)}function $(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return xe.request.delete().then(function(){xe.dismissModal(),d.publish("LeaveRequest::delete",xe.request)})}})}function E(){r.dismiss({$value:"cancel"})}function B(){var e=N();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return F(xe.getStatusFromValue(xe.request.status_id).name)}function F(e){return n.map(Ae[e],function(e){return xe.requestStatuses[e]})}function N(){return xe.request?xe.request.request_type:xe.leaveType||null}function j(){return!xe.request||e.equals({},xe.requestStatuses)?[]:xe.request.status_id?U():F("none")}function W(e){return n.find(xe.requestStatuses,function(t){return t.value===e})}function H(e){xe.errors=n.isArray(e)?e:[e],xe.loading.absenceTypes=!1,xe.submitting=!1}function G(){return!e.equals(we,xe.request.attributes())||xe.canManage&&xe.newStatusOnSave}function Y(){return xe.postContactSelection=!0,xe.staffMemberSelectionComplete=!1,xe.request.contact_id?o.resolve().then(re).then(ce).then(he).then(be).then(Z).then(z).then(xe.isMode("edit")?ge:n.noop).then(function(){xe.postContactSelection=!1,xe.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==ke)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Ae.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Ae.awaiting_approval=e,Ae.more_information_required=e,Ae.rejected=e,Ae.approved=e,Ae.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return xe.canManage?f.find(xe.request.contact_id).then(function(e){xe.contactName=e.display_name}):o.resolve()}function X(){Oe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",xe.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){H(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Ie++})),i.$on("$destroy",De),i.$on("LeaveRequestPopup::addTab",function(e,t){Me.push(t)})}function Q(){var e,t;xe.request=xe.leaveRequest||null,e=N(),t=xe.initRequestAttributes(),"leave"===e?xe.request=_.init(t):"sickness"===e?xe.request=q.init(t):"toil"===e&&(xe.request=C.init(t))}function J(){var e={};return xe.request?e=xe.request.attributes():xe.canManage||(e={contact_id:Se}),e}function K(){if(Le="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(Le="admin")}).then(function(){return"staff"===Le&&c(y.permissions.ssp.manage).then(function(e){e&&(Le="manager")})}).finally(function(){xe.canManage=xe.isRole("manager")||xe.isRole("admin")})}function Z(){(xe.isRole("admin")||xe.isMode("create")&&xe.isRole("manager"))&&(xe.newStatusOnSave=xe.requestStatuses[y.statusNames.approved].value)}function ee(){return!xe.request.status_id||!n.includes(["cancelled","rejected"],W(xe.request.status_id).name)}function te(e){var t=xe.getStatusFromValue(xe.request.status_id);return!!t&&t.name===e}function ne(e){return xe.request&&xe.request.request_type===e}function ae(e){return xe.mode===e}function oe(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date,"day")&&o.isSameOrBefore(t.end_date,"day")}function se(e){return Le===e}function ie(){return h.all().then(function(e){xe.absencePeriods=e})}function re(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Re={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return xe.loading.entitlements=!0,b.all({contact_id:xe.request.contact_id,period_id:xe.period.id,type_id:{IN:Re.ids}},!0).finally(function(){xe.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Se=e.contactId})}function le(){return xe.selectedContactId?f.find(xe.selectedContactId).then(function(e){xe.managedContacts=[e]}):xe.isRole("admin")?f.all().then(function(e){xe.managedContacts=n.remove(e.list,function(e){return e.id!==Se})}):f.find(Se).then(function(e){return e.leaveManagees()}).then(function(e){xe.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){xe.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){R(),d.publish(e,xe.request),xe.errors=[],xe.dismissModal()}function pe(){["from","to"].forEach(function(e){xe.request[e+"_date"]=we[e+"_date"]})}function he(e){if(xe.absenceTypes=me(Re.types,e),!xe.absenceTypes.length)return o.reject(ke)}function ve(){xe.period=n.find(xe.absencePeriods,function(e){return xe.isMode("create")?e.current:oe(xe.request,e)})}function be(){xe.isMode("create")?(xe.selectedAbsenceType=xe.absenceTypes[0],xe.request.type_id=xe.selectedAbsenceType.id):xe.selectedAbsenceType=n.find(xe.absenceTypes,function(e){return e.id===xe.request.type_id})}function ge(){we=e.copy(xe.request.attributes())}function _e(){var e;xe.request.id?(e=[xe.requestStatuses[y.statusNames.approved].value,xe.requestStatuses[y.statusNames.adminApproved].value,xe.requestStatuses[y.statusNames.rejected].value,xe.requestStatuses[y.statusNames.cancelled].value],xe.mode="edit",xe.isRole("staff")&&e.indexOf(xe.request.status_id)>-1&&(xe.mode="view")):xe.mode="create"}function ye(){var e=xe.request.status_id;if(!xe.isMode("view")&&!xe.submitting)return xe.submitting=!0,S(),P(),xe.request.isValid().then(ee()&&k).then(x).then(!xe.request.change_balance&&pe).then(qe).then(function(){return xe.isMode("edit")?Pe():M()}).catch(function(t){xe.request.status_id=e,t&&H(t)}).finally(function(){xe.submitting=!1})}function qe(){return o.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&n.push(e),++a===Ie&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return Ie>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function De(){Oe.forEach(function(e){e()})}function Te(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Pe(){return xe.request.update().then(Ce).then(function(){xe.isRole("manager")?fe("LeaveRequest::updatedByManager"):(xe.isRole("staff")||xe.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Re,Ae={},Ie=0,we={},Oe=[],Se="",ke="No entitlement",Le="",Me=[],xe=n.assign(this,m);xe.absencePeriods=[],xe.absenceTypes=[],xe.canManage=!1,xe.contactName=null,xe.errors=[],xe.loading={absenceTypes:!0,entitlements:!0},xe.managedContacts=[],xe.mode="",xe.newStatusOnSave=null,xe.period={},xe.postContactSelection=!1,xe.requestStatuses={},xe.selectedAbsenceType={},xe.staffMemberSelectionComplete=!1,xe.submitting=!1,xe.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},xe.canChangeAbsenceType=w,xe.canSubmit=O,xe.closeAlert=L,xe.deleteLeaveRequest=$,xe.dismissModal=E,xe.getStatuses=j,xe.getStatusFromValue=W,xe.initAfterContactSelection=Y,xe.initRequestAttributes=J,xe.isLeaveStatus=te,xe.isLeaveType=ne,xe.isMode=ae,xe.isRole=se,xe.submit=ye,xe.updateAbsenceType=Te,function(){xe.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),ie(),de()]).then(Q).then(_e).then(ve).then(function(){return xe.canManage&&!xe.isMode("edit")&&le()}).then(function(){if(xe.selectedContactId&&(xe.request.contact_id=xe.selectedContactId),xe.request.contact_id)return xe.initAfterContactSelection()}).catch(H).finally(function(){xe.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,i,r,c){function u(e){return r.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,o,i,r){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:o,isSelfRecord:i,forceRecalculateBalanceChange:r}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(t){function n(t,n,a){t.debug("Component: absence-tab-container"),n.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:n}),n.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,t){function n(e,t,n){function a(){return n.all().then(n.loadCalculationUnits).then(function(e){o.absenceTypes=e})}t.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}t.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:n}),n.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,t){function n(t,n,a,o,s,i,r){function c(e){m.errorMessage=e}function u(){return r.get({is_active:!0}).then(function(e){m.workPatterns=e})}function l(e){return s.valuesOf("hrleaveandabsences_work_pattern_change_reason",e).then(function(e){m.changeReasons=e})}function d(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_work_pattern_change_reason?reset=1").on("crmUnload",function(){l(!1)})}t.debug("Component: absence-tab-custom-work-pattern-modal");var m=Object.create(this);return m.changeReasons=[],m.errorMessage="",m.saveInProgress=!1,m.workPatterns=[],m.loading={content:!0},m.selected={workPattern:null,effectiveDate:null,changeReason:null},m.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},m.openWorkPatternChangeReasonEditor=d,function(){n.all([u(),l(!0)]).finally(function(){m.loading.content=!1})}(),m.closeModal=function(){m.dismiss({$value:"cancel"})},m.closeAlert=function(){m.errorMessage=""},m.save=function(){var t=e(m.selected.effectiveDate).format(i.serverDateFormat);return m.saveInProgress=!0,r.assignWorkPattern(m.contactId,m.selected.workPattern.id,t,null,m.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),m.closeModal()}).catch(c).finally(function(){m.saveInProgress=!1})},m}t.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","crmAngService","OptionGroup","shared-settings","WorkPatternAPI",n]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){ -g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrleaveandabsences_work_pattern_change_reason").then(function(t){b=e.indexBy(t,"value")})}function h(e){var t=[m()];return e&&(t=t.concat(e)),g.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){g.loading.workPattern=!1})}function v(){var n,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return n=b[e.change_reason],e.change_reason_label=n?n.label:"",e.effective_date=e.effective_date?t(e.effective_date).format(a):"",e}).sortBy(function(e){return-t(e.effective_date,a).valueOf()}).value()}n.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(),g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){r.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){i.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}n.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i){function r(){return l().then(function(e){q=q.concat(e)})}function c(){var t=e.groupBy(q,"created_date");C.changeLogRows=e.map(t,d).sort(function(e,t){return t.date.diff(e.date)})}function u(e,t){var n,a,o=m(e);e.entitlements.forEach(function(s,i){n=o.entitlements.slice(0,i),a=e.entitlements.slice(i+1),t(s,n,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(n,a){var o,s,i;return s=e.indexBy(n,"entitlement_id.type_id"),i=C.absenceTypes.map(function(t){return o=s[t.id],e.extend({calculation_unit:t.calculation_unit_name},o)}),{date:t(a),entitlements:i}}function m(e){var t;return t=C.changeLogRows.indexOf(e),C.changeLogRows[t+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var t,n,a,o=C.changeLogRows.length-1;o>=0;o--)if(t=C.changeLogRows[o],n=e.pluck(t.entitlements,"comment"),a=e.compact(n),1===a.length){var s=e.findIndex(n,"length");t.highlightedEntitlement=t.entitlements[s]}else a.length>1&&_(o)}function p(e,t){C.changeLogRows.splice(t,0,e)}function h(){return n.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,t;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,t=C.changeLogRows.length-1;e>=0;){var n=C.changeLogRows[e],a=C.changeLogRows[t];n.entitlements.forEach(function(e,t){var n=a.entitlements[t];e.comment===n.comment&&delete e.comment}),e--,t--}}function _(e){var t,n,a=C.changeLogRows[e];u(a,function(o,s,i){o.comment&&(t=s.concat(o).concat(i),n={date:a.date.clone(),entitlements:t},n.highlightedEntitlement=o,p(n,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(r).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}n.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(t,n,a){function o(a,o,s,i,r,c,u,l,d){function m(){D.absencePeriods=t.chain(D.absencePeriods).filter(function(e){return t.find(q,function(t){return t.period_id===e.id})}).sortBy(function(e){return-n(e.start_date).valueOf()}).value()}function f(){D.absenceTypes=t.filter(D.absenceTypes,function(e){return t.find(q,function(t){return t.type_id===e.id})})}function p(t){var n=e.url("civicrm/contact/view",{cid:D.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:t,cid:D.contactId,returnUrl:n})}function h(){return c.all().then(function(e){D.absencePeriods=e})}function v(){var e=t.uniq(t.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=t.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:D.contactId}).then(function(e){q=e})}function g(e){i.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(t){this.contactId=D.contactId,this.dismiss=t.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){D.absencePeriods=t.map(D.absencePeriods,function(e){var n=t.map(D.absenceTypes,function(n){var a=t.find(q,function(t){return t.type_id===n.id&&t.period_id===e.id});return a?{amount:a.value,calculation_unit:n.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:n}})}function y(e){var t=e.message+"

    Last updated:
    By: "+e.author_name+"
    Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
    ";d.info("Calculation comment:",t)}a.debug("Component: annual-entitlements");var q=[],C=[],D=this;D.absencePeriods=[],D.loading={absencePeriods:!0},D.getEditEntitlementsPageURL=p,D.openAnnualEntitlementChangeLog=g,D.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){D.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,t,n){function a(n,a,o,s,i,r){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(t){return e.find(m.contracts,function(n){return e.find(n.info.leave,function(e){return e.leave_type===t.id})})})}function u(e){var n=o.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return i.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,o=e.map(m.absenceTypes,function(t){var a=e.filter(n.leave,function(e){return e.leave_type===t.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:t.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}n.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){r.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}n.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(t){return t.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,t,n,a){n.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,t.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/absence-tab":n+"/absence-tab"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); +!function(e){define("leave-absences/shared/config",[],function(){var n=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":n+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(n){return n.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,n,t){"use strict";t.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(t,a,o){return t.debug("AbsenceTypeAPI"),a.extend({all:function(n){return t.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(n||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return t.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:n(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,n){return e.debug("AbsenceTypeInstance"),n.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,n){"use strict";n.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(n,t,a,o,s,i){return n.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,n,t){return s.calculateToilExpiryDate(e,n,t)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(n){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(t){return t=e.indexBy(t,"value"),e.map(n,function(n){return e.assign(n,{calculation_unit_label:t[n.calculation_unit].label,calculation_unit_name:t[n.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,n){"use strict";n.factory("WorkPatternAPI",["$log","api",function(n,t){function a(n){var t=e.clone(n);return t.workPattern=t["api.WorkPattern.get"].values[0],delete t["api.WorkPattern.get"],t}return n.debug("WorkPatternAPI"),t.extend({assignWorkPattern:function(n,t,a,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:n,pattern_id:t,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(t,a,o,s){return n.debug("WorkPatternAPI.getCalendar",t,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(t)?{IN:t}:t,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(n,t,o){return this.sendGET("ContactWorkPattern","get",e.assign({},t,{contact_id:n,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,n,t){"use strict";t.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(t,a,o,s,i){function r(n,t){return u().then(function(a){var o=this.days[c(n).valueOf()];return!!o&&e.find(a,function(e){return e.name===t}).value===o.type}.bind(this))}function c(e){return n(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(n){var t={};return n.calendar.forEach(function(e){t[c(e.date).valueOf()]=e}),e(n).omit("calendar").assign({days:t}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,n){"use strict";n.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(n,t,a,o){return n.debug("Calendar"),t.extend({get:function(t,s,i,r){return n.debug("Calendar.get"),a.getCalendar(t,s,i,r).then(function(n){var a=n.values.map(function(e){return o.init(e)});return e.isArray(t)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,n){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,t){function a(e){var t=n.clone(e),a=t["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(t.remainder=a[0].remainder),delete t["api.LeavePeriodEntitlement.getremainder"],t}function o(e){var t=n.clone(e),a=t["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return t.value=a,delete t["api.LeavePeriodEntitlement.getentitlement"],t}return e.debug("EntitlementAPI"),t.extend({all:function(n,t){return e.debug("EntitlementAPI.all"),n["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},t&&(n["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",n,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),t&&(e=e.map(a)),e})},breakdown:function(n){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",n).then(function(e){return e.values})},getLeaveBalances:function(n,t,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",n,t,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,n){return e.debug("EntitlementLogAPI"),n.extend({all:function(n){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",n,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,n,t){return e.debug("EntitlementInstance"),n.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return t.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,n){"use strict";n.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(n,t,a,o,s){return n.debug("Entitlement"),t.extend({all:function(e,n){return a.all(this.processFilters(e),n).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(n,t){return a.breakdown(n).then(function(n){return t?(t.map(function(t){var a=e.find(n,function(e){return e.id===t.id});return a&&(t.breakdown=a.breakdown),t}),t):n.map(function(e){return o.init(e,!0)})})},logs:function(n){return n=e.cloneDeep(n||{}),n.contact_id&&(n["entitlement_id.contact_id"]=n.contact_id,delete n.contact_id),n.period_id&&(n["entitlement_id.period_id"]=n.period_id,delete n.period_id),n.return=n.return||[],n.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(n)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,n){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,t,a){return e.debug("LeaveRequestAPI"),t.extend({all:function(n,t,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return n&&n.contact_id&&n.contact_id.IN&&0===n.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",n,t,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(n,t,o,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var i=a.defer();n&&t||i.reject("contact_id and period_id are mandatory");var r={contact_id:n,period_id:t,statuses:o?{IN:o}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",r,!1).then(function(e){i.resolve(e.values)}),i.promise},calculateBalanceChange:function(t){return e.debug("LeaveRequestAPI.calculateBalanceChange",t),this.sendPOST("LeaveRequest","calculatebalancechange",t).then(function(e){return e.values.breakdown=n.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,n){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:n.toString()},!1)},create:function(n){return e.debug("LeaveRequestAPI.create",n),this.sendPOST("LeaveRequest","create",n).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,t,a){return a=n.assign({},a,{leave_request_id:e,attachment_id:t}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,t){return t=n.assign({},t,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",t).then(function(e){return e.values})},find:function(n){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:n}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,t){return t=n.assign({},t,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",t,!1).then(function(e){return e.values})},getComments:function(e,t){return t=n.assign({},t,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",t,!1).then(function(e){return e.values})},isManagedBy:function(n,t){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:n,contact_id:t}).then(function(e){return e.values})},isValid:function(t){e.debug("LeaveRequestAPI.isValid",t);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",t).then(function(e){e.count>0?o.reject(n(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,t,a){return a=n.assign({},a,{leave_request_id:e,text:t.text,contact_id:t.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(n){e.debug("LeaveRequestAPI.update",n);var t=a.defer();return n.id||t.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",n).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,n,t){"use strict";t.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(t,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var n=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=n,t.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return t.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var n=[];return e.forEach(this.files,function(e){e.toBeDeleted&&n.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),t.all(n)}function f(e){return n.duration(e.time_to).subtract(n.duration(e.time_from)).asHours()}function p(n){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){return e.find(t,function(e){return e.name===n})})}function h(n){var a=e.cloneDeep(n),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return t.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(n){return s.amount=n[0].time_from?Math.min(this.from_date_amount,f(n[0])):0,o&&(i.amount=n[1].time_from?Math.min(this.to_date_amount,f(n[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,n){return e+n.amount},0),a}.bind(this))}function v(){var e=this.id,n=[];return n.push(t.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(n){return function(){return r.saveComment(e,n)}}))),n=n.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),t.all(n)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(n){var t=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===n&&e.pull(t,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,t)).then(function(e){return"hours"===n?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return t.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,t.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(n){if(n.comment_id)return void(n.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return n.created_at===e.created_at&&n.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(n){return{amount:e.reduce(n.values,function(e,n){return e+parseFloat(n.amount)},0),breakdown:n.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return t.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):t.resolve()},roleOf:function(e){return this.contact_id===e?t.resolve("owner"):a(s.permissions.admin.administer).then(function(n){return n?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):t.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,n,t,a){return e.debug("LeaveRequest"),n.extend({all:function(e,n,o,s,i){return t.all(this.processFilters(e),n,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,n,a,o){return t.balanceChangeByAbsenceType(e,n,a,o)},find:function(e){return t.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/instances/work-pattern.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("WorkPatternInstance",["$log","ModelInstance",function(e,n){return e.debug("WorkPatternInstance"),n.extend({})}])}),define("leave-absences/shared/models/work-pattern.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/work-pattern.instance"],function(e,n){"use strict";n.factory("WorkPattern",["$log","Model","WorkPatternAPI","WorkPatternInstance",function(n,t,a,o){return n.debug("WorkPattern"),t.extend({assignWorkPattern:function(e,n,t,o,s,i){return a.assignWorkPattern(e,n,t,o,s,i)},default:function(){return a.get({is_default:!0}).then(function(n){return o.init(e.first(n),!0)})},unassignWorkPattern:function(e){return a.unassignWorkPattern(e)},workPatternsOf:function(e,n,t){return a.workPatternsOf(e,n,t).then(function(e){return e.map(function(e){return o.init(e,!0)})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,n,t){function a(t,a,o,s,i,r){function c(){return d().then(function(t){var a=t.filter(function(e){var t=e.info.details;return n(t.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(n(t.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!t.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function u(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?c():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return o.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):i.all()}function m(e){return"me"===e?o.leaveManagees(v.contactId):"unassigned"===e?o.leaveManagees(void 0,{unassigned:!0}):o.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){r.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}t.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,u()}}}t.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(e,n,t){function a(){return{loadContacts:function(){return t.init({id:i.contactId}).leaveManagees().then(function(e){i.lookupContacts=e}).then(o)}}}function o(){return n.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:i.filters.userSettings.department?i.filters.userSettings.department.value:null,level_type:i.filters.userSettings.level_type?i.filters.userSettings.level_type.value:null,location:i.filters.userSettings.location?i.filters.userSettings.location.value:null,region:i.filters.userSettings.region?i.filters.userSettings.region.value:null,id:{IN:i.filters.userSettings.contact?[i.filters.userSettings.contact.id]:i.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var i;return{init:function(e){return i=e,i.showContactName=!0,i.showFilters=!0,a()}}}t.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(e,n){function t(){return{loadContacts:function(){return n.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,t()}}}t.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,n,t,a){function o(a,o,s,i,r,c,u,l,d,m){function f(){for(var e=[],n=t(M.selectedPeriod.start_date).clone().startOf("month"),a=t(M.selectedPeriod.end_date).clone().endOf("month");n.isBefore(a);)e.push(A(n)),n.add(1,"month");M.months=e}function p(){i.$new().$watch(function(){return M.selectedMonths},function(n,t){null===t||e.equals(n,t)||I()})}function h(e){M.injectMonths=!0,S("injected").then(function(){I(e)}).then(function(){M.loading.calendar=!1})}function v(){k=a("LeaveCalendar"+n.capitalize(L)+"Controller").init(M)}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function g(){return c.all().then(function(e){M.absencePeriods=n.sortBy(e,"start_date"),M.selectedPeriod=n.find(M.absencePeriods,function(e){return!!e.current})}).then(f).then(w)}function _(){return u.all().then(u.loadCalculationUnits)}function y(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return k.loadContacts().then(function(e){M.contacts=e})}function C(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){M.filters.optionValues.regions=e.hrjc_region,M.filters.optionValues.locations=e.hrjc_location,M.filters.optionValues.levelTypes=e.hrjc_level_type,M.filters.optionValues.departments=e.hrjc_department})}function T(){return l.all()}function D(){return o.all([_(),T(),y()]).then(function(e){M.supportData.absenceTypes=e[0],M.supportData.publicHolidays=e[1],M.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,M.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,M.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,M.supportData.toilAmounts=n.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function P(){var e=o.resolve();return M.injectMonths&&(e=S("destroyed"),M.injectMonths=!1),e}function A(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function R(e){e=n.includes(["contacts","period"],e)?e:"period",o.resolve().then(function(){M.loading.calendar=!0}).then(P).then("period"===e?f:n.noop).then("contacts"===e?q:n.noop).then(function(){h("contacts"===e)})}function I(e){var t=M.selectedMonths.length?M.months.filter(function(e){return n.includes(M.selectedMonths,e.index)}):M.months;i.$emit("LeaveCalendar::showMonths",t,!!e)}function w(){M.selectedMonths=[t().month()]}function O(){return M.roleOverride?o.resolve().then(function(){L=M.roleOverride}):o.all([m(r.permissions.admin.administer),m(r.permissions.ssp.manage)]).then(function(e){L=e[0]?"admin":e[1]?"manager":"staff"})}function S(e){return o(function(t){var a=0,o=i.$on("LeaveCalendar::month"+n.capitalize(e),function(){++a===M.months.length&&(o(),t())})})}s.debug("Component: leave-calendar");var k,L,M=this;M.absencePeriods=[],M.contacts=[],M.contactIdsToReduceTo=null,M.injectMonths=!1,M.months=[],M.selectedMonths=null,M.selectedPeriod=null,M.showContactName=!1,M.showFilters=!1,M.supportData={},M.loading={calendar:!0,page:!0},M.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},M.labelPeriod=b,M.refresh=R,function(){O().then(p).then(v).then(P).then(g).then(function(){return o.all([q(),D()])}).then(function(){return M.showFilters?C():n.noop}).then(function(){h()}).then(function(){M.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",o]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,n,t){function a(t,a,o){"use strict";function s(e,n,t,a,s){e.stopPropagation(),o.openModal(n,t,a,s)}function i(e){return e.isAM?"AM":e.isPM?"PM":""}function r(e){var t=n(e.from_date).isSame(h.date,"day"),a=n(e.to_date).isSame(h.date,"day");return t?n(e.from_date).format("HH:mm"):a?n(e.to_date).format("HH:mm"):""}function c(n,t){h.contactData.leaveRequestsAttributes[n.id].absenceTypeTitle=e.find(h.supportData.absenceTypes,{id:n.type_id}).title}function u(n,t){var a=e.find(h.supportData.absenceTypes,{id:n.type_id}),o=e.find(h.supportData.calculationUnits,{value:a.calculation_unit});t.unit=o.name}function l(e,n){n.from_date=new Date(e.from_date),n.to_date=new Date(e.to_date)}function d(n,t){"days"===t.unit&&(t.from_date_type=e.find(h.supportData.dayTypes,{value:n.from_date_type}).label,t.to_date_type=e.find(h.supportData.dayTypes,{value:n.to_date_type}).label)}function m(e,n){var t="";t=n.isAccruedTOIL?"AT":"days"===n.unit?i(n):r(e),n.label=t}function f(e){var n=h.contactData.leaveRequestsAttributes[e.id];[u,d,m,l,c].forEach(function(t){t.call(this,e,n)})}function p(){a.$watch("day.contactData.leaveRequests",function(){h.contactData&&h.contactData.leaveRequests&&h.contactData.leaveRequests.forEach(f)},!0)}t.debug("Component: leave-calendar-day");var h=this;h.openLeavePopup=s,function(){p()}()}t.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}), +define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function n(e){function n(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var t=this;t.legendCollapsed=!0,t.getAbsenceTypeStyle=n}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",n]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(e){_([e]),F(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(t){var a=n(),o=t.clone().startOf("month");return e.map(e.times(t.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(G.period.start_date)&&o.isSameOrBefore(G.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return W[e]}function f(){return G.showOnlyWithLeaveRequests?G.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):G.contacts}function p(e){return n(e,c.serverDateFormat)}function h(e){k(e),F(e)}function v(n){var t={request_type:"toil"};return e.some(n,t)&&!e.every(n,t)?e.filter(n,t):n}function b(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){G.supportData.dayTypes=e.indexBy(G.supportData.dayTypes,"name"),G.supportData.leaveRequestStatuses=e.indexBy(G.supportData.leaveRequestStatuses,"value"),G.supportData.publicHolidays=e.transform(G.supportData.publicHolidays,function(e,n){e[p(n.date).valueOf()]=n},{})}function _(e){return e.forEach(function(e){var n=P(e);H[e.contact_id]=H[e.contact_id]||{},n.forEach(function(n){H[e.contact_id][n.date]||(H[e.contact_id][n.date]=[]),H[e.contact_id][n.date].push(e)})}),a.resolve()}function y(){j.push(o.$on("LeaveCalendar::showMonths",E)),j.push(r.subscribe("LeaveRequest::new",u)),j.push(r.subscribe("LeaveRequest::edit",U)),j.push(r.subscribe("LeaveRequest::updatedByManager",U)),j.push(r.subscribe("LeaveRequest::delete",h)),j.push(r.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):U(e.leaveRequest)}))}function q(e,t,a){var o=G.supportData.dayTypes[e];return n(a).isSame(t.from_date,"day")?o.value===t.from_date_type:n(a).isSame(t.to_date,"day")?o.value===t.to_date_type:void 0}function C(e,n){return e.request_type===n}function T(e){return!!G.supportData.publicHolidays[p(e).valueOf()]}function D(n){var t=G.supportData.leaveRequestStatuses[n.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],t)}function P(t){for(var a=[],o=n(t.from_date).clone(),s=n(t.to_date);o.isSameOrBefore(s);)o.month()===G.month.index&&o.year()===G.month.year&&a.push(e.find(G.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function A(n){var t=e.find(G.supportData.leaveRequestStatuses,function(e){return e.name===n});return t?t.value:null}function R(){return[A(c.statusNames.approved),A(c.statusNames.adminApproved),A(c.statusNames.awaitingApproval),A(c.statusNames.moreInformationRequired)]}function I(){return G.month.loading=!0,a.all([O(),w()]).then(S).then($).then(function(){N=!0,G.month.loading=!1})}function w(){return i.all({from_date:{to:G.month.days[G.month.days.length-1].date},to_date:{from:G.month.days[0].date},status_id:{IN:R()},contact_id:{IN:G.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(G.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function O(){var n=G.month.days[0].date,t=G.month.days[G.month.days.length-1].date;return s.get(G.contacts.map(function(e){return e.id}),n,t).then(function(n){W=e.indexBy(n,"contact_id")})}function S(){return G.contactIdsToReduceTo&&(G.contacts=G.contacts.filter(function(n){return e.includes(G.contactIdsToReduceTo,n.contact_id)||e.find(H,function(e){return e.contact_id===n.contact_id})})),a.resolve()}function k(n){var t=P(n);H[n.contact_id]=H[n.contact_id]||{},t.forEach(function(t){e.remove(H[n.contact_id][t.date],function(e){return e.id===n.id})})}function L(){o.$emit("LeaveCalendar::monthDestroyed"),j.map(function(e){e.remove?e.remove():e()})}function M(n,t,o){var s,i;return n.contactsData[t]=n.contactsData[t]||{},i=m(t),s=!0===o?a.resolve():a.all([i.isWeekend(p(n.date)),i.isNonWorkingDay(p(n.date))]).then(function(a){e.assign(n.contactsData[t],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:T(n.date)})}),s.then(function(){return H[t]&&H[t][n.date]?H[t][n.date]:[]}).then(function(a){e.assign(n.contactsData[t],{leaveRequests:a,leaveRequestsToShowInCell:v(a),leaveRequestsAttributes:x(n,a)})})}function x(e,n){var t={};return n.forEach(function(n){t[n.id]={styles:B(n),isAccruedTOIL:n?C(n,"toil"):null,isRequested:n?D(n):null,isAM:n?q("half_day_am",n,e.date):null,isPM:n?q("half_day_pm",n,e.date):null}}),t}function $(){return a.all(G.month.days.map(function(e){return a.all(G.contacts.map(function(n){return M(e,n.id)}))}))}function E(n,t,a){!e.find(t,function(e){return e.index===G.month.index})?G.visible=!1:(G.currentPage=0,G.visible=!0,(a||!N)&&I())}function B(n){var t=e.find(G.supportData.absenceTypes,function(e){return e.id===n.type_id});return n.balance_change>0?{borderColor:t.color}:{borderColor:t.color,backgroundColor:t.color}}function U(e){h(e),-1!==R().indexOf(e.status_id)&&u(e)}function F(e){return a.all(P(e).map(function(n){return M(n,e.contact_id,!0)}))}t.debug("Component: leave-calendar-month");var N=!1,j=[],W={},H={},G=this;G.currentPage=0,G.pageSize=20,G.visible=!1,G.showContactName=!!G.showContactName,G.showOnlyWithLeaveRequests=!!G.showOnlyWithLeaveRequests,G.$onDestroy=L,G.contactsList=f,G.getContactUrl=b,function(){var e=n().month(G.month.index).year(G.month.year);g(),y(),G.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}t.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,n){"use strict";function t(n,t,a){function o(){var n=t.defer();return a.open(e.defaults(s(),{onConfirm:function(){n.resolve(!0)}})),n.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return n.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}n.factory("LeaveRequestService",t),t.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,n,t){function a(t,a,o,s,i,r,c,u){function l(n){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],n)||"toil"===q.leaveRequest.request_type?o.open(h(n)):f(n)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(t){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],t)&&("manager"===q.role||("3"===a?n().isBefore(q.leaveRequest.from_date):"2"===a))}function f(n){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(t){return t?e.assign(i.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(n)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var n=T[e].dialog;return{title:"Confirm "+n.title+"?",copyCancel:"Cancel",copyConfirm:n.btnLabel,classConfirm:"btn-"+n.btnClass,msg:n.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,n,t,a,o){e.stopPropagation(),s.openModal(n,t,a,o)}function b(n){var t=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===t&&r.publish("ManagerBadge:: Update Count"),r.publish("LeaveRequest::statusUpdate",{status:n,leaveRequest:q.leaveRequest})}function g(){var n=q.leaveRequestStatuses[q.leaveRequest.status_id].name,t=e.compact(e.map(T,function(t,a){return e.includes(t.allowedStatuses,n)?a:null}));!m(n)&&e.pull(t,"cancel"),"admin"!==q.role&&e.pull(t,"delete"),"staff"===q.role&&e.pull(t,"approve","reject"),"staff"!==q.role&&_(t),d()&&t.push("delete"),q.allowedActions=e.map(t,function(e){return{key:e,label:T[e].label,isDirectAction:T[e].isDirectAction}})}function _(n){e.each(n,function(t,a){"edit"===t&&(n[a]="respond"),e.includes(["respond","view"],t)&&(n[a]="edit")})}t.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,T={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}t.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return n.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var n=e.indexBy(q.request.comments,"contact_id"),t=Object.keys(n);return r.all({id:{IN:t}},{page:1,size:0}).then(function(n){q.comment.contacts=e.indexBy(n.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}t.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}t.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,n,t){function a(t,a,o,s,i,r,c,u,l,d,m){function f(){ne.balance.closing=ne.balance.opening+ne.balance.change.amount}function p(e){return n(e,c.serverDateFormat).toDate()}function h(e){return n(e).format(c.serverDateFormat)}function v(e){var n;return i.resolve().then(function(){N(e),"from"===e&&F(),S("hours")&&(_(e),"from"!==e||ne.uiOptions.multipleDays||_("to")),ne.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(n=e.id!==ne.period.id,n&&(ne.period=e),!ne.period.id)return i.reject("Please change date as it is not in any absence period")}).then(W).then(function(){if(n)return x()}).then(function(){return ne.onDateChangeExtended&&ne.onDateChangeExtended(e)}).then(function(){if(V(),!n)return E();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(P).finally(y)}function b(){return V(),E()}function g(){return ne.uiOptions.toDate=null,N("to"),i.resolve().then(V).then(ne.setDaysSelectionModeExtended).then(y).then(!ne.uiOptions.multipleDays&&E)}function _(e){ne.uiOptions.times[e].loading=!0}function y(){["from","to"].forEach(function(e){ne.loading[e+"DayTypes"]=!1,S("hours")&&(ne.uiOptions.times[e].loading=!1)})}function q(t){var a=n(ne.uiOptions[t+"Date"]).format(ne.uiOptions.userDateFormat.toUpperCase());return e.find(ne.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function C(){return ne.request?ne.request.request_type:ne.leaveType||null}function T(e){return n().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return z(),ne.loading.balanceChange=!0,ne.request.getBalanceChangeBreakdown().then(j).catch(P)}function P(n){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(n)?n:[n]),ne.loading.fromDayTypes=!1,ne.loading.balanceChange=!1,ne.loading.tab=!1,ne.loading.toDayTypes=!1}function A(){return ne.isMode("create")||ne.forceRecalculateBalanceChange?E():D()}function R(){var e=ne.request.attributes();return ne.uiOptions.fromDate=p(ne.request.from_date),ne.request.to_date=e.to_date,ne.request.to_date_type=e.to_date_type,ne.uiOptions.toDate=p(ne.request.to_date),ne.initDayTypesExtended?ne.initDayTypesExtended():i.resolve()}function I(){ee.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){Q()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,n){J(n)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",E))}function w(){ne.isMode("edit")&&(ne.isLeaveStatus(c.statusNames.approved)||ne.isLeaveStatus(c.statusNames.adminApproved))&&(Z={absenceTypeId:ne.request.type_id,value:ne.selectedAbsenceType.remainder-ne.request.balance_change})}function O(){o.$watch(function(){return ne.uiOptions.times.from.time},function(e,n){e!==n&&(ne.uiOptions.multipleDays||(K(e),V()))})}function S(e){return ne.selectedAbsenceType.calculation_unit_name===e}function k(e){return ne.request.request_type===e}function L(n){return e.includes(["weekend","non_working_day","public_holiday"],n)}function M(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){ne.requestDayTypes=e})}function x(){return u.get(ne.request.contact_id,ne.period.start_date,ne.period.end_date).then(function(e){ne.calendar=e})}function $(){var e=(ne.pagination.currentPage-1)*ne.pagination.numPerPage,n=e+ne.pagination.numPerPage;ne.pagination.filteredbreakdown=ne.balance.change.breakdown.slice(e,n)}function E(){return z(),ne.canCalculateChange()?(ne.loading.balanceChange=!0,ne.request.change_balance=!0,ne.calculateBalanceChange().then(j).catch(P).finally(function(){ne.loading.balanceChange=!1})):i.resolve()}function B(){ne.pagination.totalItems=ne.balance.change.breakdown.length,ne.pagination.filteredbreakdown=ne.balance.change.breakdown,ne.pagination.pageChanged()}function U(){return h(ne.request.from_date)===h(ne.request.to_date)}function F(){ne.uiOptions.toDate&&ne.uiOptions.fromDate&&ne.uiOptions.multipleDays&&n(ne.uiOptions.toDate).isSameOrBefore(ne.uiOptions.fromDate)&&(ne.uiOptions.toDate=null,N("to"))}function N(e){ne.resetUIInputsExtended&&ne.resetUIInputsExtended(e),V(),z()}function j(e){ne.balance.change=e,ne.request.balance_change=e.amount,f(),B(),ne.loading.balanceChange=!1}function W(){var e,t,a;ne.uiOptions.fromDate?(e=n(ne.uiOptions.fromDate).add(1,"day").toDate(),a=e,t=e):(a=p(ne.period.start_date),t=ne.uiOptions.date.to.options.minDate),ne.uiOptions.date.to.options.initDate=t,ne.uiOptions.date.to.options.minDate=a,ne.uiOptions.date.to.options.maxDate=p(ne.period.end_date)}function H(){return!ne.isMode("create")&&U()||ne.isMode("create")&&(k("sickness")||S("hours"))?ne.uiOptions.multipleDays=!1:ne.uiOptions.multipleDays=!0,i.resolve().then(ne.setDaysSelectionModeExtended)}function G(){Z&&Z.absenceTypeId===ne.selectedAbsenceType.id?ne.balance.opening=Z.value||0:ne.balance.opening=ne.selectedAbsenceType.remainder}function Y(){ne.selectedAbsenceType=e.find(ne.absenceTypes,function(e){return e.id===ne.request.type_id})}function V(){var e=ne.uiOptions,n=e.times;ne.request.from_date=e.fromDate?h(e.fromDate):null,ne.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(ne.request.to_date=ne.request.from_date,ne.request.to_date_type=ne.request.from_date_type),(S("hours")||k("toil"))&&(ne.request.from_date=ne.request.from_date&&n.from.time?ne.request.from_date+" "+n.from.time:null,ne.request.to_date=ne.request.to_date&&n.to.time?ne.request.to_date+" "+n.to.time:null)}function z(){ne.uiOptions.showBalance=ne.canCalculateChange()}function X(){e.forEach(ee,function(e){e()})}function Q(){var e,n=ne.selectedAbsenceType.calculation_unit_name;return Y(),e=n!==ne.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&H).then(e&&ne.onAbsenceTypeUpdateExtended).then(e&&V).then(y).then(E)}function J(e){return ne.absenceTypes=e,Y(),n(ne.uiOptions.toDate).isAfter(ne.period.end_date)&&(ne.uiOptions.toDate=void 0,N("to")),G(),E()}function K(e){var n=T(e).add(ne.uiOptions.time_interval,"minutes");n.isAfter(T(ne.uiOptions.times.to.max))||(ne.uiOptions.times.to.min=n.format("HH:mm"),n.isAfter(T(ne.uiOptions.times.to.time))&&(ne.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],ne=this;ne.canManage=!1,ne.calendar={},ne.errors=[],ne.isRequired=!0,ne.requestDayTypes=[],ne.statusNames=c.statusNames,ne.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},ne.pagination={currentPage:1,filteredbreakdown:ne.balance.change.breakdown,numPerPage:7,totalItems:ne.balance.change.breakdown.length,pageChanged:$},ne.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:r.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},ne.convertDateFormatFromServer=p,ne.convertDateToServerFormat=h,ne.dateChangeHandler=v,ne.dateTypeChangeHandler=b,ne.daysSelectionModeChangeHandler=g,ne.disableAndShowLoadingTimeInput=_,ne.getMomentDateWithGivenTime=T,ne.handleError=P,ne.isCalculationUnit=S,ne.isLeaveType=k,ne.isNotWorkingDay=L,ne.performBalanceChangeCalculation=E,ne.setRequestDateTimesAndDateTypes=V,ne.updateEndTimeInputMinTime=K,ne.$onDestroy=X,function(){t("RequestModalDetails"+e.capitalize(C(ne.leaveType,ne.request))+"Controller",{detailsController:ne}),ne.canManage=ne.isRole("manager")||ne.isRole("admin"),ne.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",ne),I(),ne.initChildController().then(function(){return i.all([x(),M()])}).then(!ne.isMode("create")&&R).then(H).then(function(){if(!ne.isMode("create"))return i.resolve().then(ne.initTimesExtended).then(V)}).then(!ne.isMode("create")&&W).then(w).then(G).then(A).then(O).then(!ne.isMode("view")&&ne.initWatchersExtended).catch(P).finally(function(){ne.loading.tab=!1})}()}t.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,n,t){function a(t,a,o,s,i,r,c,u,l){function d(){return O.fileUploader&&O.fileUploader.queue.length>0}function m(){return O.getFilesAmount()0?R.map(function(e){return e.label}).join(", "):""}function q(){return O.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function C(){return a.all(R.map(function(e){return l.getMimeTypeFor(e.label).then(function(n){w[e.label]=n})})).catch(function(){w=null})}function T(){return c.valuesOf("safe_file_extension").then(function(e){R=e})}function D(e){return!e.attachment_id||O.canManage}function P(){e.forEach(I,function(e){e()})}function A(e,n){O.fileUploader.queue&&O.fileUploader.queue.length>0?O.fileUploader.uploadAll({entityID:O.request.id}).then(function(){n()}).catch(n):n()}t.debug("Component: leave-request-popup-files-tab");var R=[],I=[],w={},O=Object.create(this);return O.filesLoaded=!1,O.fileUploader=null,O.today=Date.now(),O.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",O.userDateFormat=i.DATE_FORMAT,O.$onDestroy=P,O.canRemoveAttachment=D,O.canSubmit=d,O.canUploadMore=m,O.formatDateTime=f,O.getAuthorName=p,O.getFilesAmount=h,O.listFileTypes=y,function(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",O),g(),a.all([T(),q()]).then(_).finally(function(){O.filesLoaded=!0})}(),O}t.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function n(e,n,t){function a(e,t,a,o){n.openModal.apply(n,arguments)}e.debug("Component: leave-request-record-actions");var o,s=this;s.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],s.openLeavePopup=a,function(){o=t.parse(),o.openModal&&a(null,o.openModal,s.selectedContactId,s.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",n]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,n,t){function a(n,t,a,o,s,i,r,c,u,l,d,m){function f(e,n){n.data.push(e),n.dataIndex[e.id]=e}function p(e){E(e),W.sections.other.open&&f(e,W.sections.other)}function h(){Object.values(W.sections).forEach(function(e){e.data=[]})}function v(e){var n=j[e.status];n?n(e.leaveRequest):W.refresh()}function b(n){n.dataIndex=e.indexBy(n.data,"id")}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function _(){return s.all().then(function(n){W.absencePeriods=e.sortBy(n,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!0===e.current})})}function y(){return i.all().then(i.loadCalculationUnits).then(function(n){W.absenceTypes=n,W.absenceTypesIndexed=e.indexBy(n,"id")})}function q(){return R("approved",{status_id:N(m.statusNames.approved)})}function C(){return t.all([c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,null,!0),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[N(m.statusNames.approved)]),c.balanceChangeByAbsenceType(W.contactId,W.selectedPeriod.id,[N(m.statusNames.awaitingApproval),N(m.statusNames.moreInformationRequired)])]).then(function(e){W.absenceTypes.forEach(function(n){n.balanceChanges={holidays:e[0][n.id],approved:e[1][n.id],pending:e[2][n.id]}})})}function T(){return r.all({contact_id:W.contactId,period_id:W.selectedPeriod.id},!0).then(function(e){W.entitlements=e}).then(function(){W.absenceTypesFiltered=W.absenceTypes.filter(function(n){var t=e.find(W.entitlements,function(e){return e.type_id===n.id});return n.entitlement=t?t.value:0,n.remainder=t?t.remainder:{current:0,future:0},!(0===n.entitlement&&"1"!==n.allow_overuse&&"1"!==n.allow_accruals_request)})})}function D(){return r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id},W.entitlements).then(function(){return M(W.entitlements)}).then(function(e){W.sections.entitlements.data=e})}function P(){return t.all([r.breakdown({contact_id:W.contactId,period_id:W.selectedPeriod.id,expired:!0}),A({request_type:"toil",expired:!0})]).then(function(e){return t.all({expiredBalanceChangesFlatten:M(e[0]),expiredTOILS:x(e[1].list)})}).then(function(n){W.sections.expired.data=n.expiredBalanceChangesFlatten.concat(n.expiredTOILS),W.sections.expired.data=e.sortBy(W.sections.expired.data,"expiry_date")})}function A(n){return c.all(e.assign({contact_id:W.contactId,from_date:{from:W.selectedPeriod.start_date},to_date:{to:W.selectedPeriod.end_date},type_id:{IN:W.absenceTypes.map(function(e){return e.id})}},n),null,"from_date ASC",null,!1)}function R(e,n){return A(n).then(function(n){W.sections[e].data=n.list})}function I(){return t.all(Object.values(W.sections).filter(function(e){return e.open}).map(k))}function w(){return R("other",{status_id:{in:[N(m.statusNames.rejected),N(m.statusNames.cancelled)]}})}function O(){return R("pending",{status_id:{in:[N(m.statusNames.awaitingApproval),N(m.statusNames.moreInformationRequired)]}})}function S(){return R("holidays",{public_holiday:!0})}function k(e){return e.loading=!0,e.loadLeaveRequests().then(b.bind(this,e)).then(function(){e.loading=!1})}function L(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){W.leaveRequestStatuses=e.indexBy(n,"value")})}function M(n){return t.resolve().then(function(){return n.map(function(n){var t=e.find(W.entitlements,function(e){return e.id===n.id});return n.breakdown.map(function(n){return e.assign(e.clone(n),{type_id:t.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function x(e){return t.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function $(){l.subscribe("LeaveRequest::new",function(){W.refresh()}),l.subscribe("LeaveRequest::edit",function(){W.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){E(e)})}function E(n){e.forEach(W.sections,function(t,a){t.dataIndex[n.id]&&(e.remove(t.data,function(e){return e.id===n.id}),delete t.dataIndex[n.id],B(n,a))})}function B(e,n){var t=W.absenceTypesIndexed[e.type_id],a="pending"===n?"future":"current";t.balanceChanges[n]-=e.balance_change,t.remainder[a]-=e.balance_change}function U(){W.loading.content=!0,t.all([T(),C()]).then(function(){W.loading.content=!1}).then(function(){return t.all([I(),h()])})}function F(e){var n=W.sections[e];n.open=!n.open,n.open&&!n.data.length&&k(n)}function N(n){return e.find(W.leaveRequestStatuses,function(e){return e.name===n}).value}n.debug("Component: staff-leave-report");var j={delete:E,cancel:p},W=this;W.absencePeriods=[],W.absenceTypes=[],W.absenceTypesFiltered=[],W.absenceTypesIndexed={},W.dateFormat=d.DATE_FORMAT,W.leaveRequestStatuses={},W.selectedPeriod=null,W.role="absence-tab"===a.section?"admin":"staff",W.loading={content:!0,page:!0},W.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:D},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:P},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w}},W.labelPeriod=g,W.refresh=U,W.toggleSection=F,function(){t.all([L(),y(),_()]).then(function(){W.loading.page=!1}).then(function(){return t.all([T(),C()])}).then(function(){W.loading.content=!1}),$()}()}t.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){ +function a(t,a,o,s,i,r,c){function u(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function l(){var e=i.request,n=!!e.from_date&&!!e.to_date,t=i.selectedAbsenceType.calculation_unit_name;return"days"===t?n=n&&!!e.from_date_type&&!!e.to_date_type:"hours"===t&&(n=n&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),n}function d(){return i.canCalculateChange()}function m(n,t){var a=i.uiOptions.times[n],o=e.clone(t.time_from),s=e.clone(t.time_to);i.uiOptions.multipleDays||("from"===n&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===n&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===n?a.max:a.min}function f(n,t){return n?(n=i.convertDateToServerFormat(n),v(n).then(function(t){return t?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(n,i.requestDayTypes).then(function(n){return n.length?n:i.requestDayTypes.filter(function(n){return e.includes(["all_day","half_day_am","half_day_pm"],n.name)})})}).then(function(e){return I(t,e),e})):o.reject([])}function p(e,t){return e=n(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?t.filter(function(n){return n.name===e}):[]})}function h(e,t){return n.duration(t).subtract(n.duration(e)).asHours()}function v(e){return c.all({public_holiday:1,contact_id:i.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function b(){return o.resolve()}function g(){return D(i.uiOptions.fromDate,"from").then(function(){return D(i.uiOptions.toDate,"to")})}function _(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,n){i.isCalculationUnit("days")||+e==+n||(i.isRole("staff")&&(i.request.change_balance=!0),S(),i.performBalanceChangeCalculation())})}function y(e){var t=n(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(h(a.min,t)<=0||h(a.max,t)>=0)&&(t="from"===e?a.min:a.max),i.uiOptions.times[e].time=t}function q(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],n=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(A)).then(function(){["from","to"].forEach(function(e){y(e),O(e),n[e].amount=Math.min(i.request[e+"_date_amount"],n[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(S)}function C(){["from","to"].forEach(function(e){_(e),T(e)})}function T(e){s.$watch(function(){return i.uiOptions.times[e].time},function(n,t){i.isCalculationUnit("days")||n===t||(i.setRequestDateTimesAndDateTypes(),n&&O(e,!0))})}function D(e,n){return f(e,n).then(function(){i.loading[n+"DayTypes"]=!1})}function P(e){return D(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return A(e).then(function(){O(e,!0)})})}function A(e){var n=i.uiOptions[e+"Date"],t=!i.uiOptions.multipleDays;return n?i.request.getWorkDayForDate(i.convertDateToServerFormat(n)).then(function(n){L[e]=n,m(e,n),t&&"from"===e&&m("to",n)}).catch(function(n){return L[e]={},i.handleError(n)}).finally(function(){t&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function R(n){var t=i.uiOptions.times[n];i["request"+e.startCase(n)+"DayTypes"]=[],t.time="",t.min="00:00",t.max="00:00",t.amount="0",t.maxAmount="0"}function I(n,t){var a="request"+e.startCase(n)+"DayTypes";i[a]=t,i.isMode("create")&&(i.request[n+"_date_type"]=i[a][0].value)}function w(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),A("from").then(function(){O("from",!0)})):o.resolve()}function O(e,n){var t=i.uiOptions,a=t.multipleDays?e:"from",o=t.times[a],s=t.multipleDays&&"to"===a?o.min:t.times.from.time,r=t.multipleDays&&"from"===a?o.max:t.times.to.time,c=L[a].number_of_hours?h(s,r).toString():"0";o.maxAmount=c,n&&(o.amount=o.maxAmount)}function S(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function k(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?A("from").then(function(){O("from",!0)}):o.resolve()}var L={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=u,i.canCalculateChange=l,i.canSubmit=d,i.initChildController=b,i.initDayTypesExtended=g,i.initTimesExtended=q,i.initWatchersExtended=C,i.onAbsenceTypeUpdateExtended=k,i.onDateChangeExtended=P,i.resetUIInputsExtended=R,i.setDaysSelectionModeExtended=w}t.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,n){function t(n,t,a,o,s,i,r){function c(){return!(!r.canCalculateChange()||!r.request.sickness_reason)}function u(){return a.all([m(),h(),f(!0)])}function l(n){var t=r.request.getDocumentArray();return!!e.find(t,function(e){return e===n})}function d(n){return!!e.find(r.sicknessDocumentTypes,function(e){return e.value===n})}function m(){return i.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){r.sicknessDocumentTypes=e})}function f(n){return i.valuesOf("hrleaveandabsences_sickness_reason",n).then(function(n){r.sicknessReasons=e.indexBy(n,"name")})}function p(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}function h(){r.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}t.debug("RequestModalDetailsSicknessController"),n("RequestModalDetailsLeaveController",{detailsController:r}),r.canSubmit=c,r.initChildController=u,r.isChecked=l,r.isDocumentInRequest=d,r.openSicknessReasonOptionsEditor=p}n.controller("RequestModalDetailsSicknessController",t),t.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=n.duration(n(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,n=!c.uiOptions.multipleDays&&!!c.request.from_date,t=n||e,a=N.from_date!==c.request.from_date||N.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&t&&W.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,n=c.request;return b({hasErrors:e?!n.to_date&&!n.from_date:!n.from_date,label:e?"To Date":"From Date",value:n.to_date})}function b(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return a.reject([t])}return e.value?a.resolve(n(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&W.hasExpirationFromAdminSettings,n=W.hasPreviousExpirationDate,t=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=t&&(a||e||n)}function _(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function y(){return W.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){W.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",y().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function T(){o.$watch(function(){return c.request.toil_to_accrue},function(e,n){+e!=+n&&c.performBalanceChangeCalculation()})}function D(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,n){e!==n&&c.isCalculationUnit("hours")&&k(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function P(){var e=c.uiOptions.times;e.from.time=n(c.request.from_date).format("HH:mm"),e.to.time=n(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function A(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,n){e!==n&&(c.setRequestDateTimesAndDateTypes(),U(),l(),L())})})}function R(){c.isMode("view")||(T(),D(),A())}function I(n){return i.valuesOf("hrleaveandabsences_toil_amounts",n).then(function(n){c.toilAmounts=e.sortBy(n,function(e){return+e.weight})})}function w(){return l(),L(),U()}function O(){return x(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),j?j=!1:L(),U()}function S(e){c.uiOptions.times[e].time=""}function k(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function L(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function M(){N=e.cloneDeep(c.request.attributes())}function x(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function $(){c.setRequestDateTimesAndDateTypes(),l(),L(),c.isCalculationUnit("hours")?k():c.request.toil_to_accrue=null}function E(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){I(!1)})}function B(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function U(){return f()?d().catch(a.resolve):a.resolve()}function F(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var N,j=!c.isMode("create"),W={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=P,c.initWatchersExtended=R,c.onAbsenceTypeUpdateExtended=$,c.onDateChangeExtended=w,c.openToilInDaysAccrualOptionsEditor=E,c.resetUIInputsExtended=S,c.setDaysSelectionModeExtended=O,c.updateExpiryDate=F,function(){M(),x(),B(),!c.isMode("create")&&_()}()}t.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,t,a){return e.debug("AbsencePeriodInstance"),t.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var t=n();return e.current=!1,n(e.start_date).isSameOrBefore(t,"day")&&n(e.end_date).isSameOrAfter(t,"day")&&(e.current=!0),e},isInPeriod:function(e){var t=a.DATE_FORMAT.toUpperCase(),o=n(e,t);return n(this.start_date).isSameOrBefore(o)&&n(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,n){return e.debug("AbsencePeriodAPI"),n.extend({all:function(n){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,t,a,o,s){return e.debug("AbsencePeriod"),t.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=n().format(s.serverDateFormat),t={start_date:{"<=":e},end_date:{">=":e}};return a.all(t).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,n){return e.debug("PublicHolidayAPI"),n.extend({all:function(n){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,n){return e.debug("PublicHolidayInstance"),n.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,n){"use strict";n.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(n,t,a,o,s){return n.debug("PublicHoliday"),t.extend({all:function(e){return n.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(t){n.debug("PublicHoliday.isPublicHoliday",t);var o=e(t).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},t.defaultCustomData(),n)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(n){var t=this.getDocumentArray(),a=t.indexOf(n);e.contains(t,n)?t.splice(a,1):t.push(n),this.sickness_required_documents=t.join(",")},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},t.defaultCustomData(),n)},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,n,t,a){"use strict";function o(n,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C,T){function D(e){"days"===xe.selectedAbsenceType.calculation_unit_name?delete xe.request[e+"_date_amount"]:delete xe.request[e+"_date_type"]}function P(){["from","to"].forEach(D)}function A(){var e=xe.requestStatuses[y.statusNames.awaitingApproval].value;we.status_id===e&&e!==xe.request.status_id&&d.publish("ManagerBadge:: Update Count")}function R(){return Me.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Me.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!xe.loading.entitlements&&(!!se("admin")||!ae("view")&&!(se("manager")&&!ae("create")))}function O(){var e=R();return xe.isMode("edit")&&(e=e&&(G()||I())),xe.canManage&&xe.requestStatuses&&(e=e&&!!xe.getStatusFromValue(xe.newStatusOnSave)),(e=e&&!!xe.period.id)&&!xe.isMode("view")}function S(){xe.isSelfRecord?xe.request.status_id=xe.requestStatuses[y.statusNames.awaitingApproval].value:xe.canManage&&(xe.request.status_id=xe.newStatusOnSave||xe.request.status_id)}function k(){if(xe.isMode("edit")&&!xe.isRole("staff")&&"toil"!==N())return xe.request.calculateBalanceChange(xe.selectedAbsenceType.calculation_unit_name).then(function(e){if(+xe.balance.change.amount!=+e.amount)return T.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function L(){xe.errors=[]}function M(){return xe.request.create().then(Ce).then(function(){fe("LeaveRequest::new")})}function x(){ee()&&!xe.isRole("staff")&&(xe.request.change_balance=!0)}function $(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return xe.request.delete().then(function(){xe.dismissModal(),d.publish("LeaveRequest::delete",xe.request)})}})}function E(){r.dismiss({$value:"cancel"})}function B(){var e=N();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return F(xe.getStatusFromValue(xe.request.status_id).name)}function F(e){return t.map(Re[e],function(e){return xe.requestStatuses[e]})}function N(){return xe.request?xe.request.request_type:xe.leaveType||null}function j(){return!xe.request||e.equals({},xe.requestStatuses)?[]:xe.request.status_id?U():F("none")}function W(e){return t.find(xe.requestStatuses,function(n){return n.value===e})}function H(e){xe.errors=t.isArray(e)?e:[e],xe.loading.absenceTypes=!1,xe.submitting=!1}function G(){return!e.equals(we,xe.request.attributes())||xe.canManage&&xe.newStatusOnSave}function Y(){return xe.postContactSelection=!0,xe.staffMemberSelectionComplete=!1,xe.request.contact_id?o.resolve().then(re).then(ce).then(he).then(be).then(Z).then(z).then(xe.isMode("edit")?ge:t.noop).then(function(){xe.postContactSelection=!1,xe.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==ke)return o.reject(e)}):o.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Re.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Re.awaiting_approval=e,Re.more_information_required=e,Re.rejected=e,Re.approved=e,Re.cancelled=[y.statusNames.awaitingApproval].concat(e)}function z(){return xe.canManage?f.find(xe.request.contact_id).then(function(e){xe.contactName=e.display_name}):o.resolve()}function X(){Oe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",ge),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){ce().then(he).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",xe.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,n){H(n)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Ie++})),i.$on("$destroy",Te),i.$on("LeaveRequestPopup::addTab",function(e,n){Me.push(n)})}function Q(){var e,n;xe.request=xe.leaveRequest||null,e=N(),n=xe.initRequestAttributes(),"leave"===e?xe.request=_.init(n):"sickness"===e?xe.request=q.init(n):"toil"===e&&(xe.request=C.init(n))}function J(){var e={};return xe.request?e=xe.request.attributes():xe.canManage||(e={contact_id:Se}),e}function K(){if(Le="staff","my-leave"!==s.section)return c(y.permissions.admin.administer).then(function(e){e&&(Le="admin")}).then(function(){return"staff"===Le&&c(y.permissions.ssp.manage).then(function(e){e&&(Le="manager")})}).finally(function(){xe.canManage=xe.isRole("manager")||xe.isRole("admin")})}function Z(){(xe.isRole("admin")||xe.isMode("create")&&xe.isRole("manager"))&&(xe.newStatusOnSave=xe.requestStatuses[y.statusNames.approved].value)}function ee(){return!xe.request.status_id||!t.includes(["cancelled","rejected"],W(xe.request.status_id).name)}function ne(e){var n=xe.getStatusFromValue(xe.request.status_id);return!!n&&n.name===e}function te(e){return xe.request&&xe.request.request_type===e}function ae(e){return xe.mode===e}function oe(e,n){var t=a(e.from_date),o=a(e.to_date);return t.isSameOrAfter(n.start_date,"day")&&o.isSameOrBefore(n.end_date,"day")}function se(e){return Le===e}function ie(){return h.all().then(function(e){xe.absencePeriods=e})}function re(){return v.all(B()).then(v.loadCalculationUnits).then(function(e){Ae={types:e,ids:e.map(function(e){return e.id})}})}function ce(){return xe.loading.entitlements=!0,b.all({contact_id:xe.request.contact_id,period_id:xe.period.id,type_id:{IN:Ae.ids}},!0).finally(function(){xe.loading.entitlements=!1})}function ue(){return p.get().then(function(e){Se=e.contactId})}function le(){return xe.selectedContactId?f.find(xe.selectedContactId).then(function(e){xe.managedContacts=[e]}):xe.isRole("admin")?f.all().then(function(e){xe.managedContacts=t.remove(e.list,function(e){return e.id!==Se})}):f.find(Se).then(function(e){return e.leaveManagees()}).then(function(e){xe.managedContacts=e})}function de(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){xe.requestStatuses=t.indexBy(e,"name")})}function me(e,n){var a;return t.compact(e.map(function(e){if(a=t.find(n,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){A(),d.publish(e,xe.request),xe.errors=[],xe.dismissModal()}function pe(){["from","to"].forEach(function(e){xe.request[e+"_date"]=we[e+"_date"]})}function he(e){if(xe.absenceTypes=me(Ae.types,e),!xe.absenceTypes.length)return o.reject(ke)}function ve(){xe.period=t.find(xe.absencePeriods,function(e){return xe.isMode("create")?e.current:oe(xe.request,e)})}function be(){xe.isMode("create")?(xe.selectedAbsenceType=xe.absenceTypes[0],xe.request.type_id=xe.selectedAbsenceType.id):xe.selectedAbsenceType=t.find(xe.absenceTypes,function(e){return e.id===xe.request.type_id})}function ge(){we=e.copy(xe.request.attributes())}function _e(){var e;xe.request.id?(e=[xe.requestStatuses[y.statusNames.approved].value,xe.requestStatuses[y.statusNames.adminApproved].value,xe.requestStatuses[y.statusNames.rejected].value,xe.requestStatuses[y.statusNames.cancelled].value],xe.mode="edit",xe.isRole("staff")&&e.indexOf(xe.request.status_id)>-1&&(xe.mode="view")):xe.mode="create"}function ye(){var e=xe.request.status_id;if(!xe.isMode("view")&&!xe.submitting)return xe.submitting=!0,S(),P(),xe.request.isValid().then(ee()&&k).then(x).then(!xe.request.change_balance&&pe).then(qe).then(function(){return xe.isMode("edit")?Pe():M()}).catch(function(n){xe.request.status_id=e,n&&H(n)}).finally(function(){xe.submitting=!1})}function qe(){return o.all(Me.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Ce(){function e(e){e&&t.push(e),++a===Ie&&(t.length>0?n.reject(t):n.resolve())}var n=o.defer(),t=[],a=0;return Ie>0?s.$broadcast("LeaveRequestPopup::submit",e):n.resolve(),n.promise}function Te(){Oe.forEach(function(e){e()})}function De(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Pe(){return xe.request.update().then(Ce).then(function(){xe.isRole("manager")?fe("LeaveRequest::updatedByManager"):(xe.isRole("staff")||xe.isRole("admin"))&&fe("LeaveRequest::edit")})}n.debug("RequestCtrl");var Ae,Re={},Ie=0,we={},Oe=[],Se="",ke="No entitlement",Le="",Me=[],xe=t.assign(this,m);xe.absencePeriods=[],xe.absenceTypes=[],xe.canManage=!1,xe.contactName=null,xe.errors=[],xe.loading={absenceTypes:!0,entitlements:!0},xe.managedContacts=[],xe.mode="",xe.newStatusOnSave=null,xe.period={},xe.postContactSelection=!1,xe.requestStatuses={},xe.selectedAbsenceType={},xe.staffMemberSelectionComplete=!1,xe.submitting=!1,xe.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},xe.canChangeAbsenceType=w,xe.canSubmit=O,xe.closeAlert=L,xe.deleteLeaveRequest=$,xe.dismissModal=E,xe.getStatuses=j,xe.getStatusFromValue=W,xe.initAfterContactSelection=Y,xe.initRequestAttributes=J,xe.isLeaveStatus=ne,xe.isLeaveType=te,xe.isMode=ae,xe.isRole=se,xe.submit=ye,xe.updateAbsenceType=De,function(){xe.loading.absenceTypes=!0,V(),X(),o.all([ue(),K(),ie(),de()]).then(Q).then(_e).then(ve).then(function(){return xe.canManage&&!xe.isMode("edit")&&le()}).then(function(){if(xe.selectedContactId&&(xe.request.contact_id=xe.selectedContactId),xe.request.contact_id)return xe.initAfterContactSelection()}).catch(H).finally(function(){xe.loading.absenceTypes=!1})}()}n.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,n){"use strict";function t(e,n,t,a,o,s,i,r,c){function u(e){return r.get().then(function(n){return e.roleOf(n.contactId)}).then(function(e){return"none"!==e})}function l(e,t,o,i,r){a.open({appendTo:n.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:t,leaveRequest:e,selectedContactId:o,isSelfRecord:i,forceRecalculateBalanceChange:r}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(n){n?l(e,e.request_type,e.contact_id,"my-leave"===t.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}n.factory("LeavePopup",t),t.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(n){function t(n,t,a){n.debug("Component: absence-tab-container"),t.section="absence-tab",this.contactId=e.adminId,function(){a.getDateFormat()}()}n.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:t}),t.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,n){function t(e,n,t){function a(){return t.all().then(t.loadCalculationUnits).then(function(e){o.absenceTypes=e})}n.debug("Component: absence-tab-entitlements");var o=this;o.absenceTypes=[],o.loading={component:!0},function(){a().finally(function(){o.loading.component=!1})}()}n.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:t}),t.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,n){function t(n,t,a,o,s,i,r){function c(e){m.errorMessage=e}function u(){return r.get({is_active:!0}).then(function(e){m.workPatterns=e})}function l(e){return s.valuesOf("hrleaveandabsences_work_pattern_change_reason",e).then(function(e){m.changeReasons=e})}function d(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_work_pattern_change_reason?reset=1").on("crmUnload",function(){l(!1)})}n.debug("Component: absence-tab-custom-work-pattern-modal");var m=Object.create(this);return m.changeReasons=[],m.errorMessage="",m.saveInProgress=!1,m.workPatterns=[],m.loading={content:!0},m.selected={workPattern:null,effectiveDate:null,changeReason:null},m.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},m.openWorkPatternChangeReasonEditor=d,function(){t.all([u(),l(!0)]).finally(function(){m.loading.content=!1})}(),m.closeModal=function(){m.dismiss({$value:"cancel"})},m.closeAlert=function(){m.errorMessage=""},m.save=function(){var n=e(m.selected.effectiveDate).format(i.serverDateFormat);return m.saveInProgress=!0,r.assignWorkPattern(m.contactId,m.selected.workPattern.id,n,null,m.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),m.closeModal()}).catch(c).finally(function(){m.saveInProgress=!1})},m}n.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","crmAngService","OptionGroup","shared-settings","WorkPatternAPI",t]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,n,t){function a(t,a,o,s,i,r,c,u,l,d){function m(){return d.workPatternsOf(g.contactId,{},!1).then(function(e){g.customWorkPatterns=e})}function f(){return d.default().then(function(e){g.defaultWorkPattern=e})}function p(){return l.valuesOf("hrleaveandabsences_work_pattern_change_reason").then(function(n){b=e.indexBy(n,"value")})}function h(e){var n=[m()];return e&&(n=n.concat(e)),g.loading.workPattern=!0,a.all(n).then(function(){v()}).finally(function(){g.loading.workPattern=!1})} +function v(){var t,a=u.DATE_FORMAT.toUpperCase();g.customWorkPatterns=e(g.customWorkPatterns).map(function(e){return t=b[e.change_reason],e.change_reason_label=t?t.label:"",e.effective_date=e.effective_date?n(e.effective_date).format(a):"",e}).sortBy(function(e){return-n(e.effective_date,a).valueOf()}).value()}t.debug("Component: absence-tab-work-patterns");var b=[],g=Object.create(this);return g.customWorkPatterns=[],g.defaultWorkPattern=null,g.linkToWorkPatternListingPage=function(){var e=CRM.url("civicrm/contact/view",{cid:g.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:g.contactId,returnUrl:e})}(),g.loading={workPattern:!0},function(){h([p(),f(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){h()})}(),g.deleteWorkPattern=function(e){r.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){h()})}})},g.openModal=function(){i.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},g}t.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,n,t){function a(t,a,o,s,i){function r(){return l().then(function(e){q=q.concat(e)})}function c(){var n=e.groupBy(q,"created_date");C.changeLogRows=e.map(n,d).sort(function(e,n){return n.date.diff(e.date)})}function u(e,n){var t,a,o=m(e);e.entitlements.forEach(function(s,i){t=o.entitlements.slice(0,i),a=e.entitlements.slice(i+1),n(s,t,a)})}function l(){return o.all({contact_id:C.contactId,period_id:C.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function d(t,a){var o,s,i;return s=e.indexBy(t,"entitlement_id.type_id"),i=C.absenceTypes.map(function(n){return o=s[n.id],e.extend({calculation_unit:n.calculation_unit_name},o)}),{date:n(a),entitlements:i}}function m(e){var n;return n=C.changeLogRows.indexOf(e),C.changeLogRows[n+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function f(){for(var n,t,a,o=C.changeLogRows.length-1;o>=0;o--)if(n=C.changeLogRows[o],t=e.pluck(n.entitlements,"comment"),a=e.compact(t),1===a.length){var s=e.findIndex(t,"length");n.highlightedEntitlement=n.entitlements[s]}else a.length>1&&_(o)}function p(e,n){C.changeLogRows.splice(n,0,e)}function h(){return t.all({id:C.periodId}).then(function(e){C.absencePeriod=e[0]})}function v(e){return a.all().then(a.loadCalculationUnits).then(function(e){C.absenceTypes=e})}function b(){return o.logs({contact_id:C.contactId,period_id:C.periodId}).then(function(e){q=e})}function g(){var e,n;if(!(C.changeLogRows.length<=1))for(e=C.changeLogRows.length-2,n=C.changeLogRows.length-1;e>=0;){var t=C.changeLogRows[e],a=C.changeLogRows[n];t.entitlements.forEach(function(e,n){var t=a.entitlements[n];e.comment===t.comment&&delete e.comment}),e--,n--}}function _(e){var n,t,a=C.changeLogRows[e];u(a,function(o,s,i){o.comment&&(n=s.concat(o).concat(i),t={date:a.date.clone(),entitlements:n},t.highlightedEntitlement=o,p(t,e++))}),y(e)}function y(e){C.changeLogRows.splice(e,1)}var q=[],C=this;C.absencePeriod=null,C.absenceTypes=[],C.changeLogRows=[],C.loading={component:!0},function(){h().then(v).then(b).then(r).then(c).then(g).then(f).finally(function(){C.loading.component=!1})}()}t.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(n,t,a){function o(a,o,s,i,r,c,u,l,d){function m(){T.absencePeriods=n.chain(T.absencePeriods).filter(function(e){return n.find(q,function(n){return n.period_id===e.id})}).sortBy(function(e){return-t(e.start_date).valueOf()}).value()}function f(){T.absenceTypes=n.filter(T.absenceTypes,function(e){return n.find(q,function(n){return n.type_id===e.id})})}function p(n){var t=e.url("civicrm/contact/view",{cid:T.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:n,cid:T.contactId,returnUrl:t})}function h(){return c.all().then(function(e){T.absencePeriods=e})}function v(){var e=n.uniq(n.map(q,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){C=n.indexBy(e.list,"contact_id")})}function b(){return u.all({contact_id:T.contactId}).then(function(e){q=e})}function g(e){i.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(n){this.contactId=T.contactId,this.dismiss=n.dismiss,this.periodId=e}],controllerAs:"modal"})}function _(){T.absencePeriods=n.map(T.absencePeriods,function(e){var t=n.map(T.absenceTypes,function(t){var a=n.find(q,function(n){return n.type_id===t.id&&n.period_id===e.id});return a?{amount:a.value,calculation_unit:t.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:C[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:t}})}function y(e){var n=e.message+"

    Last updated:
    By: "+e.author_name+"
    Date: "+t.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
    ";d.info("Calculation comment:",n)}a.debug("Component: annual-entitlements");var q=[],C=[],T=this;T.absencePeriods=[],T.loading={absencePeriods:!0},T.getEditEntitlementsPageURL=p,T.openAnnualEntitlementChangeLog=g,T.showComment=y,function(){b().then(v).then(h).then(m).then(f).then(_).finally(function(){T.loading.absencePeriods=!1})}()}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,n,t){function a(t,a,o,s,i,r){function c(){m.absenceTypes=e.filter(m.absenceTypes,function(n){return e.find(m.contracts,function(t){return e.find(t.info.leave,function(e){return e.leave_type===n.id})})})}function u(e){var t=o.DATE_FORMAT.toUpperCase();return e?n(e).format(t):""}function l(){return i.all({contact_id:m.contactId}).then(function(e){m.contracts=e})}function d(){m.contracts=e.sortBy(m.contracts,function(e){return n(e.info.details.period_start_date)}).map(function(n){var t=n.info,a=t.details,o=e.map(m.absenceTypes,function(n){var a=e.filter(t.leave,function(e){return e.leave_type===n.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:n.calculation_unit_name}});return{position:a.position,start_date:u(a.period_start_date),end_date:u(a.period_end_date),absences:o}})}t.debug("Component: contract-entitlements");var m=this;m.contracts=[],m.loading={contracts:!0},function(){r.getDateFormat().then(l).then(c).then(d).finally(function(){m.loading.contracts=!1})}()}t.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(n){return n.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,n,t,a){t.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,n.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,n,t,a){e.debug("app.run"),n.sharedPathTpl=t.sharedPathTpl,n.settings=a}]),e}),function(e,n){var t=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";n.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":t+"/shared","leave-absences/absence-tab":t+"/absence-tab"}}),n(["leave-absences/shared/config"],function(){n(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/absence-tab.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js index 76648352352..4021b985697 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.min.js @@ -6,9 +6,9 @@ */ -!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return U(e)&&e.then&&e.$$promises}if(!U(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!U(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},U(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||F(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!U(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=U(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=F(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(D.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:U(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!D[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return D[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=D;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=D;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),w.current)}).then(null,function(a){return a===P?S:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=P(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function D(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=P(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function P(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:S(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function L(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return U(n)?e+G(n):(n=t.$eval(n),U(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,U=t.isObject,F=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;aWhen All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(D(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){E.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function D(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function P(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){E.selectedMonths=[n().month()]}function T(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=P,function(){T().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return F[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){U.push(r.$on("LeaveCalendar::showMonths",M)),U.push(i.subscribe("LeaveRequest::new",c)),U.push(i.subscribe("LeaveRequest::edit",j)),U.push(i.subscribe("LeaveRequest::updatedByManager",j)),U.push(i.subscribe("LeaveRequest::delete",h)),U.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function D(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function P(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[P(u.statusNames.approved),P(u.statusNames.adminApproved),P(u.statusNames.awaitingApproval),P(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([O(),T()]).then(g).then(L).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){F=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),U.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function L(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=D(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,U=[],F={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}), -define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){U(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return L()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,U("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(F).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function D(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function P(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function S(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function T(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function L(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(F).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,U("to"))}function U(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function F(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,U("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([L(),E()])}).then(!te.isMode("create")&&P).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(S).then(V).then(D).then(T).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?P.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(P.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){P=e})}function A(e){return!e.attachment_id||T.canManage}function w(){e.forEach(R,function(e){e()})}function D(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var P=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=w,T.canRemoveAttachment=A,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=h,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){F.filters.leaveRequest.contact_id=null,F.refresh()}function p(){var e=F.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?F.leaveRequests.filter.list.length:F.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(F.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(F.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(F.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(F.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){F.absencePeriods=e.sortBy(t,"start_date"),F.filters.leaveRequest.selectedPeriod=e.find(F.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){F.absenceTypes=e})}function w(e){return(F.isAdmin?r.all(p()):r.leaveManagees(F.contactId,p())).then(function(t){return F.filteredUsers=F.isAdmin?t.list:t,e?P(e):n.all([P("table"),P("filter")])}).then(function(){F.filters.leaveRequest.leaveStatus!==H&&0===F.leaveRequests.table.list.length&&F.refresh(1,!0)})}function D(){return s.valuesOf("hrjc_department").then(function(e){F.departments=e})}function P(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:F.pagination,r="filter"===e?{return:["status_id"]}:{};return F.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){F.leaveRequests[e]=t}).catch(function(){F.leaveRequests[e].list=[]}).finally(function(){F.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){F.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){F.locations=e})}function T(t){var n=F.filters.leaveRequest;return{contact_id:E(),managed_by:F.isAdmin&&"me"!==n.assignedTo.type?void 0:F.contactId,status_id:M(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(F.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){F.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){F.leaveRequestStatuses=e.concat(F.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function E(){return F.filteredUsers.length>0&&F.filters.leaveRequest.contact_id?F.filters.leaveRequest.contact_id:{IN:F.filteredUsers.map(function(e){return e.id})}}function L(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function M(e){var t=F.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=L(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(F.filters.leaveRequest.leaveStatus=H),(e<=F.totalNoOfPages()||0===F.totalNoOfPages())&&(F.pagination.page=e,w(n))}function j(e){F.filters.leaveRequest.leaveStatus=e,F.refresh(1,!1,"table")}function B(e){F.filters.leaveRequest.assignedTo=e,F.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){F.refresh()}),f.subscribe("LeaveRequest::new",function(){F.refresh()}),f.subscribe("LeaveRequest::edit",function(){F.refresh()}),f.subscribe("LeaveRequest::delete",function(){F.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){F.refresh()})}function U(){return Math.ceil(F.leaveRequests.table.total/F.pagination.size)}t.debug("Component: manage-leave-requests");var F=this,H={name:"all",label:"All"};F.absencePeriods=[],F.absenceTypes=[],F.filteredUsers=[],F.isFilterExpanded=!1,F.isAdmin=!1,F.leaveRequests={table:{list:[]},filter:{list:[]}},F.leaveRequestStatuses=[H],F.loading={content:!0,page:!0,table:!0},F.pagination={page:1,size:7},F.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],F.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:F.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:F.filtersByAssignee[0]}},F.clearStaffSelection=m,F.countLeaveRequestByStatus=h,F.getAbsenceTypeByID=v,F.getArrayOfSize=g,F.getLeaveStatusByValue=b,F.getNavBadge=y,F.getUserNameByID=q,F.labelPeriod=$,F.openLeavePopup=x,F.refresh=k,F.refreshWithFilter=j,F.refreshWithFilterByAssignee=B,F.totalNoOfPages=U,function(){o(i.permissions.admin.administer).then(function(e){F.isAdmin=e,n.all([C(),A(),O(),D(),S(),R(),I()]).then(function(){F.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function l(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function d(){return s.canCalculateChange()}function f(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=s.convertDateToServerFormat(t),v(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return R(n,e),e})):r.reject([])}function p(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function h(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function v(e){return u.all({public_holiday:1,contact_id:s.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function g(){return r.resolve()}function b(){return A(s.uiOptions.fromDate,"from").then(function(){return A(s.uiOptions.toDate,"to")})}function y(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),O(),s.performBalanceChangeCalculation())})}function _(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(h(a.min,n)<=0||h(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function q(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(D)).then(function(){["from","to"].forEach(function(e){_(e),T(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(O)}function $(){["from","to"].forEach(function(e){y(e),C(e)})}function C(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&T(e,!0))})}function A(e,t){return m(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function w(e){return A(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return D(e).then(function(){T(e,!0)})})}function D(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){x[e]=t,f(e,t),n&&"from"===e&&f("to",t)}).catch(function(t){return x[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function P(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function R(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),D("from").then(function(){T("from",!0)})):r.resolve()}function T(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=x[a].number_of_hours?h(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function O(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function I(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?D("from").then(function(){T("from",!0)}):r.resolve()}var x={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=c,s.canCalculateChange=l,s.canSubmit=d,s.initChildController=g,s.initDayTypesExtended=b,s.initTimesExtended=q,s.initWatchersExtended=$,s.onAbsenceTypeUpdateExtended=I,s.onDateChangeExtended=w,s.resetUIInputsExtended=P,s.setDaysSelectionModeExtended=S}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s,i){function u(){return!(!i.canCalculateChange()||!i.request.sickness_reason)}function c(){return a.all([f(),h(),m(!0)])}function l(t){var n=i.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function d(t){return!!e.find(i.sicknessDocumentTypes,function(e){return e.value===t})}function f(){return s.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){i.sicknessDocumentTypes=e})}function m(t){return s.valuesOf("hrleaveandabsences_sickness_reason",t).then(function(t){i.sicknessReasons=e.indexBy(t,"name")})}function p(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){m(!1)})}function h(){i.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:i}),i.canSubmit=u,i.initChildController=c,i.isChecked=l,i.isDocumentInRequest=d,i.openSicknessReasonOptionsEditor=p}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=U.from_date!==u.request.from_date||U.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&H.hasExpirationFromAdminSettings,t=H.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&u.isCalculationUnit("hours")&&I(),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){ -var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function D(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),B(),l(),x())})})}function P(){u.isMode("view")||(C(),A(),D())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function S(){return l(),x(),B()}function T(){return L(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),F?F=!1:x(),B()}function O(e){u.uiOptions.times[e].time=""}function I(){u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours}function x(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function E(){U=e.cloneDeep(u.request.attributes())}function L(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function M(){u.setRequestDateTimesAndDateTypes(),l(),x(),u.isCalculationUnit("hours")?I():u.request.toil_to_accrue=null}function k(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){R(!1)})}function j(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function B(){return m()?d().catch(a.resolve):a.resolve()}function N(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var U,F=!u.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=P,u.onAbsenceTypeUpdateExtended=M,u.onDateChangeExtended=S,u.openToilInDaysAccrualOptionsEditor=k,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=T,u.updateExpiryDate=N,function(){E(),L(),j(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,r,o){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(o.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function D(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=P();return Le.isMode("edit")&&(e=e&&(V()||R())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function O(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function I(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==U())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){me("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=U();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(Pe[e],function(e){return Le.requestStatuses[e]})}function U(){return Le.request?Le.request.request_type:Le.leaveType||null}function F(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Se,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Pe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Pe.awaiting_approval=e,Pe.more_information_required=e,Pe.rejected=e,Pe.approved=e,Pe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?m.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=U(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date,"day")&&r.isSameOrBefore(t.end_date,"day")}function oe(e){return xe===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){De={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:De.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Le.selectedContactId?m.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?m.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){D(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Se[e+"_date"]})}function he(e){if(Le.absenceTypes=fe(De.types,e),!Le.absenceTypes.length)return r.reject(Ie)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Se=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,O(),w(),Le.request.isValid().then(ee()&&I).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?we():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?me("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var De,Pe={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Ee=[],Le=n.assign(this,f);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=S,Le.canSubmit=T,Le.closeAlert=x,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=F,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=Ae,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){ -return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(t){return t.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM),define("leave-absences/admin-dashboard/modules/config",["common/angular","leave-absences/admin-dashboard/modules/settings"],function(e){return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(e,t,n,a,r,o){var s={format:["DateFormat",function(e){return e.getDateFormat()}]};r.debugEnabled(o.debug),t.defaults.stripTrailingSlashes=!1,a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:s}).state("calendar",{url:"/calendar",template:'',resolve:s}).state("leave-balances",{url:"/leave-balances",template:"",resolve:s})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function t(e,t){e.debug("Component: admin-dashboard-container"),t.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",t]})}),define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/admin-dashboard":n+"/admin-dashboard"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); +!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in T)B(T[o])&&(t[o]=T[o](t,T.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=x[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),w.current)}).then(null,function(a){return a===D?T:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function T(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:T(e)||t.$current,inherit:!0}}function E(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function x(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function M(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,T(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function L(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;aWhen All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(x.selectedPeriod.start_date).clone().startOf("month"),a=n(x.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");x.months=e}function p(){s.$new().$watch(function(){return x.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){x.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){x.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(E)+"Controller").init(x)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){x.absencePeriods=t.sortBy(e,"start_date"),x.selectedPeriod=t.find(x.absencePeriods,function(e){return!!e.current})}).then(m).then(T)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){x.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){x.filters.optionValues.regions=e.hrjc_region,x.filters.optionValues.locations=e.hrjc_location,x.filters.optionValues.levelTypes=e.hrjc_level_type,x.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){x.supportData.absenceTypes=e[0],x.supportData.publicHolidays=e[1],x.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,x.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,x.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,x.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return x.injectMonths&&(e=O("destroyed"),x.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){x.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=x.selectedMonths.length?x.months.filter(function(e){return t.includes(x.selectedMonths,e.index)}):x.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function T(){x.selectedMonths=[n().month()]}function S(){return x.roleOverride?r.resolve().then(function(){E=x.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){E=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===x.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,E,x=this;x.absencePeriods=[],x.contacts=[],x.contactIdsToReduceTo=null,x.injectMonths=!1,x.months=[],x.selectedMonths=null,x.selectedPeriod=null,x.showContactName=!1,x.showFilters=!1,x.supportData={},x.loading={calendar:!0,page:!0},x.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},x.labelPeriod=g,x.refresh=D,function(){S().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return x.showFilters?$():t.noop}).then(function(){h()}).then(function(){x.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function s(e){return e.isAM?"AM":e.isPM?"PM":""}function i(e){var n=t(e.from_date).isSame(h.date,"day"),a=t(e.to_date).isSame(h.date,"day");return n?t(e.from_date).format("HH:mm"):a?t(e.to_date).format("HH:mm"):""}function u(t,n){h.contactData.leaveRequestsAttributes[t.id].absenceTypeTitle=e.find(h.supportData.absenceTypes,{id:t.type_id}).title}function c(t,n){var a=e.find(h.supportData.absenceTypes,{id:t.type_id}),r=e.find(h.supportData.calculationUnits,{value:a.calculation_unit});n.unit=r.name}function l(e,t){t.from_date=new Date(e.from_date),t.to_date=new Date(e.to_date)}function d(t,n){"days"===n.unit&&(n.from_date_type=e.find(h.supportData.dayTypes,{value:t.from_date_type}).label,n.to_date_type=e.find(h.supportData.dayTypes,{value:t.to_date_type}).label)}function f(e,t){var n="";n=t.isAccruedTOIL?"AT":"days"===t.unit?s(t):i(e),t.label=n}function m(e){var t=h.contactData.leaveRequestsAttributes[e.id];[c,d,f,l,u].forEach(function(n){n.call(this,e,t)})}function p(){a.$watch("day.contactData.leaveRequests",function(){h.contactData&&h.contactData.leaveRequests&&h.contactData.leaveRequests.forEach(m)},!0)}n.debug("Component: leave-calendar-day");var h=this;h.openLeavePopup=o,function(){p()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),N(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(V.period.start_date)&&r.isSameOrBefore(V.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return H[e]}function m(){return V.showOnlyWithLeaveRequests?V.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):V.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),N(e)}function v(t){var n={request_type:"toil"};return e.some(t,n)&&!e.every(t,n)?e.filter(t,n):t}function g(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){V.supportData.dayTypes=e.indexBy(V.supportData.dayTypes,"name"),V.supportData.leaveRequestStatuses=e.indexBy(V.supportData.leaveRequestStatuses,"value"),V.supportData.publicHolidays=e.transform(V.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]||(W[e.contact_id][t.date]=[]),W[e.contact_id][t.date].push(e)})}),a.resolve()}function _(){U.push(r.$on("LeaveCalendar::showMonths",k)),U.push(i.subscribe("LeaveRequest::new",c)),U.push(i.subscribe("LeaveRequest::edit",B)),U.push(i.subscribe("LeaveRequest::updatedByManager",B)),U.push(i.subscribe("LeaveRequest::delete",h)),U.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var r=V.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!V.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=V.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===V.month.index&&r.year()===V.month.year&&a.push(e.find(V.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){var n=e.find(V.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function D(){return[P(u.statusNames.approved),P(u.statusNames.adminApproved),P(u.statusNames.awaitingApproval),P(u.statusNames.moreInformationRequired)]}function R(){return V.month.loading=!0,a.all([S(),T()]).then(O).then(L).then(function(){F=!0,V.month.loading=!1})}function T(){return s.all({from_date:{to:V.month.days[V.month.days.length-1].date},to_date:{from:V.month.days[0].date},status_id:{IN:D()},contact_id:{IN:V.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(V.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function S(){var t=V.month.days[0].date,n=V.month.days[V.month.days.length-1].date;return o.get(V.contacts.map(function(e){return e.id}),t,n).then(function(t){H=e.indexBy(t,"contact_id")})}function O(){return V.contactIdsToReduceTo&&(V.contacts=V.contacts.filter(function(t){return e.includes(V.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function I(t){var n=w(t);W[t.contact_id]=W[t.contact_id]||{},n.forEach(function(n){e.remove(W[t.contact_id][n.date],function(e){return e.id===t.id})})}function E(){r.$emit("LeaveCalendar::monthDestroyed"),U.map(function(e){e.remove?e.remove():e()})}function x(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return W[n]&&W[n][t.date]?W[n][t.date]:[]}).then(function(a){e.assign(t.contactsData[n],{leaveRequests:a,leaveRequestsToShowInCell:v(a),leaveRequestsAttributes:M(t,a)})})}function M(e,t){var n={};return t.forEach(function(t){n[t.id]={styles:j(t),isAccruedTOIL:t?$(t,"toil"):null,isRequested:t?A(t):null,isAM:t?q("half_day_am",t,e.date):null,isPM:t?q("half_day_pm",t,e.date):null}}),n}function L(){return a.all(V.month.days.map(function(e){return a.all(V.contacts.map(function(t){return x(e,t.id)}))}))}function k(t,n,a){!e.find(n,function(e){return e.index===V.month.index})?V.visible=!1:(V.currentPage=0,V.visible=!0,(a||!F)&&R())}function j(t){var n=e.find(V.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){h(e),-1!==D().indexOf(e.status_id)&&c(e)}function N(e){return a.all(w(e).map(function(t){return x(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var F=!1,U=[],H={},W={},V=this;V.currentPage=0,V.pageSize=20,V.visible=!1,V.showContactName=!!V.showContactName,V.showOnlyWithLeaveRequests=!!V.showOnlyWithLeaveRequests,V.$onDestroy=E,V.contactsList=m,V.getContactUrl=g,function(){var e=t().month(V.month.index).year(V.month.year);b(),_(),V.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){ +return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function T(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function E(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function x(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function L(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:L},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=E,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),x()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(T).then(V).then(P).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function f(){return S.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){T[e.label]=t})})).catch(function(){T=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||S.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],T={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=w,S.canRemoveAttachment=A,S.canSubmit=d,S.canUploadMore=f,S.formatDateTime=m,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(S(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function T(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function S(t){var n=U.filters.leaveRequest;return{contact_id:x(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:L(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function E(e,t,n,a){d.openModal.apply(d,arguments)}function x(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function M(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function L(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=M(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=h,U.getAbsenceTypeByID=v,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=E,U.refresh=k,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),O(),P(),T(),R(),I()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function l(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function d(){return s.canCalculateChange()}function f(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=s.convertDateToServerFormat(t),v(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return R(n,e),e})):r.reject([])}function p(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function h(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function v(e){return u.all({public_holiday:1,contact_id:s.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function g(){return r.resolve()}function b(){return A(s.uiOptions.fromDate,"from").then(function(){return A(s.uiOptions.toDate,"to")})}function y(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),O(),s.performBalanceChangeCalculation())})}function _(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(h(a.min,n)<=0||h(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function q(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(P)).then(function(){["from","to"].forEach(function(e){_(e),S(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(O)}function $(){["from","to"].forEach(function(e){y(e),C(e)})}function C(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&S(e,!0))})}function A(e,t){return m(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function w(e){return A(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return P(e).then(function(){S(e,!0)})})}function P(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){E[e]=t,f(e,t),n&&"from"===e&&f("to",t)}).catch(function(t){return E[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function D(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function R(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function T(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),P("from").then(function(){S("from",!0)})):r.resolve()}function S(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=E[a].number_of_hours?h(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function O(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function I(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?P("from").then(function(){S("from",!0)}):r.resolve()}var E={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=c,s.canCalculateChange=l,s.canSubmit=d,s.initChildController=g,s.initDayTypesExtended=b,s.initTimesExtended=q,s.initWatchersExtended=$,s.onAbsenceTypeUpdateExtended=I,s.onDateChangeExtended=w,s.resetUIInputsExtended=D,s.setDaysSelectionModeExtended=T}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s,i){function u(){return!(!i.canCalculateChange()||!i.request.sickness_reason)}function c(){return a.all([f(),h(),m(!0)])}function l(t){var n=i.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function d(t){return!!e.find(i.sicknessDocumentTypes,function(e){return e.value===t})}function f(){return s.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){i.sicknessDocumentTypes=e})}function m(t){return s.valuesOf("hrleaveandabsences_sickness_reason",t).then(function(t){i.sicknessReasons=e.indexBy(t,"name")})}function p(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){m(!1)})}function h(){i.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:i}),i.canSubmit=u,i.initChildController=c,i.isChecked=l,i.isDocumentInRequest=d,i.openSicknessReasonOptionsEditor=p}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=F.from_date!==u.request.from_date||F.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&H.hasExpirationFromAdminSettings,t=H.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&u.isCalculationUnit("hours")&&I(),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),B(),l(),E())})})}function D(){u.isMode("view")||(C(),A(),P())}function R(t){ +return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function T(){return l(),E(),B()}function S(){return M(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),U?U=!1:E(),B()}function O(e){u.uiOptions.times[e].time=""}function I(){u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours}function E(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function x(){F=e.cloneDeep(u.request.attributes())}function M(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function L(){u.setRequestDateTimesAndDateTypes(),l(),E(),u.isCalculationUnit("hours")?I():u.request.toil_to_accrue=null}function k(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){R(!1)})}function j(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function B(){return m()?d().catch(a.resolve):a.resolve()}function N(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var F,U=!u.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onAbsenceTypeUpdateExtended=L,u.onDateChangeExtended=T,u.openToilInDaysAccrualOptionsEditor=k,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=N,function(){x(),M(),j(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),r=t(e,n);return t(this.start_date).isSameOrBefore(r)&&t(this.end_date).isSameOrAfter(r)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,r,o){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},current:function(){var e=t().format(o.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Me.selectedAbsenceType.calculation_unit_name?delete Me.request[e+"_date_amount"]:delete Me.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Me.requestStatuses[_.statusNames.awaitingApproval].value;Te.status_id===e&&e!==Me.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return xe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return xe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return!Me.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=D();return Me.isMode("edit")&&(e=e&&(V()||R())),Me.canManage&&Me.requestStatuses&&(e=e&&!!Me.getStatusFromValue(Me.newStatusOnSave)),(e=e&&!!Me.period.id)&&!Me.isMode("view")}function O(){Me.isSelfRecord?Me.request.status_id=Me.requestStatuses[_.statusNames.awaitingApproval].value:Me.canManage&&(Me.request.status_id=Me.newStatusOnSave||Me.request.status_id)}function I(){if(Me.isMode("edit")&&!Me.isRole("staff")&&"toil"!==F())return Me.request.calculateBalanceChange(Me.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Me.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function E(){Me.errors=[]}function x(){return Me.request.create().then($e).then(function(){me("LeaveRequest::new")})}function M(){ee()&&!Me.isRole("staff")&&(Me.request.change_balance=!0)}function L(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Me.request.delete().then(function(){Me.dismissModal(),d.publish("LeaveRequest::delete",Me.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Me.getStatusFromValue(Me.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Me.requestStatuses[e]})}function F(){return Me.request?Me.request.request_type:Me.leaveType||null}function U(){return!Me.request||e.equals({},Me.requestStatuses)?[]:Me.request.status_id?B():N("none")}function H(e){return n.find(Me.requestStatuses,function(t){return t.value===e})}function W(e){Me.errors=n.isArray(e)?e:[e],Me.loading.absenceTypes=!1,Me.submitting=!1}function V(){return!e.equals(Te,Me.request.attributes())||Me.canManage&&Me.newStatusOnSave}function G(){return Me.postContactSelection=!0,Me.staffMemberSelectionComplete=!1,Me.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Me.isMode("edit")?be:n.noop).then(function(){Me.postContactSelection=!1,Me.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Me.canManage?m.find(Me.request.contact_id).then(function(e){Me.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Me.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){xe.push(t)})}function K(){var e,t;Me.request=Me.leaveRequest||null,e=F(),t=Me.initRequestAttributes(),"leave"===e?Me.request=y.init(t):"sickness"===e?Me.request=q.init(t):"toil"===e&&(Me.request=$.init(t))}function X(){var e={};return Me.request?e=Me.request.attributes():Me.canManage||(e={contact_id:Oe}),e}function Q(){if(Ee="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(Ee="admin")}).then(function(){return"staff"===Ee&&u(_.permissions.ssp.manage).then(function(e){e&&(Ee="manager")})}).finally(function(){Me.canManage=Me.isRole("manager")||Me.isRole("admin")})}function Z(){(Me.isRole("admin")||Me.isMode("create")&&Me.isRole("manager"))&&(Me.newStatusOnSave=Me.requestStatuses[_.statusNames.approved].value)}function ee(){return!Me.request.status_id||!n.includes(["cancelled","rejected"],H(Me.request.status_id).name)}function te(e){var t=Me.getStatusFromValue(Me.request.status_id);return!!t&&t.name===e}function ne(e){return Me.request&&Me.request.request_type===e}function ae(e){return Me.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date,"day")&&r.isSameOrBefore(t.end_date,"day")}function oe(e){return Ee===e}function se(){return h.all().then(function(e){Me.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Me.loading.entitlements=!0,g.all({contact_id:Me.request.contact_id,period_id:Me.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Me.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Me.selectedContactId?m.find(Me.selectedContactId).then(function(e){Me.managedContacts=[e]}):Me.isRole("admin")?m.all().then(function(e){Me.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Me.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Me.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Me.request),Me.errors=[],Me.dismissModal()}function pe(){["from","to"].forEach(function(e){Me.request[e+"_date"]=Te[e+"_date"]})}function he(e){if(Me.absenceTypes=fe(Pe.types,e),!Me.absenceTypes.length)return r.reject(Ie)}function ve(){Me.period=n.find(Me.absencePeriods,function(e){return Me.isMode("create")?e.current:re(Me.request,e)})}function ge(){Me.isMode("create")?(Me.selectedAbsenceType=Me.absenceTypes[0],Me.request.type_id=Me.selectedAbsenceType.id):Me.selectedAbsenceType=n.find(Me.absenceTypes,function(e){return e.id===Me.request.type_id})}function be(){Te=e.copy(Me.request.attributes())}function ye(){var e;Me.request.id?(e=[Me.requestStatuses[_.statusNames.approved].value,Me.requestStatuses[_.statusNames.adminApproved].value,Me.requestStatuses[_.statusNames.rejected].value,Me.requestStatuses[_.statusNames.cancelled].value],Me.mode="edit",Me.isRole("staff")&&e.indexOf(Me.request.status_id)>-1&&(Me.mode="view")):Me.mode="create"}function _e(){var e=Me.request.status_id;if(!Me.isMode("view")&&!Me.submitting)return Me.submitting=!0,O(),w(),Me.request.isValid().then(ee()&&I).then(M).then(!Me.request.change_balance&&pe).then(qe).then(function(){return Me.isMode("edit")?we():x()}).catch(function(t){Me.request.status_id=e,t&&W(t)}).finally(function(){Me.submitting=!1})}function qe(){return r.all(xe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Me.request.update().then($e).then(function(){Me.isRole("manager")?me("LeaveRequest::updatedByManager"):(Me.isRole("staff")||Me.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Te={},Se=[],Oe="",Ie="No entitlement",Ee="",xe=[],Me=n.assign(this,f);Me.absencePeriods=[],Me.absenceTypes=[],Me.canManage=!1,Me.contactName=null,Me.errors=[],Me.loading={absenceTypes:!0,entitlements:!0},Me.managedContacts=[],Me.mode="",Me.newStatusOnSave=null,Me.period={},Me.postContactSelection=!1,Me.requestStatuses={},Me.selectedAbsenceType={},Me.staffMemberSelectionComplete=!1,Me.submitting=!1,Me.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Me.canChangeAbsenceType=T,Me.canSubmit=S,Me.closeAlert=E,Me.deleteLeaveRequest=L,Me.dismissModal=k,Me.getStatuses=U,Me.getStatusFromValue=H,Me.initAfterContactSelection=G,Me.initRequestAttributes=X,Me.isLeaveStatus=te,Me.isLeaveType=ne,Me.isMode=ae,Me.isRole=oe,Me.submit=_e,Me.updateAbsenceType=Ae,function(){Me.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Me.canManage&&!Me.isMode("edit")&&le()}).then(function(){if(Me.selectedContactId&&(Me.request.contact_id=Me.selectedContactId),Me.request.contact_id)return Me.initAfterContactSelection()}).catch(W).finally(function(){Me.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n), +n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(t){return t.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM),define("leave-absences/admin-dashboard/modules/config",["common/angular","leave-absences/admin-dashboard/modules/settings"],function(e){return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(e,t,n,a,r,o){var s={format:["DateFormat",function(e){return e.getDateFormat()}]};r.debugEnabled(o.debug),t.defaults.stripTrailingSlashes=!1,a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:s}).state("calendar",{url:"/calendar",template:'',resolve:s}).state("leave-balances",{url:"/leave-balances",template:"",resolve:s})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function t(e,t){e.debug("Component: admin-dashboard-container"),t.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",t]})}),define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/admin-dashboard":n+"/admin-dashboard"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/admin-dashboard.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js index fc7b12948a5..c2092846c18 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.min.js @@ -6,9 +6,9 @@ */ -!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return U(e)&&e.then&&e.$$promises}if(!U(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!U(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},U(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||F(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!U(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=U(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=F(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:U(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),w.current)}).then(null,function(a){return a===D?S:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function T(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:S(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=T(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=T(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function L(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return U(n)?e+G(n):(n=t.$eval(n),U(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,U=t.isObject,F=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n){function a(e){e.absencePeriods&&c.absencePeriods.length&&(c.filters.period_id=o().id),e.absenceTypes&&c.absenceTypes.length&&(c.filters.type_id=s().id),(e.loggedInContactId||e.userRole)&&(c.filters.managed_by="manager"===c.userRole?c.loggedInContactId:void 0),r()&&c.submitFilters()}function r(){return e.every(c.filters,function(e){return null!==e})}function o(){return e.find(c.absencePeriods,function(e){return e.current})||c.absencePeriods.reduce(function(e,n){return t(e.end_date).isAfter(n.end_date)?e:n})}function s(){return c.absenceTypes.reduce(function(e,t){return e.title.localeCompare(t.title)?e:t})}function i(e){return e.current?"Current Period ("+e.title+")":e.title}function u(){n.$emit("LeaveBalanceFilters::update",c.filters)}var c=this;c.filters={period_id:null,type_id:null,managed_by:null},c.$onChanges=a,c.labelPeriod=i,c.submitFilters=u}n.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,t){return e.extend({all:function(e,n,a,r,o){return t.getLeaveBalances(this.processFilters(e),n,a,r,o)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){return r.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function p(){return o.all().then(o.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function h(){return s.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function v(){return n.all([m(),p(),h(),g(),q()]).catch(function(e){u.error("Error",e)})}function g(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function b(){return P.loading.report=!0,i.all(w,P.pagination,void 0,void 0,!1).then(function(e){P.report=y(e.list),P.reportCount=e.total}).catch(function(e){u.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function y(n){return n.map(function(n){return n=e.copy(n),n.absence_types=t.indexBy(n.absence_types,function(e){return e.id}),n})}function _(){a.$on("LeaveBalanceFilters::update",C),c.subscribe("LeaveRequest::new",$)}function q(){return f(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function $(e){C(e,w)}function C(e,t){w=t,P.pagination.page=1,A(),P.loadReportCurrentPage()}function A(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+w.type_id})}var w={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.loadReportCurrentPage=b,function(){_(),v().then(function(){P.loading.component=!1})}()}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return f(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(m(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function f(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function m(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){E.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){E.selectedMonths=[n().month()]}function T(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=D,function(){T().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return F[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){U.push(r.$on("LeaveCalendar::showMonths",M)),U.push(i.subscribe("LeaveRequest::new",c)),U.push(i.subscribe("LeaveRequest::edit",j)),U.push(i.subscribe("LeaveRequest::updatedByManager",j)),U.push(i.subscribe("LeaveRequest::delete",h)),U.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([O(),T()]).then(g).then(L).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){F=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),U.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function L(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,U=[],F={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}), -define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){U(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return L()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,U("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(F).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function S(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function T(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function L(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(F).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,U("to"))}function U(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function F(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,U("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([L(),E()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(S).then(V).then(P).then(T).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return T.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||T.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){T.fileUploader.queue&&T.fileUploader.queue.length>0?T.fileUploader.uploadAll({entityID:T.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],S={},T=Object.create(this);return T.filesLoaded=!1,T.fileUploader=null,T.today=Date.now(),T.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",T.userDateFormat=s.DATE_FORMAT,T.$onDestroy=w,T.canRemoveAttachment=A,T.canSubmit=d,T.canUploadMore=f,T.formatDateTime=m,T.getAuthorName=p,T.getFilesAmount=h,T.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",T),b(),a.all([C(),q()]).then(y).finally(function(){T.filesLoaded=!0})}(),T}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){F.filters.leaveRequest.contact_id=null,F.refresh()}function p(){var e=F.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?F.leaveRequests.filter.list.length:F.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(F.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(F.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(F.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(F.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){F.absencePeriods=e.sortBy(t,"start_date"),F.filters.leaveRequest.selectedPeriod=e.find(F.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){F.absenceTypes=e})}function w(e){return(F.isAdmin?r.all(p()):r.leaveManagees(F.contactId,p())).then(function(t){return F.filteredUsers=F.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){F.filters.leaveRequest.leaveStatus!==H&&0===F.leaveRequests.table.list.length&&F.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){F.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:F.pagination,r="filter"===e?{return:["status_id"]}:{};return F.loading[n]=!0,l.all(T(t),a,"from_date DESC",r,!1).then(function(t){F.leaveRequests[e]=t}).catch(function(){F.leaveRequests[e].list=[]}).finally(function(){F.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){F.levelTypes=e})}function S(){return s.valuesOf("hrjc_location").then(function(e){F.locations=e})}function T(t){var n=F.filters.leaveRequest;return{contact_id:E(),managed_by:F.isAdmin&&"me"!==n.assignedTo.type?void 0:F.contactId,status_id:M(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(F.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){F.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){F.leaveRequestStatuses=e.concat(F.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function E(){return F.filteredUsers.length>0&&F.filters.leaveRequest.contact_id?F.filters.leaveRequest.contact_id:{IN:F.filteredUsers.map(function(e){return e.id})}}function L(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function M(e){var t=F.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=L(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(F.filters.leaveRequest.leaveStatus=H),(e<=F.totalNoOfPages()||0===F.totalNoOfPages())&&(F.pagination.page=e,w(n))}function j(e){F.filters.leaveRequest.leaveStatus=e,F.refresh(1,!1,"table")}function B(e){F.filters.leaveRequest.assignedTo=e,F.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){F.refresh()}),f.subscribe("LeaveRequest::new",function(){F.refresh()}),f.subscribe("LeaveRequest::edit",function(){F.refresh()}),f.subscribe("LeaveRequest::delete",function(){F.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){F.refresh()})}function U(){return Math.ceil(F.leaveRequests.table.total/F.pagination.size)}t.debug("Component: manage-leave-requests");var F=this,H={name:"all",label:"All"};F.absencePeriods=[],F.absenceTypes=[],F.filteredUsers=[],F.isFilterExpanded=!1,F.isAdmin=!1,F.leaveRequests={table:{list:[]},filter:{list:[]}},F.leaveRequestStatuses=[H],F.loading={content:!0,page:!0,table:!0},F.pagination={page:1,size:7},F.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],F.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:F.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:F.filtersByAssignee[0]}},F.clearStaffSelection=m,F.countLeaveRequestByStatus=h,F.getAbsenceTypeByID=v,F.getArrayOfSize=g,F.getLeaveStatusByValue=b,F.getNavBadge=y,F.getUserNameByID=q,F.labelPeriod=$,F.openLeavePopup=x,F.refresh=k,F.refreshWithFilter=j,F.refreshWithFilterByAssignee=B,F.totalNoOfPages=U,function(){o(i.permissions.admin.administer).then(function(e){F.isAdmin=e,n.all([C(),A(),O(),P(),S(),R(),I()]).then(function(){F.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function l(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function d(){return s.canCalculateChange()}function f(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=s.convertDateToServerFormat(t),v(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return R(n,e),e})):r.reject([])}function p(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function h(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function v(e){return u.all({public_holiday:1,contact_id:s.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function g(){return r.resolve()}function b(){return A(s.uiOptions.fromDate,"from").then(function(){return A(s.uiOptions.toDate,"to")})}function y(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),O(),s.performBalanceChangeCalculation())})}function _(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(h(a.min,n)<=0||h(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function q(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(P)).then(function(){["from","to"].forEach(function(e){_(e),T(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(O)}function $(){["from","to"].forEach(function(e){y(e),C(e)})}function C(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&T(e,!0))})}function A(e,t){return m(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function w(e){return A(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return P(e).then(function(){T(e,!0)})})}function P(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){x[e]=t,f(e,t),n&&"from"===e&&f("to",t)}).catch(function(t){return x[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function D(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function R(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),P("from").then(function(){T("from",!0)})):r.resolve()}function T(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=x[a].number_of_hours?h(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function O(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function I(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?P("from").then(function(){T("from",!0)}):r.resolve()}var x={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=c,s.canCalculateChange=l,s.canSubmit=d,s.initChildController=g,s.initDayTypesExtended=b,s.initTimesExtended=q,s.initWatchersExtended=$,s.onAbsenceTypeUpdateExtended=I,s.onDateChangeExtended=w,s.resetUIInputsExtended=D,s.setDaysSelectionModeExtended=S}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}), -define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s,i){function u(){return!(!i.canCalculateChange()||!i.request.sickness_reason)}function c(){return a.all([f(),h(),m(!0)])}function l(t){var n=i.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function d(t){return!!e.find(i.sicknessDocumentTypes,function(e){return e.value===t})}function f(){return s.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){i.sicknessDocumentTypes=e})}function m(t){return s.valuesOf("hrleaveandabsences_sickness_reason",t).then(function(t){i.sicknessReasons=e.indexBy(t,"name")})}function p(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){m(!1)})}function h(){i.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:i}),i.canSubmit=u,i.initChildController=c,i.isChecked=l,i.isDocumentInRequest=d,i.openSicknessReasonOptionsEditor=p}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=U.from_date!==u.request.from_date||U.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&H.hasExpirationFromAdminSettings,t=H.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&u.isCalculationUnit("hours")&&I(),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),B(),l(),x())})})}function D(){u.isMode("view")||(C(),A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function S(){return l(),x(),B()}function T(){return L(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),F?F=!1:x(),B()}function O(e){u.uiOptions.times[e].time=""}function I(){u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours}function x(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function E(){U=e.cloneDeep(u.request.attributes())}function L(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function M(){u.setRequestDateTimesAndDateTypes(),l(),x(),u.isCalculationUnit("hours")?I():u.request.toil_to_accrue=null}function k(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){R(!1)})}function j(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function B(){return m()?d().catch(a.resolve):a.resolve()}function N(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var U,F=!u.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onAbsenceTypeUpdateExtended=M,u.onDateChangeExtended=S,u.openToilInDaysAccrualOptionsEditor=k,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=T,u.updateExpiryDate=N,function(){E(),L(),j(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function T(){var e=D();return Le.isMode("edit")&&(e=e&&(V()||R())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function O(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function I(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==U())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){me("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=U();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Le.requestStatuses[e]})}function U(){return Le.request?Le.request.request_type:Le.leaveType||null}function F(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Se,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?m.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Te.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=U(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date,"day")&&r.isSameOrBefore(t.end_date,"day")}function oe(e){return xe===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Le.selectedContactId?m.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?m.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Se[e+"_date"]})}function he(e){if(Le.absenceTypes=fe(Pe.types,e),!Le.absenceTypes.length)return r.reject(Ie)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Se=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,O(),w(),Le.request.isValid().then(ee()&&I).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?we():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Te.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?me("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Se={},Te=[],Oe="",Ie="No entitlement",xe="",Ee=[],Le=n.assign(this,f);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=S,Le.canSubmit=T,Le.closeAlert=x,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=F,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=Ae,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){ -return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e){define("leave-absences/manager-leave/modules/config",["common/angular","leave-absences/manager-leave/modules/settings"],function(t){return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/manager-leave/requests"),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","common/services/crm-ang.service","leave-absences/shared/ui-router","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); +!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[f]),c[r[f]]=e[r[f]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,m),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),m.$$values=b,m.$$promises=m.$$promises||!0,delete m.$$inheritedValues,c.resolve(b))}function u(e){m.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),m=c.promise,g=m.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),m;o.$$inheritedValues&&r(b,f(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,f(o.$$values,h)),m.$$inheritedValues=f(o.$$values,h),i()):(o.$$inheritedValues&&(m.$$inheritedValues=f(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(m.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){b[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return m}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(f,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",f=0,m=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),q.length>0)for(f=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,f=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(f=e),f},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(m(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function f(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),m(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:f})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return m(r,t.self);for(var o in T)B(T[o])&&(t[o]=T[o](t,T.$delegates[o]));return P[n]=t,!t[R]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){w.$current.navigable==t&&c(e,n)||w.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=w.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.$current=t,w.current=t.self,w.params=n,V(w.params,m),w.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),w.current)}).then(null,function(a){return a===D?T:w.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(w.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},w.is=function(e,t,a){a=W({relative:w.$current},a||{});var r=f(e,a.relative);return j(r)?w.$current===r&&(!t||c(r.params.$$values(t),m)):n},w.includes=function(e,t,a){if(a=W({relative:w.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=w.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(w.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(f&&(f.remove(),f=null),p&&(p.$destroy(),p=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(s){var d,f=D(n,c,i,r),y=f&&e.$current&&e.$current.locals[f];if(s||y!==h){d=n.$new(),h=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});m=_,p=d,p.$emit("$viewContentLoaded",f),p.$eval(v)}}var f,m,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var f=t.extend({},d);o[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=f),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}m(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function R(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function T(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:T(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=R(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],f=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var m=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&m(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),m(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){f.state=t[0],f.params=t[1],f.options=t[2],f.href=e.href(f.state,f.params,f.options),m&&m(),c&&(m=c.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function L(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,T(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n){function a(e){e.absencePeriods&&c.absencePeriods.length&&(c.filters.period_id=o().id),e.absenceTypes&&c.absenceTypes.length&&(c.filters.type_id=s().id),(e.loggedInContactId||e.userRole)&&(c.filters.managed_by="manager"===c.userRole?c.loggedInContactId:void 0),r()&&c.submitFilters()}function r(){return e.every(c.filters,function(e){return null!==e})}function o(){return e.find(c.absencePeriods,function(e){return e.current})||c.absencePeriods.reduce(function(e,n){return t(e.end_date).isAfter(n.end_date)?e:n})}function s(){return c.absenceTypes.reduce(function(e,t){return e.title.localeCompare(t.title)?e:t})}function i(e){return e.current?"Current Period ("+e.title+")":e.title}function u(){n.$emit("LeaveBalanceFilters::update",c.filters)}var c=this;c.filters={period_id:null,type_id:null,managed_by:null},c.$onChanges=a,c.labelPeriod=i,c.submitFilters=u}n.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,t){return e.extend({all:function(e,n,a,r,o){return t.getLeaveBalances(this.processFilters(e),n,a,r,o)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){return r.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function p(){return o.all().then(o.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function h(){return s.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function v(){return n.all([m(),p(),h(),g(),q()]).catch(function(e){u.error("Error",e)})}function g(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function b(){return P.loading.report=!0,i.all(w,P.pagination,void 0,void 0,!1).then(function(e){P.report=y(e.list),P.reportCount=e.total}).catch(function(e){u.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function y(n){return n.map(function(n){return n=e.copy(n),n.absence_types=t.indexBy(n.absence_types,function(e){return e.id}),n})}function _(){a.$on("LeaveBalanceFilters::update",C),c.subscribe("LeaveRequest::new",$)}function q(){return f(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function $(e){C(e,w)}function C(e,t){w=t,P.pagination.page=1,A(),P.loadReportCurrentPage()}function A(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+w.type_id})}var w={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.loadReportCurrentPage=b,function(){_(),v().then(function(){P.loading.component=!1})}()}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return f(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(m(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function f(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function m(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){E.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(m).then(T)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function T(){E.selectedMonths=[n().month()]}function S(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=D,function(){S().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function s(e){return e.isAM?"AM":e.isPM?"PM":""}function i(e){var n=t(e.from_date).isSame(h.date,"day"),a=t(e.to_date).isSame(h.date,"day");return n?t(e.from_date).format("HH:mm"):a?t(e.to_date).format("HH:mm"):""}function u(t,n){h.contactData.leaveRequestsAttributes[t.id].absenceTypeTitle=e.find(h.supportData.absenceTypes,{id:t.type_id}).title}function c(t,n){var a=e.find(h.supportData.absenceTypes,{id:t.type_id}),r=e.find(h.supportData.calculationUnits,{value:a.calculation_unit});n.unit=r.name}function l(e,t){t.from_date=new Date(e.from_date),t.to_date=new Date(e.to_date)}function d(t,n){"days"===n.unit&&(n.from_date_type=e.find(h.supportData.dayTypes,{value:t.from_date_type}).label,n.to_date_type=e.find(h.supportData.dayTypes,{value:t.to_date_type}).label)}function f(e,t){var n="";n=t.isAccruedTOIL?"AT":"days"===t.unit?s(t):i(e),t.label=n}function m(e){var t=h.contactData.leaveRequestsAttributes[e.id];[c,d,f,l,u].forEach(function(n){n.call(this,e,t)})}function p(){a.$watch("day.contactData.leaveRequests",function(){h.contactData&&h.contactData.leaveRequests&&h.contactData.leaveRequests.forEach(m)},!0)}n.debug("Component: leave-calendar-day");var h=this;h.openLeavePopup=o,function(){p()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),N(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(V.period.start_date)&&r.isSameOrBefore(V.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return H[e]}function m(){return V.showOnlyWithLeaveRequests?V.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):V.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),N(e)}function v(t){var n={request_type:"toil"};return e.some(t,n)&&!e.every(t,n)?e.filter(t,n):t}function g(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){V.supportData.dayTypes=e.indexBy(V.supportData.dayTypes,"name"),V.supportData.leaveRequestStatuses=e.indexBy(V.supportData.leaveRequestStatuses,"value"),V.supportData.publicHolidays=e.transform(V.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]||(W[e.contact_id][t.date]=[]),W[e.contact_id][t.date].push(e)})}),a.resolve()}function _(){U.push(r.$on("LeaveCalendar::showMonths",k)),U.push(i.subscribe("LeaveRequest::new",c)),U.push(i.subscribe("LeaveRequest::edit",B)),U.push(i.subscribe("LeaveRequest::updatedByManager",B)),U.push(i.subscribe("LeaveRequest::delete",h)),U.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var r=V.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!V.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=V.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===V.month.index&&r.year()===V.month.year&&a.push(e.find(V.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){var n=e.find(V.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function D(){return[P(u.statusNames.approved),P(u.statusNames.adminApproved),P(u.statusNames.awaitingApproval),P(u.statusNames.moreInformationRequired)]}function R(){return V.month.loading=!0,a.all([S(),T()]).then(O).then(M).then(function(){F=!0,V.month.loading=!1})}function T(){return s.all({from_date:{to:V.month.days[V.month.days.length-1].date},to_date:{from:V.month.days[0].date},status_id:{IN:D()},contact_id:{IN:V.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(V.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function S(){var t=V.month.days[0].date,n=V.month.days[V.month.days.length-1].date;return o.get(V.contacts.map(function(e){return e.id}),t,n).then(function(t){H=e.indexBy(t,"contact_id")})}function O(){return V.contactIdsToReduceTo&&(V.contacts=V.contacts.filter(function(t){return e.includes(V.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function I(t){var n=w(t);W[t.contact_id]=W[t.contact_id]||{},n.forEach(function(n){e.remove(W[t.contact_id][n.date],function(e){return e.id===t.id})})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),U.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return W[n]&&W[n][t.date]?W[n][t.date]:[]}).then(function(a){e.assign(t.contactsData[n],{leaveRequests:a,leaveRequestsToShowInCell:v(a),leaveRequestsAttributes:L(t,a)})})}function L(e,t){var n={};return t.forEach(function(t){n[t.id]={styles:j(t),isAccruedTOIL:t?$(t,"toil"):null,isRequested:t?A(t):null,isAM:t?q("half_day_am",t,e.date):null,isPM:t?q("half_day_pm",t,e.date):null}}),n}function M(){return a.all(V.month.days.map(function(e){return a.all(V.contacts.map(function(t){return E(e,t.id)}))}))}function k(t,n,a){!e.find(n,function(e){return e.index===V.month.index})?V.visible=!1:(V.currentPage=0,V.visible=!0,(a||!F)&&R())}function j(t){var n=e.find(V.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){h(e),-1!==D().indexOf(e.status_id)&&c(e)}function N(e){return a.all(w(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var F=!1,U=[],H={},W={},V=this;V.currentPage=0,V.pageSize=20,V.visible=!1,V.showContactName=!!V.showContactName,V.showOnlyWithLeaveRequests=!!V.showOnlyWithLeaveRequests,V.$onDestroy=x,V.contactsList=m,V.getContactUrl=g,function(){var e=t().month(V.month.index).year(V.month.year);b(),_(),V.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id, +e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return L()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function T(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function L(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([L(),E()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(T).then(V).then(P).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function f(){return S.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){T[e.label]=t})})).catch(function(){T=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function A(e){return!e.attachment_id||S.canManage}function w(){e.forEach(R,function(e){e()})}function P(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],R=[],T={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=w,S.canRemoveAttachment=A,S.canSubmit=d,S.canUploadMore=f,S.formatDateTime=m,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,r,o,s,i,u,c,l,d,f){"use strict";function m(){U.filters.leaveRequest.contact_id=null,U.refresh()}function p(){var e=U.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?U.leaveRequests.filter.list.length:U.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function v(t){return e.find(U.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function b(t){var n=e.find(U.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function y(e){switch(e){case i.statusNames.approved:return"badge-success";case i.statusNames.rejected:return"badge-danger";case i.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function _(t){return e.find(U.leaveRequestStatuses,function(e){return e.name===t}).value}function q(t){var n=e.find(U.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function $(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return u.all().then(function(t){U.absencePeriods=e.sortBy(t,"start_date"),U.filters.leaveRequest.selectedPeriod=e.find(U.absencePeriods,function(e){return!!e.current})})}function A(){return c.all().then(c.loadCalculationUnits).then(function(e){U.absenceTypes=e})}function w(e){return(U.isAdmin?r.all(p()):r.leaveManagees(U.contactId,p())).then(function(t){return U.filteredUsers=U.isAdmin?t.list:t,e?D(e):n.all([D("table"),D("filter")])}).then(function(){U.filters.leaveRequest.leaveStatus!==H&&0===U.leaveRequests.table.list.length&&U.refresh(1,!0)})}function P(){return s.valuesOf("hrjc_department").then(function(e){U.departments=e})}function D(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:U.pagination,r="filter"===e?{return:["status_id"]}:{};return U.loading[n]=!0,l.all(S(t),a,"from_date DESC",r,!1).then(function(t){U.leaveRequests[e]=t}).catch(function(){U.leaveRequests[e].list=[]}).finally(function(){U.loading[n]=!1})}function R(){return s.valuesOf("hrjc_level_type").then(function(e){U.levelTypes=e})}function T(){return s.valuesOf("hrjc_location").then(function(e){U.locations=e})}function S(t){var n=U.filters.leaveRequest;return{contact_id:E(),managed_by:U.isAdmin&&"me"!==n.assignedTo.type?void 0:U.contactId,status_id:M(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(U.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function O(){return s.valuesOf("hrjc_region").then(function(e){U.regions=e})}function I(){return s.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){U.leaveRequestStatuses=e.concat(U.leaveRequestStatuses)})}function x(e,t,n,a){d.openModal.apply(d,arguments)}function E(){return U.filteredUsers.length>0&&U.filters.leaveRequest.contact_id?U.filters.leaveRequest.contact_id:{IN:U.filteredUsers.map(function(e){return e.id})}}function L(e){var t=[_(i.statusNames.moreInformationRequired),_(i.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function M(e){var t=U.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=L(n)),n.length)return{IN:n}}function k(e,t,n){e="number"==typeof e?e:1,t&&(U.filters.leaveRequest.leaveStatus=H),(e<=U.totalNoOfPages()||0===U.totalNoOfPages())&&(U.pagination.page=e,w(n))}function j(e){U.filters.leaveRequest.leaveStatus=e,U.refresh(1,!1,"table")}function B(e){U.filters.leaveRequest.assignedTo=e,U.refresh()}function N(){f.subscribe("LeaveRequest::updatedByManager",function(){U.refresh()}),f.subscribe("LeaveRequest::new",function(){U.refresh()}),f.subscribe("LeaveRequest::edit",function(){U.refresh()}),f.subscribe("LeaveRequest::delete",function(){U.refresh()}),f.subscribe("LeaveRequest::statusUpdate",function(){U.refresh()})}function F(){return Math.ceil(U.leaveRequests.table.total/U.pagination.size)}t.debug("Component: manage-leave-requests");var U=this,H={name:"all",label:"All"};U.absencePeriods=[],U.absenceTypes=[],U.filteredUsers=[],U.isFilterExpanded=!1,U.isAdmin=!1,U.leaveRequests={table:{list:[]},filter:{list:[]}},U.leaveRequestStatuses=[H],U.loading={content:!0,page:!0,table:!0},U.pagination={page:1,size:7},U.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],U.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:U.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:U.filtersByAssignee[0]}},U.clearStaffSelection=m,U.countLeaveRequestByStatus=h,U.getAbsenceTypeByID=v,U.getArrayOfSize=g,U.getLeaveStatusByValue=b,U.getNavBadge=y,U.getUserNameByID=q,U.labelPeriod=$,U.openLeavePopup=x,U.refresh=k,U.refreshWithFilter=j,U.refreshWithFilterByAssignee=B,U.totalNoOfPages=F,function(){o(i.permissions.admin.administer).then(function(e){U.isAdmin=e,n.all([C(),A(),O(),P(),T(),R(),I()]).then(function(){U.loading.page=!1,w()}),N()})}()}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function l(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function d(){return s.canCalculateChange()}function f(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function m(t,n){return t?(t=s.convertDateToServerFormat(t),v(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return R(n,e),e})):r.reject([])}function p(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function h(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function v(e){return u.all({public_holiday:1,contact_id:s.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function g(){return r.resolve()}function b(){return A(s.uiOptions.fromDate,"from").then(function(){return A(s.uiOptions.toDate,"to")})}function y(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),O(),s.performBalanceChangeCalculation())})}function _(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(h(a.min,n)<=0||h(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function q(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(P)).then(function(){["from","to"].forEach(function(e){_(e),S(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(O)}function $(){["from","to"].forEach(function(e){y(e),C(e)})}function C(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&S(e,!0))})}function A(e,t){return m(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function w(e){return A(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return P(e).then(function(){S(e,!0)})})}function P(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){x[e]=t,f(e,t),n&&"from"===e&&f("to",t)}).catch(function(t){return x[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function D(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function R(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function T(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),P("from").then(function(){S("from",!0)})):r.resolve()}function S(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=x[a].number_of_hours?h(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function O(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function I(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?P("from").then(function(){S("from",!0)}):r.resolve()}var x={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=c,s.canCalculateChange=l,s.canSubmit=d,s.initChildController=g,s.initDayTypesExtended=b,s.initTimesExtended=q,s.initWatchersExtended=$,s.onAbsenceTypeUpdateExtended=I,s.onDateChangeExtended=w,s.resetUIInputsExtended=D,s.setDaysSelectionModeExtended=T}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s,i){function u(){return!(!i.canCalculateChange()||!i.request.sickness_reason)}function c(){return a.all([f(),h(),m(!0)])}function l(t){var n=i.request.getDocumentArray();return!!e.find(n,function(e){return e===t})} +function d(t){return!!e.find(i.sicknessDocumentTypes,function(e){return e.value===t})}function f(){return s.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){i.sicknessDocumentTypes=e})}function m(t){return s.valuesOf("hrleaveandabsences_sickness_reason",t).then(function(t){i.sicknessReasons=e.indexBy(t,"name")})}function p(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){m(!1)})}function h(){i.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:i}),i.canSubmit=u,i.initChildController=c,i.isChecked=l,i.isDocumentInRequest=d,i.openSicknessReasonOptionsEditor=p}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function f(){return!!u.request.toil_to_accrue}function m(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=F.from_date!==u.request.from_date||F.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&H.hasExpirationFromAdminSettings,t=H.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(R)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function A(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&u.isCalculationUnit("hours")&&I(),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function w(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),B(),l(),x())})})}function D(){u.isMode("view")||(C(),A(),P())}function R(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function T(){return l(),x(),B()}function S(){return L(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),U?U=!1:x(),B()}function O(e){u.uiOptions.times[e].time=""}function I(){u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours}function x(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function E(){F=e.cloneDeep(u.request.attributes())}function L(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function M(){u.setRequestDateTimesAndDateTypes(),l(),x(),u.isCalculationUnit("hours")?I():u.request.toil_to_accrue=null}function k(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){R(!1)})}function j(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function B(){return m()?d().catch(a.resolve):a.resolve()}function N(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var F,U=!u.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=f,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=w,u.initWatchersExtended=D,u.onAbsenceTypeUpdateExtended=M,u.onDateChangeExtended=T,u.openToilInDaysAccrualOptionsEditor=k,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=N,function(){E(),L(),j(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function f(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function m(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,m(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,m(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),f.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,f,m,p,h,v,g,b,y,_,q,$,C){function A(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function w(){["from","to"].forEach(A)}function P(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Te.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=D();return Le.isMode("edit")&&(e=e&&(V()||R())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function O(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function I(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==F())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){me("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Le.requestStatuses[e]})}function F(){return Le.request?Le.request.request_type:Le.leaveType||null}function U(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Te,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?m.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Re++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=F(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date,"day")&&r.isSameOrBefore(t.end_date,"day")}function oe(e){return xe===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Le.selectedContactId?m.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?m.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):m.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function fe(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function me(e){P(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Te[e+"_date"]})}function he(e){if(Le.absenceTypes=fe(Pe.types,e),!Le.absenceTypes.length)return r.reject(Ie)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Te=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,O(),w(),Le.request.isValid().then(ee()&&I).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?we():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Re&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Re>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function Ae(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function we(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?me("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&me("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Re=0,Te={},Se=[],Oe="",Ie="No entitlement",xe="",Ee=[],Le=n.assign(this,f);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=T,Le.canSubmit=S,Le.closeAlert=x,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=U,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=Ae,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}), +define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e){define("leave-absences/manager-leave/modules/config",["common/angular","leave-absences/manager-leave/modules/settings"],function(t){return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/manager-leave/requests"),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","common/services/crm-ang.service","leave-absences/shared/ui-router","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/manager-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js index 461c5e472f6..a774369268e 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.min.js @@ -6,9 +6,9 @@ */ -!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[m]),c[r[m]]=e[r[m]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&f(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,f),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),f.$$values=b,f.$$promises=f.$$promises||!0,delete f.$$inheritedValues,c.resolve(b))}function u(e){f.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),f=c.promise,g=f.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),f;o.$$inheritedValues&&r(b,m(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,m(o.$$values,h)),f.$$inheritedValues=m(o.$$values,h),i()):(o.$$inheritedValues&&(f.$$inheritedValues=m(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(f.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),m=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(m++,g[e].then(function(t){b[e]=t,--m||l()},c))}),m||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return f}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(m,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",m=0,f=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),f.push(g.segment),m=c.lastIndex;y=e.substring(m);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,m+_),q.length>0)for(m=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),m=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",f.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=f[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:m}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,m=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(m=e),m},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(f(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function m(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),f(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:m})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(D.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!D[r])return f(r,t.self);for(var o in R)B(R[o])&&(t[o]=R[o](t,R.$delegates[o]));return D[n]=t,!t[T]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){A.$current.navigable==t&&c(e,n)||A.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=A.$current.name.split("."),a=0,r=t.length;a=D;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=D;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.$current=t,A.current=t.self,A.params=n,V(A.params,f),A.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),A.current)}).then(null,function(a){return a===P?R:A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),R):(A.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},A.is=function(e,t,a){a=W({relative:A.$current},a||{});var r=m(e,a.relative);return j(r)?A.$current===r&&(!t||c(r.params.$$values(t),f)):n},A.includes=function(e,t,a){if(a=W({relative:A.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=A.$current.name}var r=m(e,a.relative);if(!j(r))return n;if(!j(A.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(m&&(m.remove(),m=null),p&&(p.$destroy(),p=null),f){var e=f.data("$uiViewAnim");b.leave(f,function(){e.$$animLeave.resolve(),m=null}),m=f,f=null}}function d(s){var d,m=P(n,c,i,r),y=m&&e.$current&&e.$current.locals[m];if(s||y!==h){d=n.$new(),h=e.$current.locals[m],d.$emit("$viewContentLoading",m);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});f=_,p=d,p.$emit("$viewContentLoaded",m),p.$eval(v)}}var m,f,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function D(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=P(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var m=t.extend({},d);o[d.$$resolveAs]=m;var f=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=m),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}f(o)}}}}}function P(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function T(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function R(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function S(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:R(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=T(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=S(r),d=s[1]||s[0],m=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var f=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),m&&m(),d&&(m=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&f(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),f(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){m.state=t[0],m.params=t[1],m.options=t[2],m.href=e.href(m.state,m.params,m.options),f&&f(),c&&(f=c.$$addStateInfo(m.state,m.params)),m.href&&r.$set(u.attr,m.href)}var i,u=S(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",m={state:null,params:null,options:null,href:null},f=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return m}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function L(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,R(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function m(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,m){function f(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(D(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||T()})}function h(e){E.injectMonths=!0,O("injected").then(function(){T(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(f).then(R)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function w(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function D(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function P(e){ -e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(A).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function T(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function R(){E.selectedMonths=[n().month()]}function S(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([m(i.permissions.admin.administer),m(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=P,function(){S().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),w()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function m(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?f():p()}function f(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),m(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function m(e){return U[e]}function f(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",M)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function w(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function D(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function P(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function T(){return[P(u.statusNames.approved),P(u.statusNames.adminApproved),P(u.statusNames.awaitingApproval),P(u.statusNames.moreInformationRequired)]}function R(){return W.month.loading=!0,a.all([O(),S()]).then(g).then(L).then(function(){N=!0}).then(function(){W.month.loading=!1})}function S(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:T()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function O(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function I(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=m(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?k(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?w(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function L(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return E(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&R())}function k(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=D(e);t&&(h(t),-1!==T().indexOf(e.status_id)&&c(e))}function B(e){return a.all(A(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=x,W.contactsList=f,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return L()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(A).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function w(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(A)}function A(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function D(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():w()}function P(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function T(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function R(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function S(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function L(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(A).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,f(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=A,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),T(),te.initChildController().then(function(){return s.all([L(),E()])}).then(!te.isMode("create")&&P).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(R).then(V).then(D).then(S).then(!te.isMode("view")&&te.initWatchersExtended).catch(A).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return S.fileUploader&&S.fileUploader.queue.length>0}function m(){return S.getFilesAmount()0?P.map(function(e){return e.label}).join(", "):""}function q(){return S.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(P.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){R[e.label]=t})})).catch(function(){R=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){P=e})}function w(e){return!e.attachment_id||S.canManage}function A(){e.forEach(T,function(e){e()})}function D(e,t){S.fileUploader.queue&&S.fileUploader.queue.length>0?S.fileUploader.uploadAll({entityID:S.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var P=[],T=[],R={},S=Object.create(this);return S.filesLoaded=!1,S.fileUploader=null,S.today=Date.now(),S.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",S.userDateFormat=s.DATE_FORMAT,S.$onDestroy=A,S.canRemoveAttachment=w,S.canSubmit=d,S.canUploadMore=m,S.formatDateTime=f,S.getAuthorName=p,S.getFilesAmount=h,S.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",S),b(),a.all([C(),q()]).then(y).finally(function(){S.filesLoaded=!0})}(),S}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,r,o,s,i,u,c,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){k(e),H.sections.other.open&&f(e,H.sections.other)}function h(){Object.values(H.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):H.refresh()}function g(t){t.dataIndex=e.indexBy(t.data,"id")}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function y(){return o.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.selectedPeriod=e.find(H.absencePeriods,function(e){return!0===e.current})})}function _(){return s.all().then(s.loadCalculationUnits).then(function(t){H.absenceTypes=t,H.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return P("approved",{status_id:F(m.statusNames.approved)})}function $(){return n.all([u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,null,!0),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.approved)]),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){H.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function C(){return i.all({contact_id:H.contactId,period_id:H.selectedPeriod.id},!0).then(function(e){H.entitlements=e}).then(function(){H.absenceTypesFiltered=H.absenceTypes.filter(function(t){var n=e.find(H.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function w(){return i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id},H.entitlements).then(function(){return E(H.entitlements)}).then(function(e){H.sections.entitlements.data=e})}function A(){return n.all([i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id,expired:!0}),D({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:E(e[0]),expiredTOILS:L(e[1].list)})}).then(function(t){ -H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function D(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})}},t),null,"from_date ASC",null,!1)}function P(e,t){return D(t).then(function(t){H.sections[e].data=t.list})}function T(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(I))}function R(){return P("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function S(){return P("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function O(){return P("holidays",{public_holiday:!0})}function I(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function x(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function E(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function L(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){k(e)})}function k(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([C(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([T(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&I(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:k,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([x(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([C(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function l(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function d(){return s.canCalculateChange()}function m(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),v(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return T(n,e),e})):r.reject([])}function p(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function h(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function v(e){return u.all({public_holiday:1,contact_id:s.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function g(){return r.resolve()}function b(){return w(s.uiOptions.fromDate,"from").then(function(){return w(s.uiOptions.toDate,"to")})}function y(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),O(),s.performBalanceChangeCalculation())})}function _(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(h(a.min,n)<=0||h(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function q(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(D)).then(function(){["from","to"].forEach(function(e){_(e),S(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(O)}function $(){["from","to"].forEach(function(e){y(e),C(e)})}function C(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&S(e,!0))})}function w(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function A(e){return w(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return D(e).then(function(){S(e,!0)})})}function D(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){x[e]=t,m(e,t),n&&"from"===e&&m("to",t)}).catch(function(t){return x[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function P(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function T(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function R(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),D("from").then(function(){S("from",!0)})):r.resolve()}function S(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=x[a].number_of_hours?h(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function O(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function I(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?D("from").then(function(){S("from",!0)}):r.resolve()}var x={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=c,s.canCalculateChange=l,s.canSubmit=d,s.initChildController=g,s.initDayTypesExtended=b,s.initTimesExtended=q,s.initWatchersExtended=$,s.onAbsenceTypeUpdateExtended=I,s.onDateChangeExtended=A,s.resetUIInputsExtended=P,s.setDaysSelectionModeExtended=R}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s,i){function u(){return!(!i.canCalculateChange()||!i.request.sickness_reason)}function c(){return a.all([m(),h(),f(!0)])}function l(t){var n=i.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function d(t){return!!e.find(i.sicknessDocumentTypes,function(e){return e.value===t})}function m(){return s.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){i.sicknessDocumentTypes=e})}function f(t){return s.valuesOf("hrleaveandabsences_sickness_reason",t).then(function(t){i.sicknessReasons=e.indexBy(t,"name")})}function p(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}function h(){i.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:i}),i.canSubmit=u,i.initChildController=c,i.isChecked=l,i.isDocumentInRequest=d,i.openSicknessReasonOptionsEditor=p}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function m(){return!!u.request.toil_to_accrue}function f(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=F.from_date!==u.request.from_date||F.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&H.hasExpirationFromAdminSettings,t=H.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(T)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function w(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&u.isCalculationUnit("hours")&&I(),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function A(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function D(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),B(),l(),x())})})}function P(){u.isMode("view")||(C(),w(),D())}function T(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function R(){return l(),x(),B()}function S(){return L(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),U?U=!1:x(),B()}function O(e){u.uiOptions.times[e].time=""}function I(){u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours}function x(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function E(){F=e.cloneDeep(u.request.attributes())}function L(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function M(){u.setRequestDateTimesAndDateTypes(),l(),x(),u.isCalculationUnit("hours")?I():u.request.toil_to_accrue=null}function k(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){T(!1)})}function j(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function B(){return f()?d().catch(a.resolve):a.resolve()}function N(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var F,U=!u.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=m,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=A,u.initWatchersExtended=P,u.onAbsenceTypeUpdateExtended=M,u.onDateChangeExtended=R,u.openToilInDaysAccrualOptionsEditor=k,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=S,u.updateExpiryDate=N,function(){E(),L(),j(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,m,f,p,h,v,g,b,y,_,q,$,C){function w(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function A(){["from","to"].forEach(w)}function D(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Re.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function R(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function S(){var e=P();return Le.isMode("edit")&&(e=e&&(V()||T())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function O(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function I(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==F())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){fe("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(Pe[e],function(e){return Le.requestStatuses[e]})}function F(){return Le.request?Le.request.request_type:Le.leaveType||null}function U(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Re,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Pe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Pe.awaiting_approval=e,Pe.more_information_required=e,Pe.rejected=e,Pe.approved=e,Pe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?f.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Se.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Te++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=F(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date,"day")&&r.isSameOrBefore(t.end_date,"day")}function oe(e){return xe===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){De={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:De.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Le.selectedContactId?f.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?f.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):f.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){D(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Re[e+"_date"]})}function he(e){if(Le.absenceTypes=me(De.types,e),!Le.absenceTypes.length)return r.reject(Ie)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Re=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,O(),A(),Le.request.isValid().then(ee()&&I).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?Ae():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Te&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Te>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Se.forEach(function(e){e()})}function we(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?fe("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var De,Pe={},Te=0,Re={},Se=[],Oe="",Ie="No entitlement",xe="",Ee=[],Le=n.assign(this,m);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=R,Le.canSubmit=S,Le.closeAlert=x,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=U,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=we,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM), +!function(e){define("leave-absences/shared/config",[],function(){var t=CRM.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences/shared";e.config({paths:{"leave-absences/shared/ui-router":"leave-absences/shared/vendor/angular-ui-router.min",mocks:"../test/mocks"},shim:{"leave-absences/shared/ui-router":{}}}),e.config({paths:{"leave-absences/shared/ui-router":t+"/vendor/angular-ui-router.min",mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/angular/test/mocks"}})})}(require),function(e){define("leave-absences/shared/ui-router",[],function(){return function(){"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ui.router"),function(e,t,n){"use strict";function a(e,t){return W(new(W(function(){},{prototype:e})),t)}function r(e){return H(arguments,function(t){t!==e&&H(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function o(e,t){var n=[];for(var a in e.path){if(e.path[a]!==t.path[a])break;n.push(e.path[a])}return n}function s(e){if(Object.keys)return Object.keys(e);var t=[];return H(e,function(e,n){t.push(n)}),t}function i(e,t){if(Array.prototype.indexOf)return e.indexOf(t,Number(arguments[2])||0);var n=e.length>>>0,a=Number(arguments[2])||0;for((a=a<0?Math.ceil(a):Math.floor(a))<0&&(a+=n);a=0||(l.push(r[m]),c[r[m]]=e[r[m]]);return W({},c,t)}function c(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(b[n]=a,N(e))v.push(n,[function(){return t.get(e)}],c);else{var r=t.annotate(e);H(r,function(e){e!==n&&u.hasOwnProperty(e)&&f(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=o}}function p(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var h=s(u||{}),v=[],g=[],b={};return H(u,f),u=g=b=null,function(a,o,s){function i(){--y||(_||r(b,o.$$values),f.$$values=b,f.$$promises=f.$$promises||!0,delete f.$$inheritedValues,c.resolve(b))}function u(e){f.$$failure=e,c.reject(e)}if(p(a)&&s===n&&(s=o,o=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=l;if(o){if(!p(o))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else o=d;var c=e.defer(),f=c.promise,g=f.$$promises={},b=W({},a),y=1+v.length/3,_=!1;if(j(o.$$failure))return u(o.$$failure),f;o.$$inheritedValues&&r(b,m(o.$$inheritedValues,h)),W(g,o.$$promises),o.$$values?(_=r(b,m(o.$$values,h)),f.$$inheritedValues=m(o.$$values,h),i()):(o.$$inheritedValues&&(f.$$inheritedValues=m(o.$$inheritedValues,h)),o.then(i,u));for(var q=0,$=v.length;q<$;q+=3)a.hasOwnProperty(v[q])?i():function(n,r,o){function c(e){d.reject(e),u(e)}function l(){if(!j(f.$$failure))try{d.resolve(t.invoke(r,s,b)),d.promise.then(function(e){b[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),m=0;H(o,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(m++,g[e].then(function(t){b[e]=t,--m||l()},c))}),m||l(),g[n]=d.promise}(v[q],v[q+1],v[q+2]);return f}},this.resolve=function(e,t,n,a){return this.study(e)(t,n,a)}}function g(e,t,n){this.fromConfig=function(e,t,n){return j(e.template)?this.fromString(e.template,t):j(e.templateUrl)?this.fromUrl(e.templateUrl,t):j(e.templateProvider)?this.fromProvider(e.templateProvider,t,n):null},this.fromString=function(e,t){return B(e)?e(t):e},this.fromUrl=function(n,a){return B(n)&&(n=n(a)),null==n?null:e.get(n,{cache:t,headers:{Accept:"text/html"}}).then(function(e){return e.data})},this.fromProvider=function(e,t,a){return n.invoke(e,null,a||{params:t})}}function b(e,t,r){function o(t,n,a,r){if(v.push(t),p[t])return p[t];if(!/^\w+([-.]+\w+)*(?:\[\])?$/.test(t))throw new Error("Invalid parameter name '"+t+"' in pattern '"+e+"'");if(h[t])throw new Error("Duplicate parameter name '"+t+"' in pattern '"+e+"'");return h[t]=new Y.Param(t,n,a,r),h[t]}function s(e,t,n,a){var r=["",""],o=e.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&");if(!t)return o;switch(n){case!1:r=["(",")"+(a?"?":"")];break;case!0:o=o.replace(/\/$/,""),r=["(?:/(",")|/)?"];break;default:r=["("+n+"|",")?"]}return o+r[0]+t+r[1]}function i(r,o){var s,i,u,c,l;return s=r[2]||r[3],l=t.params[s],u=e.substring(m,r.index),i=o?r[4]:r[4]||("*"==r[1]?".*":null),i&&(c=Y.type(i)||a(Y.type("string"),{pattern:new RegExp(i,t.caseInsensitive?"i":n)})),{id:s,regexp:i,segment:u,type:c,cfg:l}}t=W({params:{}},F(t)?t:{});var u,c=/([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,l=/([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,d="^",m=0,f=this.segments=[],p=r?r.params:{},h=this.params=r?r.params.$$new():new Y.ParamSet,v=[];this.source=e;for(var g,b,y;(u=c.exec(e))&&(g=i(u,!1),!(g.segment.indexOf("?")>=0));)b=o(g.id,g.type,g.cfg,"path"),d+=s(g.segment,b.type.pattern.source,b.squash,b.isOptional),f.push(g.segment),m=c.lastIndex;y=e.substring(m);var _=y.indexOf("?");if(_>=0){var q=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,m+_),q.length>0)for(m=0;u=l.exec(q);)g=i(u,!0),b=o(g.id,g.type,g.cfg,"search"),m=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=s(y)+(!1===t.strict?"/?":"")+"$",f.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=f[0],this.$$paramNames=v}function y(e){W(this,e)}function _(){function e(e){return null!=e?e.toString().replace(/(~|\/)/g,function(e){return{"~":"~~","/":"~2F"}[e]}):e}function r(e){return null!=e?e.toString().replace(/(~~|~2F)/g,function(e){return{"~~":"~","~2F":"/"}[e]}):e}function o(){return{strict:h,caseInsensitive:m}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function c(){for(;$.length;){var e=$.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(g[e.name],d.invoke(e.def))}}function l(e){W(this,e||{})}Y=this;var d,m=!1,h=!0,v=!1,g={},q=!0,$=[],C={string:{encode:e,decode:r,is:function(e){return null==e||!j(e)||"string"==typeof e},pattern:/[^\/]*/},int:{encode:e,decode:function(e){return parseInt(e,10)},is:function(e){return j(e)&&this.decode(e.toString())===e},pattern:/\d+/},bool:{encode:function(e){return e?1:0},decode:function(e){return 0!==parseInt(e,10)},is:function(e){return!0===e||!1===e},pattern:/0|1/},date:{encode:function(e){return this.is(e)?[e.getFullYear(),("0"+(e.getMonth()+1)).slice(-2),("0"+e.getDate()).slice(-2)].join("-"):n},decode:function(e){if(this.is(e))return e;var t=this.capture.exec(e);return t?new Date(t[1],t[2]-1,t[3]):n},is:function(e){return e instanceof Date&&!isNaN(e.valueOf())},equals:function(e,t){return this.is(e)&&this.is(t)&&e.toISOString()===t.toISOString()},pattern:/[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,capture:/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/},json:{encode:t.toJson,decode:t.fromJson,is:t.isObject,equals:t.equals,pattern:/[^\/]*/},any:{encode:t.identity,decode:t.identity,equals:t.equals,pattern:/.*/}};_.$$getDefaultValue=function(e){if(!u(e.value))return e.value;if(!d)throw new Error("Injectable functions cannot be called at configuration time");return d.invoke(e.value)},this.caseInsensitive=function(e){return j(e)&&(m=e),m},this.strictMode=function(e){return j(e)&&(h=e),h},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(!0!==e&&!1!==e&&!N(e))throw new Error("Invalid squash policy: "+e+". Valid policies: false, true, arbitrary-string");return v=e,e},this.compile=function(e,t){return new b(e,W(o(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return H(b.prototype,function(n,a){B(n)&&(t=t&&j(e[a])&&B(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return g[e];if(g.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return g[e]=new y(W({name:e},t)),n&&($.push({name:e,def:n}),q||c()),this},H(C,function(e,t){g[t]=new y(W({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,q=!1,c(),H(C,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,o){function c(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!h.type.is(e))throw new Error("Default value ("+e+") for parameter '"+h.id+"' is not an instance of Type ("+h.type.name+")");return e}function l(e){function t(e){return function(t){return t.from===e}}return e=function(e){var n=p(f(h.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}(e),j(e)?h.type.$normalize(e):c()}function m(){return"{Param:"+e+" "+a+" squash: '"+q+"' optional: "+_+"}"}var h=this;r=function(e){var t=F(e)?s(e):[];return-1===i(t,"value")&&-1===i(t,"type")&&-1===i(t,"squash")&&-1===i(t,"array")&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}(r),a=function(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a||(n.type?t.isString(n.type)?g[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?g.any:g.string)}(r,a,o);var b=function(){var t={array:"search"===o&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return W(t,n,r).array}();a=b?a.$asArray(b,"search"===o):a,"string"!==a.name||b||"path"!==o||r.value!==n||(r.value="");var _=r.value!==n,q=function(e,t){var n=e.squash;if(!t||!1===n)return!1;if(!j(n)||null==n)return v;if(!0===n||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}(r,_),$=function(e,t,a,r){var o,s,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return o=U(e.replace)?e.replace:[],N(r)&&o.push({from:r,to:n}),s=p(o,function(e){return e.from}),f(u,function(e){return-1===i(s,e.from)}).concat(o)}(r,b,_,q);W(this,{id:e,type:a,location:o,array:b,squash:q,replace:$,isOptional:_,value:l,dynamic:n,config:r,toString:m})},l.prototype={$$new:function(){return a(this,W(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=s(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(s(t),function(t){-1===i(e,t)&&-1===i(a,t)&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return H(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return H(a.$$keys(),function(r){var o=e&&e[r],s=t&&t[r];a[r].type.equals(o,s)||(n=!1)}),n},$$validates:function(e){var a,r,o,s,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(P.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=-1!==n.indexOf(".")?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!P[r])return f(r,t.self);for(var o in S)B(S[o])&&(t[o]=S[o](t,S.$delegates[o]));return P[n]=t,!t[T]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){A.$current.navigable==t&&c(e,n)||A.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function b(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=A.$current.name.split("."),a=0,r=t.length;a=P;a--)s=p[a],s.self.onExit&&i.invoke(s.self.onExit,s.self,s.locals.globals),s.locals=null;for(a=P;a<_.length;a++)r=_[a],r.locals=E[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(A.$current=t,A.current=t.self,A.params=n,V(A.params,f),A.transition=null,o.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===o.location}),o.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),A.current)}).then(null,function(a){return a===D?S:A.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),S):(A.transition=null,s=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),s.defaultPrevented||v.update(),r.reject(a))});return B},A.is=function(e,t,a){a=W({relative:A.$current},a||{});var r=m(e,a.relative);return j(r)?A.$current===r&&(!t||c(r.params.$$values(t),f)):n},A.includes=function(e,t,a){if(a=W({relative:A.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=A.$current.name}var r=m(e,a.relative);if(!j(r))return n;if(!j(A.$current.includes[r.name]))return!1;if(!t)return!0;for(var o=s(t),i=0;i2?c.enter(e,null,n).then(a):c.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?c.leave(e).then(n):c.leave(e,n)}};if(u){var a=u&&u(n,e);return{enter:function(e,t,n){a.enter(e,null,t),n()},leave:function(e,t){a.leave(e),t()}}}return function(){return{enter:function(e,t,n){t.after(e),n()},leave:function(e,t){e.remove(),t()}}}()}var i=function(){return n.has?function(e){return n.has(e)?n.get(e):null}:function(e){try{return n.get(e)}catch(e){return null}}}(),u=i("$animator"),c=i("$animate");return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,c){function l(){if(m&&(m.remove(),m=null),p&&(p.$destroy(),p=null),f){var e=f.data("$uiViewAnim");b.leave(f,function(){e.$$animLeave.resolve(),m=null}),m=f,f=null}}function d(s){var d,m=D(n,c,i,r),y=m&&e.$current&&e.$current.locals[m];if(s||y!==h){d=n.$new(),h=e.$current.locals[m],d.$emit("$viewContentLoading",m);var _=u(d,function(e){var r=o.defer(),s=o.defer(),u={$animEnter:r.promise,$animLeave:s.promise,$$animLeave:s};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),p&&p.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),l()});f=_,p=d,p.$emit("$viewContentLoaded",m),p.$eval(v)}}var m,f,p,h,v=c.onload||"",g=c.autoscroll,b=s(c,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}}}function P(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(o){var s=o.html();return function(o,i,u){var c=a.$current,l=D(o,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:s);var m=t.extend({},d);o[d.$$resolveAs]=m;var f=e(i.contents());if(d.$$controller){d.$scope=o,d.$element=i;var p=n(d.$$controller,d);d.$$controllerAs&&(o[d.$$controllerAs]=p,o[d.$$controllerAs][d.$$resolveAs]=m),B(p.$onInit)&&p.$onInit(),i.data("$ngControllerController",p),i.children().data("$ngControllerController",p)}f(o)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),o=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(o?o.state.name:"")}function T(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),!(n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/))||4!==n.length)throw new Error("Invalid state ref '"+e+"'");return{state:n[1],paramExpr:n[3]||null}}function S(e){var t=e.parent().inheritedData("$uiView");if(t&&t.state&&t.state.name)return t.state}function R(e){var t="[object SVGAnimatedString]"===Object.prototype.toString.call(e.prop("href")),n="FORM"===e[0].nodeName;return{attr:n?"action":t?"xlink:href":"href",isAnchor:"A"===e.prop("tagName").toUpperCase(),clickable:!n}}function O(e,t,n,a,r){return function(o){var s=o.which||o.button,i=r();if(!(s>1||o.ctrlKey||o.metaKey||o.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});o.preventDefault();var c=a.isAnchor&&!i.href?1:0;o.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:S(e)||t.$current,inherit:!0}}function x(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,o,s){var i,u=T(o.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=R(r),d=s[1]||s[0],m=null;c.options=W(I(r,e),o.uiSrefOpts?a.$eval(o.uiSrefOpts):{});var f=function(n){n&&(c.params=t.copy(n)),c.href=e.href(u.state,c.params,c.options),m&&m(),d&&(m=d.$$addStateInfo(u.state,c.params)),null!==c.href&&o.$set(l.attr,c.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==c.params&&f(e)},!0),c.params=t.copy(a.$eval(u.paramExpr))),f(),l.clickable&&(i=O(r,e,n,l,function(){return c}),r[r.on?"on":"bind"]("click",i),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",i)}))}}}function E(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,o){function s(t){m.state=t[0],m.params=t[1],m.options=t[2],m.href=e.href(m.state,m.params,m.options),f&&f(),c&&(f=c.$$addStateInfo(m.state,m.params)),m.href&&r.$set(u.attr,m.href)}var i,u=R(a),c=o[1]||o[0],l=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+l.map(function(e){return e||"null"}).join(", ")+"]",m={state:null,params:null,options:null,href:null},f=null;n.$watch(d,s,!0),s(n.$eval(d)),u.clickable&&(i=O(a,e,t,u,function(){return m}),a[a.on?"on":"bind"]("click",i),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",i)}))}}}function L(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,o){function s(t,n,r){var o=e.get(t,S(a)),s=i(t,n),u={state:o||{name:t},params:n,hash:s};return h.push(u),v[s]=r,function(){var e=h.indexOf(u);-1!==e&&h.splice(e,1)}}function i(e,n){if(!N(e))throw new Error("state should be a string");return F(n)?e+G(n):(n=t.$eval(n),F(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=s(e,t,p);return u(),n}},t.$on("$stateChangeSuccess",u),u()}]}}function M(e){var t=function(t,n){return e.is(t,n)};return t.$stateful=!0,t}function k(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,B=t.isFunction,N=t.isString,F=t.isObject,U=t.isArray,H=t.forEach,W=t.extend,V=t.copy,G=t.toJson;t.module("ui.router.util",["ng"]),t.module("ui.router.router",["ui.router.util"]),t.module("ui.router.state",["ui.router.router","ui.router.util"]),t.module("ui.router",["ui.router.state"]),t.module("ui.router.compat",["ui.router"]),v.$inject=["$q","$injector"],t.module("ui.router.util").service("$resolve",v),g.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",g);var Y;b.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,W(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){var n=this.regexp.exec(e);if(!n)return null;t=t||{};var a,r,o,s=this.parameters(),i=s.length,u=this.segments.length-1,c={};if(u!==n.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var l,d;for(a=0;a=":e}};return a.all(n).then(function(e){return e&&e.length?r.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,r){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,s){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),s=e.assign({},s,{absence_type_id:a,date:t(o).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",s).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,r,o,s){return t.debug("AbsenceType"),a.extend({all:function(e){return o.all(e).then(function(e){return e.map(function(e){return s.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return o.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return o.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return r.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function r(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(r),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,r,o){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,r,"getLeaveBalances",o)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,r,o){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return r.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return r.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),o.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,r,o,s){e.debug("LeaveRequestAPI.all");var i=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?i.resolve({list:[],total:0,allIds:[]}):i.resolve(this.getAll("LeaveRequest",t,n,r,o,"getFull",s)),i.promise},balanceChangeByAbsenceType:function(t,n,r,o){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var s=a.defer();t&&n||s.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){s.resolve(e.values)}),s.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t}).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var r=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?r.reject(t(e.values).map().flatten().value()):r.resolve(e.values)}),r.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){e.debug("LeaveRequestAPI.update",t);var n=a.defer();return t.id||n.reject("id is mandatory field"),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,r,o,s,i,u){function c(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return u.all({id:this.type_id}).then(u.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return r.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function h(t){var a=e.cloneDeep(t),r=a.breakdown.length>1,o=e.first(e.values(a.breakdown)),s=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(o.date),r&&this.getWorkDayForDate(s.date)]).then(function(t){return o.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,r&&(s.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function v(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),n.all(t)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),i.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?h.call(this,e):e}.bind(this))},cancel:function(){return c.call(this,o.statusNames.cancelled)},approve:function(){return c.call(this,o.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return c.call(this,o.statusNames.rejected)},sendBack:function(){return c.call(this,o.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return n.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return i.delete(this.id)},getBalanceChangeBreakdown:function(){return i.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return i.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return d.call(this,o.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,o.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,o.statusNames.cancelled)},isRejected:function(){return d.call(this,o.statusNames.rejected)},isSentBack:function(){return d.call(this,o.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(o.permissions.admin.administer).then(function(t){return t?"admin":i.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?i.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,o,s){return n.all(this.processFilters(e),t,r,o,s).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,r){return n.balanceChangeByAbsenceType(e,t,a,r)},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,r,o){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(o.serverDateFormat),s={date:r};return a.all(s).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(n,a,r,o,s,i){function u(){return d().then(function(n){var a=n.filter(function(e){var n=e.info.details;return t(n.period_start_date).isSameOrBefore(v.selectedPeriod.end_date)&&(t(n.period_end_date).isSameOrAfter(v.selectedPeriod.start_date)||!n.period_end_date)});return e.uniq(a.map(function(e){return e.contact_id}))})}function c(){return{loadContacts:function(){var e=v.filters.userSettings.assignedTo.type;return m(e).then(function(e){v.lookupContacts=e}).then(function(){return"me"!==e?u():a.resolve(null)}).then(function(e){return v.contactIdsToReduceTo=e,l()}).then(function(e){return e})}}}function l(){return r.all(f(),null,"display_name").then(function(e){return e.list})}function d(){return h?a.resolve(h):s.all()}function m(e){return"me"===e?r.leaveManagees(v.contactId):"unassigned"===e?r.leaveManagees(void 0,{unassigned:!0}):r.all().then(function(e){return e.list})}function f(){return{department:v.filters.userSettings.department?v.filters.userSettings.department.value:null,level_type:v.filters.userSettings.level_type?v.filters.userSettings.level_type.value:null,location:v.filters.userSettings.location?v.filters.userSettings.location.value:null,region:v.filters.userSettings.region?v.filters.userSettings.region.value:null,id:{IN:v.filters.userSettings.contact?[v.filters.userSettings.contact.id]:v.lookupContacts.map(function(e){return e.id})}}}function p(e){i.info("",["

    When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.

    ","

    People I approve filter displays only staff members who you approve leave for.

    ","

    People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.

    "].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,m){function f(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||T()})}function h(e){E.injectMonths=!0,O("injected").then(function(){T(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(f).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function w(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){ +e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(A).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function T(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){E.selectedMonths=[n().month()]}function R(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([m(i.permissions.admin.administer),m(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=D,function(){R().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),w()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function s(e){return e.isAM?"AM":e.isPM?"PM":""}function i(e){var n=t(e.from_date).isSame(h.date,"day"),a=t(e.to_date).isSame(h.date,"day");return n?t(e.from_date).format("HH:mm"):a?t(e.to_date).format("HH:mm"):""}function u(t,n){h.contactData.leaveRequestsAttributes[t.id].absenceTypeTitle=e.find(h.supportData.absenceTypes,{id:t.type_id}).title}function c(t,n){var a=e.find(h.supportData.absenceTypes,{id:t.type_id}),r=e.find(h.supportData.calculationUnits,{value:a.calculation_unit});n.unit=r.name}function l(e,t){t.from_date=new Date(e.from_date),t.to_date=new Date(e.to_date)}function d(t,n){"days"===n.unit&&(n.from_date_type=e.find(h.supportData.dayTypes,{value:t.from_date_type}).label,n.to_date_type=e.find(h.supportData.dayTypes,{value:t.to_date_type}).label)}function m(e,t){var n="";n=t.isAccruedTOIL?"AT":"days"===t.unit?s(t):i(e),t.label=n}function f(e){var t=h.contactData.leaveRequestsAttributes[e.id];[c,d,m,l,u].forEach(function(n){n.call(this,e,t)})}function p(){a.$watch("day.contactData.leaveRequests",function(){h.contactData&&h.contactData.leaveRequests&&h.contactData.leaveRequests.forEach(f)},!0)}n.debug("Component: leave-calendar-day");var h=this;h.openLeavePopup=o,function(){p()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),N(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(V.period.start_date)&&r.isSameOrBefore(V.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function m(e){return H[e]}function f(){return V.showOnlyWithLeaveRequests?V.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):V.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){I(e),N(e)}function v(t){var n={request_type:"toil"};return e.some(t,n)&&!e.every(t,n)?e.filter(t,n):t}function g(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){V.supportData.dayTypes=e.indexBy(V.supportData.dayTypes,"name"),V.supportData.leaveRequestStatuses=e.indexBy(V.supportData.leaveRequestStatuses,"value"),V.supportData.publicHolidays=e.transform(V.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]||(W[e.contact_id][t.date]=[]),W[e.contact_id][t.date].push(e)})}),a.resolve()}function _(){U.push(r.$on("LeaveCalendar::showMonths",k)),U.push(i.subscribe("LeaveRequest::new",c)),U.push(i.subscribe("LeaveRequest::edit",B)),U.push(i.subscribe("LeaveRequest::updatedByManager",B)),U.push(i.subscribe("LeaveRequest::delete",h)),U.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var r=V.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!V.supportData.publicHolidays[p(e).valueOf()]}function w(t){var n=V.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===V.month.index&&r.year()===V.month.year&&a.push(e.find(V.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){var n=e.find(V.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function D(){return[P(u.statusNames.approved),P(u.statusNames.adminApproved),P(u.statusNames.awaitingApproval),P(u.statusNames.moreInformationRequired)]}function T(){return V.month.loading=!0,a.all([R(),S()]).then(O).then(M).then(function(){F=!0,V.month.loading=!1})}function S(){return s.all({from_date:{to:V.month.days[V.month.days.length-1].date},to_date:{from:V.month.days[0].date},status_id:{IN:D()},contact_id:{IN:V.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(V.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function R(){var t=V.month.days[0].date,n=V.month.days[V.month.days.length-1].date;return o.get(V.contacts.map(function(e){return e.id}),t,n).then(function(t){H=e.indexBy(t,"contact_id")})}function O(){return V.contactIdsToReduceTo&&(V.contacts=V.contacts.filter(function(t){return e.includes(V.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function I(t){var n=A(t);W[t.contact_id]=W[t.contact_id]||{},n.forEach(function(n){e.remove(W[t.contact_id][n.date],function(e){return e.id===t.id})})}function x(){r.$emit("LeaveCalendar::monthDestroyed"),U.map(function(e){e.remove?e.remove():e()})}function E(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=m(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return W[n]&&W[n][t.date]?W[n][t.date]:[]}).then(function(a){e.assign(t.contactsData[n],{leaveRequests:a,leaveRequestsToShowInCell:v(a),leaveRequestsAttributes:L(t,a)})})}function L(e,t){var n={};return t.forEach(function(t){n[t.id]={styles:j(t),isAccruedTOIL:t?$(t,"toil"):null,isRequested:t?w(t):null,isAM:t?q("half_day_am",t,e.date):null,isPM:t?q("half_day_pm",t,e.date):null}}),n}function M(){return a.all(V.month.days.map(function(e){return a.all(V.contacts.map(function(t){return E(e,t.id)}))}))}function k(t,n,a){!e.find(n,function(e){return e.index===V.month.index})?V.visible=!1:(V.currentPage=0,V.visible=!0,(a||!F)&&T())}function j(t){var n=e.find(V.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){h(e),-1!==D().indexOf(e.status_id)&&c(e)}function N(e){return a.all(A(e).map(function(t){return E(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var F=!1,U=[],H={},W={},V=this;V.currentPage=0,V.pageSize=20,V.visible=!1,V.showContactName=!!V.showContactName,V.showOnlyWithLeaveRequests=!!V.showOnlyWithLeaveRequests,V.$onDestroy=x,V.contactsList=f,V.getContactUrl=g,function(){var e=t().month(V.month.index).year(V.month.year);b(),_(),V.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return L()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(A).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function w(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(A)}function A(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():w()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function T(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){K()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){X(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function S(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function R(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function L(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(A).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,f(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function J(){e.forEach(ee,function(e){e()})}function K(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function X(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=A,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=J,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),T(),te.initChildController().then(function(){return s.all([L(),E()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(S).then(V).then(P).then(R).then(!te.isMode("view")&&te.initWatchersExtended).catch(A).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return R.fileUploader&&R.fileUploader.queue.length>0}function m(){return R.getFilesAmount()0?D.map(function(e){return e.label}).join(", "):""}function q(){return R.request.loadAttachments().then(function(){r.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function $(){return a.all(D.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){S[e.label]=t})})).catch(function(){S=null})}function C(){return u.valuesOf("safe_file_extension").then(function(e){D=e})}function w(e){return!e.attachment_id||R.canManage}function A(){e.forEach(T,function(e){e()})}function P(e,t){R.fileUploader.queue&&R.fileUploader.queue.length>0?R.fileUploader.uploadAll({entityID:R.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var D=[],T=[],S={},R=Object.create(this);return R.filesLoaded=!1,R.fileUploader=null,R.today=Date.now(),R.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",R.userDateFormat=s.DATE_FORMAT,R.$onDestroy=A,R.canRemoveAttachment=w,R.canSubmit=d,R.canUploadMore=m,R.formatDateTime=f,R.getAuthorName=p,R.getFilesAmount=h,R.listFileTypes=_,function(){r.$broadcast("LeaveRequestPopup::childComponent::register"),o.$emit("LeaveRequestPopup::addTab",R),b(),a.all([C(),q()]).then(y).finally(function(){R.filesLoaded=!0})}(),R}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(e,n,a,r){t.openModal.apply(t,arguments)}e.debug("Component: leave-request-record-actions");var r,o=this;o.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],o.openLeavePopup=a,function(){r=n.parse(),r.openModal&&a(null,r.openModal,o.selectedContactId,o.isSelfRecord)}()}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",isSelfRecord:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(t,n,a,r,o,s,i,u,c,l,d,m){function f(e,t){t.data.push(e),t.dataIndex[e.id]=e}function p(e){k(e),H.sections.other.open&&f(e,H.sections.other)}function h(){Object.values(H.sections).forEach(function(e){e.data=[]})}function v(e){var t=U[e.status];t?t(e.leaveRequest):H.refresh()}function g(t){t.dataIndex=e.indexBy(t.data,"id")}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function y(){return o.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.selectedPeriod=e.find(H.absencePeriods,function(e){return!0===e.current})})}function _(){return s.all().then(s.loadCalculationUnits).then(function(t){H.absenceTypes=t,H.absenceTypesIndexed=e.indexBy(t,"id")})}function q(){return D("approved",{status_id:F(m.statusNames.approved)})}function $(){return n.all([u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,null,!0),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.approved)]),u.balanceChangeByAbsenceType(H.contactId,H.selectedPeriod.id,[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)])]).then(function(e){H.absenceTypes.forEach(function(t){t.balanceChanges={holidays:e[0][t.id],approved:e[1][t.id],pending:e[2][t.id]}})})}function C(){return i.all({contact_id:H.contactId,period_id:H.selectedPeriod.id},!0).then(function(e){H.entitlements=e}).then(function(){H.absenceTypesFiltered=H.absenceTypes.filter(function(t){var n=e.find(H.entitlements,function(e){return e.type_id===t.id});return t.entitlement=n?n.value:0,t.remainder=n?n.remainder:{current:0,future:0},!(0===t.entitlement&&"1"!==t.allow_overuse&&"1"!==t.allow_accruals_request)})})}function w(){return i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id},H.entitlements).then(function(){return E(H.entitlements)}).then(function(e){H.sections.entitlements.data=e})}function A(){return n.all([i.breakdown({contact_id:H.contactId,period_id:H.selectedPeriod.id,expired:!0}),P({request_type:"toil",expired:!0})]).then(function(e){return n.all({expiredBalanceChangesFlatten:E(e[0]),expiredTOILS:L(e[1].list)})}).then(function(t){H.sections.expired.data=t.expiredBalanceChangesFlatten.concat(t.expiredTOILS),H.sections.expired.data=e.sortBy(H.sections.expired.data,"expiry_date")})}function P(t){return u.all(e.assign({contact_id:H.contactId,from_date:{from:H.selectedPeriod.start_date},to_date:{to:H.selectedPeriod.end_date},type_id:{IN:H.absenceTypes.map(function(e){return e.id})} +},t),null,"from_date ASC",null,!1)}function D(e,t){return P(t).then(function(t){H.sections[e].data=t.list})}function T(){return n.all(Object.values(H.sections).filter(function(e){return e.open}).map(I))}function S(){return D("other",{status_id:{in:[F(m.statusNames.rejected),F(m.statusNames.cancelled)]}})}function R(){return D("pending",{status_id:{in:[F(m.statusNames.awaitingApproval),F(m.statusNames.moreInformationRequired)]}})}function O(){return D("holidays",{public_holiday:!0})}function I(e){return e.loading=!0,e.loadLeaveRequests().then(g.bind(this,e)).then(function(){e.loading=!1})}function x(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){H.leaveRequestStatuses=e.indexBy(t,"value")})}function E(t){return n.resolve().then(function(){return t.map(function(t){var n=e.find(H.entitlements,function(e){return e.id===t.id});return t.breakdown.map(function(t){return e.assign(e.clone(t),{type_id:n.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function L(e){return n.resolve().then(function(){return e.map(function(e){return{expiry_date:e.toil_expiry_date,type:{label:"Accrued TOIL"}}})})}function M(){l.subscribe("LeaveRequest::new",function(){H.refresh()}),l.subscribe("LeaveRequest::edit",function(){H.refresh()}),l.subscribe("LeaveRequest::statusUpdate",v),l.subscribe("LeaveRequest::delete",function(e){k(e)})}function k(t){e.forEach(H.sections,function(n,a){n.dataIndex[t.id]&&(e.remove(n.data,function(e){return e.id===t.id}),delete n.dataIndex[t.id],j(t,a))})}function j(e,t){var n=H.absenceTypesIndexed[e.type_id],a="pending"===t?"future":"current";n.balanceChanges[t]-=e.balance_change,n.remainder[a]-=e.balance_change}function B(){H.loading.content=!0,n.all([C(),$()]).then(function(){H.loading.content=!1}).then(function(){return n.all([T(),h()])})}function N(e){var t=H.sections[e];t.open=!t.open,t.open&&!t.data.length&&I(t)}function F(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}t.debug("Component: staff-leave-report");var U={delete:k,cancel:p},H=this;H.absencePeriods=[],H.absenceTypes=[],H.absenceTypesFiltered=[],H.absenceTypesIndexed={},H.dateFormat=d.DATE_FORMAT,H.leaveRequestStatuses={},H.selectedPeriod=null,H.role="absence-tab"===a.section?"admin":"staff",H.loading={content:!0,page:!0},H.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:q},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:A},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:R},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S}},H.labelPeriod=b,H.refresh=B,H.toggleSection=N,function(){n.all([x(),_(),y()]).then(function(){H.loading.page=!1}).then(function(){return n.all([C(),$()])}).then(function(){H.loading.content=!1}),M()}()}n.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings",a]})}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return s.request.calculateBalanceChange(s.selectedAbsenceType.calculation_unit_name)}function l(){var e=s.request,t=!!e.from_date&&!!e.to_date,n=s.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function d(){return s.canCalculateChange()}function m(t,n){var a=s.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);s.uiOptions.multipleDays||("from"===t&&o&&r&&(o=s.getMomentDateWithGivenTime(o).subtract(s.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=s.getMomentDateWithGivenTime(r).add(s.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min}function f(t,n){return t?(t=s.convertDateToServerFormat(t),v(t).then(function(n){return n?s.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(t,s.requestDayTypes).then(function(t){return t.length?t:s.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return T(n,e),e})):r.reject([])}function p(e,n){return e=t(e),r.all([s.calendar.isNonWorkingDay(e),s.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function h(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function v(e){return u.all({public_holiday:1,contact_id:s.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function g(){return r.resolve()}function b(){return w(s.uiOptions.fromDate,"from").then(function(){return w(s.uiOptions.toDate,"to")})}function y(e){o.$watch(function(){return s.uiOptions.times[e].amount},function(e,t){s.isCalculationUnit("days")||+e==+t||(s.isRole("staff")&&(s.request.change_balance=!0),O(),s.performBalanceChangeCalculation())})}function _(e){var n=t(s.request[e+"_date"]).format("HH:mm"),a=s.uiOptions.times[e];(h(a.min,n)<=0||h(a.max,n)>=0)&&(n="from"===e?a.min:a.max),s.uiOptions.times[e].time=n}function q(){var e=s.uiOptions.multipleDays?["from","to"]:["from"],t=s.uiOptions.times;if(s.isCalculationUnit("hours"))return r.all(e.map(P)).then(function(){["from","to"].forEach(function(e){_(e),R(e),t[e].amount=Math.min(s.request[e+"_date_amount"],t[e].maxAmount).toString()}),s.uiOptions.multipleDays||s.updateEndTimeInputMinTime(s.uiOptions.times.from.time)}).then(O)}function $(){["from","to"].forEach(function(e){y(e),C(e)})}function C(e){o.$watch(function(){return s.uiOptions.times[e].time},function(t,n){s.isCalculationUnit("days")||t===n||(s.setRequestDateTimesAndDateTypes(),t&&R(e,!0))})}function w(e,t){return f(e,t).then(function(){s.loading[t+"DayTypes"]=!1})}function A(e){return w(s.uiOptions[e+"Date"],e).then(function(){if(s.isCalculationUnit("hours"))return P(e).then(function(){R(e,!0)})})}function P(e){var t=s.uiOptions[e+"Date"],n=!s.uiOptions.multipleDays;return t?s.request.getWorkDayForDate(s.convertDateToServerFormat(t)).then(function(t){x[e]=t,m(e,t),n&&"from"===e&&m("to",t)}).catch(function(t){return x[e]={},s.handleError(t)}).finally(function(){n&&(s.uiOptions.times.to.loading=!1)}):r.resolve()}function D(t){var n=s.uiOptions.times[t];s["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function T(t,n){var a="request"+e.startCase(t)+"DayTypes";s[a]=n,s.isMode("create")&&(s.request[t+"_date_type"]=s[a][0].value)}function S(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?(s.disableAndShowLoadingTimeInput("from"),!s.uiOptions.multipleDays&&s.disableAndShowLoadingTimeInput("to"),P("from").then(function(){R("from",!0)})):r.resolve()}function R(e,t){var n=s.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,i=n.multipleDays&&"from"===a?r.max:n.times.to.time,u=x[a].number_of_hours?h(o,i).toString():"0";r.maxAmount=u,t&&(r.amount=r.maxAmount)}function O(){var e=s.uiOptions.times;s.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,s.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function I(){return s.isCalculationUnit("hours")&&s.uiOptions.fromDate?P("from").then(function(){R("from",!0)}):r.resolve()}var x={};a.debug("RequestModalDetailsLeaveController"),s.calculateBalanceChange=c,s.canCalculateChange=l,s.canSubmit=d,s.initChildController=g,s.initDayTypesExtended=b,s.initTimesExtended=q,s.initWatchersExtended=$,s.onAbsenceTypeUpdateExtended=I,s.onDateChangeExtended=A,s.resetUIInputsExtended=D,s.setDaysSelectionModeExtended=S}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,r,o,s,i){function u(){return!(!i.canCalculateChange()||!i.request.sickness_reason)}function c(){return a.all([m(),h(),f(!0)])}function l(t){var n=i.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function d(t){return!!e.find(i.sicknessDocumentTypes,function(e){return e.value===t})}function m(){return s.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){i.sicknessDocumentTypes=e})}function f(t){return s.valuesOf("hrleaveandabsences_sickness_reason",t).then(function(t){i.sicknessReasons=e.indexBy(t,"name")})}function p(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}function h(){i.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:i}),i.canSubmit=u,i.initChildController=c,i.isChecked=l,i.isDocumentInRequest=d,i.openSicknessReasonOptionsEditor=p}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){return u.balance.change.amount=+u.request.toil_to_accrue,a.resolve(u.balance.change)}function l(){if(!u.request.from_date||!u.request.to_date)return u.uiOptions.max_toil_duration_and_accrual=null,void(u.uiOptions.toil_duration_in_hours=null);u.uiOptions.max_toil_duration_and_accrual=t.duration(t(u.request.to_date).diff(u.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(u.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(u.request.type_id,e)}).then(function(e){return u.request.toil_expiry_date=e,u.uiOptions.expiryDate=new Date(e),e})}function m(){return!!u.request.toil_to_accrue}function f(){var e=u.uiOptions.multipleDays&&!!u.request.to_date,t=!u.uiOptions.multipleDays&&!!u.request.from_date,n=t||e,a=F.from_date!==u.request.from_date||F.to_date!==u.request.to_date;return u.canDisplayToilExpirationField&&n&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(u.request.from_date&&u.request.to_date&&u.request.toil_duration&&u.request.toil_to_accrue)}function h(){u.request.toil_expiry_date=!1,u.uiOptions.expiryDate=null}function v(){var e=u.uiOptions.multipleDays,t=u.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=u.isMode("create")&&H.hasExpirationFromAdminSettings,t=H.hasPreviousExpirationDate,n=u.isLeaveType("toil"),a=u.canManage;u.canDisplayToilExpirationField=n&&(a||e||t)}function y(){u.uiOptions.toil_duration_in_hours=u.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=u.isMode("edit")&&!!u.request.toil_expiry_date,i.canExpire(u.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return u.request.to_date_type=u.request.from_date_type="1",_().then(b).then($).then(T)}function $(){u.canManage&&(u.uiOptions.expiryDate=u.convertDateFormatFromServer(u.request.toil_expiry_date))}function C(){r.$watch(function(){return u.request.toil_to_accrue},function(e,t){+e!=+t&&u.performBalanceChangeCalculation()})}function w(){r.$watch(function(){return u.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&u.isCalculationUnit("hours")&&I(),u.request.toil_duration=u.uiOptions.toil_duration_in_hours?60*u.uiOptions.toil_duration_in_hours:null})}function A(){var e=u.uiOptions.times;e.from.time=t(u.request.from_date).format("HH:mm"),e.to.time=t(u.request.to_date).format("HH:mm"),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){r.$watch(function(){return u.uiOptions.times[e].time},function(e,t){e!==t&&(u.setRequestDateTimesAndDateTypes(),B(),l(),x())})})}function D(){u.isMode("view")||(C(),w(),P())}function T(t){return s.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){u.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function S(){return l(),x(),B()}function R(){return L(),u.uiOptions.multipleDays||u.updateEndTimeInputMinTime(u.uiOptions.times.from.time),l(),U?U=!1:x(),B()}function O(e){u.uiOptions.times[e].time=""}function I(){u.request.toil_to_accrue=u.uiOptions.toil_duration_in_hours}function x(){u.uiOptions.toil_duration_in_hours=u.uiOptions.max_toil_duration_and_accrual}function E(){F=e.cloneDeep(u.request.attributes())}function L(){u.uiOptions.multipleDays?["from","to"].forEach(function(e){u.uiOptions.times[e].min="00:00",u.uiOptions.times[e].max="23:45"}):(u.uiOptions.times.from.min="00:00",u.uiOptions.times.from.max="23:30",u.uiOptions.times.to.min="00:15",u.uiOptions.times.to.max="23:45")}function M(){u.setRequestDateTimesAndDateTypes(),l(),x(),u.isCalculationUnit("hours")?I():u.request.toil_to_accrue=null}function k(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){T(!1)})}function j(){u.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],r.section)}function B(){return f()?d().catch(a.resolve):a.resolve()}function N(){u.uiOptions.expiryDate&&(u.request.toil_expiry_date=u.convertDateToServerFormat(u.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var F,U=!u.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};u.canDisplayToilExpirationField=!1,u.calculateBalanceChange=c,u.canCalculateChange=m,u.canSubmit=p,u.clearExpiryDate=h,u.initChildController=q,u.initTimesExtended=A,u.initWatchersExtended=D,u.onAbsenceTypeUpdateExtended=M,u.onDateChangeExtended=S,u.openToilInDaysAccrualOptionsEditor=k,u.resetUIInputsExtended=O,u.setDaysSelectionModeExtended=R,u.updateExpiryDate=N,function(){E(),L(),j(),!u.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/models/session.model","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function r(t,r,o,s,i,u,c,l,d,m,f,p,h,v,g,b,y,_,q,$,C){function w(e){"days"===Le.selectedAbsenceType.calculation_unit_name?delete Le.request[e+"_date_amount"]:delete Le.request[e+"_date_type"]}function A(){["from","to"].forEach(w)}function P(){var e=Le.requestStatuses[_.statusNames.awaitingApproval].value;Se.status_id===e&&e!==Le.request.status_id&&d.publish("ManagerBadge:: Update Count")}function D(){return Ee.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function T(){return Ee.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Le.loading.entitlements&&(!!oe("admin")||!ae("view")&&!(oe("manager")&&!ae("create")))}function R(){var e=D();return Le.isMode("edit")&&(e=e&&(V()||T())),Le.canManage&&Le.requestStatuses&&(e=e&&!!Le.getStatusFromValue(Le.newStatusOnSave)),(e=e&&!!Le.period.id)&&!Le.isMode("view")}function O(){Le.isSelfRecord?Le.request.status_id=Le.requestStatuses[_.statusNames.awaitingApproval].value:Le.canManage&&(Le.request.status_id=Le.newStatusOnSave||Le.request.status_id)}function I(){if(Le.isMode("edit")&&!Le.isRole("staff")&&"toil"!==F())return Le.request.calculateBalanceChange(Le.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Le.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){o.$emit("LeaveRequestPopup::recalculateBalanceChange")}),r.reject()})}function x(){Le.errors=[]}function E(){return Le.request.create().then($e).then(function(){fe("LeaveRequest::new")})}function L(){ee()&&!Le.isRole("staff")&&(Le.request.change_balance=!0)}function M(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Le.request.delete().then(function(){Le.dismissModal(),d.publish("LeaveRequest::delete",Le.request)})}})}function k(){i.dismiss({$value:"cancel"})}function j(){var e=F();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function B(){return N(Le.getStatusFromValue(Le.request.status_id).name)}function N(e){return n.map(De[e],function(e){return Le.requestStatuses[e]})}function F(){return Le.request?Le.request.request_type:Le.leaveType||null}function U(){return!Le.request||e.equals({},Le.requestStatuses)?[]:Le.request.status_id?B():N("none")}function H(e){return n.find(Le.requestStatuses,function(t){return t.value===e})}function W(e){Le.errors=n.isArray(e)?e:[e],Le.loading.absenceTypes=!1,Le.submitting=!1}function V(){return!e.equals(Se,Le.request.attributes())||Le.canManage&&Le.newStatusOnSave}function G(){return Le.postContactSelection=!0,Le.staffMemberSelectionComplete=!1,Le.request.contact_id?r.resolve().then(ie).then(ue).then(he).then(ge).then(Z).then(z).then(Le.isMode("edit")?be:n.noop).then(function(){Le.postContactSelection=!1,Le.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ie)return r.reject(e)}):r.reject("The contact id was not set")}function Y(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];De.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],De.awaiting_approval=e,De.more_information_required=e,De.rejected=e,De.approved=e,De.cancelled=[_.statusNames.awaitingApproval].concat(e)}function z(){return Le.canManage?f.find(Le.request.contact_id).then(function(e){Le.contactName=e.display_name}):r.resolve()}function J(){Re.push(o.$on("LeaveRequestPopup::requestObjectUpdated",be),o.$on("LeaveRequestPopup::absencePeriodChanged",function(){ue().then(he).then(function(){o.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Le.absenceTypes)})}),o.$on("LeaveRequestPopup::handleError",function(e,t){W(t)}),o.$on("LeaveRequestPopup::childComponent::register",function(){Te++})),s.$on("$destroy",Ce),s.$on("LeaveRequestPopup::addTab",function(e,t){Ee.push(t)})}function K(){var e,t;Le.request=Le.leaveRequest||null,e=F(),t=Le.initRequestAttributes(),"leave"===e?Le.request=y.init(t):"sickness"===e?Le.request=q.init(t):"toil"===e&&(Le.request=$.init(t))}function X(){var e={};return Le.request?e=Le.request.attributes():Le.canManage||(e={contact_id:Oe}),e}function Q(){if(xe="staff","my-leave"!==o.section)return u(_.permissions.admin.administer).then(function(e){e&&(xe="admin")}).then(function(){return"staff"===xe&&u(_.permissions.ssp.manage).then(function(e){e&&(xe="manager")})}).finally(function(){Le.canManage=Le.isRole("manager")||Le.isRole("admin")})}function Z(){(Le.isRole("admin")||Le.isMode("create")&&Le.isRole("manager"))&&(Le.newStatusOnSave=Le.requestStatuses[_.statusNames.approved].value)}function ee(){return!Le.request.status_id||!n.includes(["cancelled","rejected"],H(Le.request.status_id).name)}function te(e){var t=Le.getStatusFromValue(Le.request.status_id);return!!t&&t.name===e}function ne(e){return Le.request&&Le.request.request_type===e}function ae(e){return Le.mode===e}function re(e,t){var n=a(e.from_date),r=a(e.to_date);return n.isSameOrAfter(t.start_date,"day")&&r.isSameOrBefore(t.end_date,"day")}function oe(e){return xe===e}function se(){return h.all().then(function(e){Le.absencePeriods=e})}function ie(){return v.all(j()).then(v.loadCalculationUnits).then(function(e){Pe={types:e,ids:e.map(function(e){return e.id})}})}function ue(){return Le.loading.entitlements=!0,g.all({contact_id:Le.request.contact_id,period_id:Le.period.id,type_id:{IN:Pe.ids}},!0).finally(function(){Le.loading.entitlements=!1})}function ce(){return p.get().then(function(e){Oe=e.contactId})}function le(){return Le.selectedContactId?f.find(Le.selectedContactId).then(function(e){Le.managedContacts=[e]}):Le.isRole("admin")?f.all().then(function(e){Le.managedContacts=n.remove(e.list,function(e){return e.id!==Oe})}):f.find(Oe).then(function(e){return e.leaveManagees()}).then(function(e){Le.managedContacts=e})}function de(){return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Le.requestStatuses=n.indexBy(e,"name")})}function me(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function fe(e){P(),d.publish(e,Le.request),Le.errors=[],Le.dismissModal()}function pe(){["from","to"].forEach(function(e){Le.request[e+"_date"]=Se[e+"_date"]})}function he(e){if(Le.absenceTypes=me(Pe.types,e),!Le.absenceTypes.length)return r.reject(Ie)}function ve(){Le.period=n.find(Le.absencePeriods,function(e){return Le.isMode("create")?e.current:re(Le.request,e)})}function ge(){Le.isMode("create")?(Le.selectedAbsenceType=Le.absenceTypes[0],Le.request.type_id=Le.selectedAbsenceType.id):Le.selectedAbsenceType=n.find(Le.absenceTypes,function(e){return e.id===Le.request.type_id})}function be(){Se=e.copy(Le.request.attributes())}function ye(){var e;Le.request.id?(e=[Le.requestStatuses[_.statusNames.approved].value,Le.requestStatuses[_.statusNames.adminApproved].value,Le.requestStatuses[_.statusNames.rejected].value,Le.requestStatuses[_.statusNames.cancelled].value],Le.mode="edit",Le.isRole("staff")&&e.indexOf(Le.request.status_id)>-1&&(Le.mode="view")):Le.mode="create"}function _e(){var e=Le.request.status_id;if(!Le.isMode("view")&&!Le.submitting)return Le.submitting=!0,O(),A(),Le.request.isValid().then(ee()&&I).then(L).then(!Le.request.change_balance&&pe).then(qe).then(function(){return Le.isMode("edit")?Ae():E()}).catch(function(t){Le.request.status_id=e,t&&W(t)}).finally(function(){Le.submitting=!1})}function qe(){return r.all(Ee.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function $e(){function e(e){e&&n.push(e),++a===Te&&(n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Te>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Ce(){Re.forEach(function(e){e()})}function we(){o.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Ae(){return Le.request.update().then($e).then(function(){Le.isRole("manager")?fe("LeaveRequest::updatedByManager"):(Le.isRole("staff")||Le.isRole("admin"))&&fe("LeaveRequest::edit")})}t.debug("RequestCtrl");var Pe,De={},Te=0,Se={},Re=[],Oe="",Ie="No entitlement",xe="",Ee=[],Le=n.assign(this,m);Le.absencePeriods=[],Le.absenceTypes=[],Le.canManage=!1,Le.contactName=null,Le.errors=[],Le.loading={absenceTypes:!0,entitlements:!0},Le.managedContacts=[],Le.mode="",Le.newStatusOnSave=null,Le.period={},Le.postContactSelection=!1,Le.requestStatuses={},Le.selectedAbsenceType={},Le.staffMemberSelectionComplete=!1,Le.submitting=!1,Le.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Le.canChangeAbsenceType=S,Le.canSubmit=R,Le.closeAlert=x,Le.deleteLeaveRequest=M,Le.dismissModal=k,Le.getStatuses=U,Le.getStatusFromValue=H,Le.initAfterContactSelection=G,Le.initRequestAttributes=X,Le.isLeaveStatus=te,Le.isLeaveType=ne,Le.isMode=ae,Le.isRole=oe,Le.submit=_e,Le.updateAbsenceType=we,function(){Le.loading.absenceTypes=!0,Y(),J(),r.all([ce(),Q(),se(),de()]).then(K).then(ye).then(ve).then(function(){return Le.canManage&&!Le.isMode("edit")&&le()}).then(function(){if(Le.selectedContactId&&(Le.request.contact_id=Le.selectedContactId),Le.request.contact_id)return Le.initAfterContactSelection()}).catch(W).finally(function(){Le.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","Session","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,r,o,s,i,u){function c(e){return i.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e,n,r,s,i){a.open({appendTo:t.children().eq(0),templateUrl:o.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveType:n,leaveRequest:e,selectedContactId:r,isSelfRecord:s,forceRecalculateBalanceChange:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return u.find(e).then(function(e){return c(e).then(function(t){t?l(e,e.request_type,e.contact_id,"my-leave"===n.section):r.error("Error","You dont have permission to see this leave request")})}).catch(function(e){r.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(r.tabName)}e.debug("Component: my-leave-container"),t.section="my-leave";var r=this;r.tabName=n.current.name,r.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(t){return t.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e){define("leave-absences/my-leave/modules/config",["common/angular","leave-absences/my-leave/modules/settings"],function(t){return t.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","settings",function(t,n,a,r,o,s){o.debugEnabled(s.debug),n.defaults.stripTrailingSlashes=!1,r.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.otherwise("/my-leave/report"),t.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM), define("leave-absences/my-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/models/option-group","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/ui-router","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-popup.service","leave-absences/my-leave/components/my-leave-container.component","leave-absences/my-leave/modules/config"],function(e){return e.module("my-leave",["ngResource","ngAnimate","ui.bootstrap","ui.router","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.mocks","common.models","common.services","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","my-leave.components","my-leave.config"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/angular/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/my-leave":n+"/my-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/my-leave/app"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-my-leave]"),["my-leave"])})})}(CRM,require),define("my-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/dist/my-leave.js.map \ No newline at end of file From 4e182f3bd35c849823d1592b559b82b52dccc825 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Fri, 27 Apr 2018 15:13:11 +0100 Subject: [PATCH 182/203] PCHR-3581: Make tooltip stay until unhovered --- .../leave-calendar-day.component.js | 31 ++++++- .../leave-calendar-day.component.spec.js | 69 ++++++++++++++- .../shared/components/leave-calendar-day.html | 83 ++++++++++--------- 3 files changed, 142 insertions(+), 41 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-day.component.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-day.component.js index ce9d96bfc1c..837fe05646a 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-day.component.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-day.component.js @@ -18,15 +18,22 @@ define([ controller: LeaveCalendarDayController }); - LeaveCalendarDayController.$inject = ['$log', '$scope', 'LeavePopup']; + LeaveCalendarDayController.$inject = ['$log', '$scope', '$timeout', 'LeavePopup']; - function LeaveCalendarDayController ($log, $scope, LeavePopup) { + function LeaveCalendarDayController ($log, $scope, $timeout, LeavePopup) { 'use strict'; $log.debug('Component: leave-calendar-day'); var vm = this; + vm.tooltip = { + show: false, + day_cell_hovered: false, + tooltip_hovered: false + }; + vm.openLeavePopup = openLeavePopup; + vm.toggleTooltip = toggleTooltip; (function init () { watchLeaveRequests(); @@ -188,6 +195,26 @@ define([ }); } + /** + * Toggles tooltip for the day. + * It reacts to entering/leaving either day cell or the tooltip itself, + * if either of the elements are hovered, it remains the tooltip open. + * It instantly shows a tooltip, but has a 100ms timeout to hide it once unhovered. + * + * @TODO this should be moved to a decorator to uib-tooltip + * + * @param {String} sourceElement day_cell|tooltip + * @param {Boolean} isHovered + */ + function toggleTooltip (sourceElement, isHovered) { + $timeout(function () { + vm.tooltip[sourceElement + '_hovered'] = isHovered; + + vm.tooltip.show = + vm.tooltip.day_cell_hovered || vm.tooltip.tooltip_hovered; + }, isHovered ? 0 : 100); + } + /** * Waits for the leave request to be accesible before mapping the necessary * leave request fields to it. diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-day.component.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-day.component.spec.js index a4a14194692..34e66b77bb4 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-day.component.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-day.component.spec.js @@ -12,15 +12,16 @@ define([ 'use strict'; describe('leaveCalendarDay', function () { - var $componentController, $log, $rootScope, absenceType, absenceTypes, + var $componentController, $log, $rootScope, $timeout, absenceType, absenceTypes, calculationUnits, calculationUnitInDays, calculationUnitInHours, contactData, controller, dayTypes, LeavePopup, leaveRequest, leaveRequestAttributes; beforeEach(module('manager-leave')); - beforeEach(inject(function (_$componentController_, _$log_, _$rootScope_, _LeavePopup_) { + beforeEach(inject(function (_$componentController_, _$log_, _$rootScope_, _$timeout_, _LeavePopup_) { $componentController = _$componentController_; $log = _$log_; $rootScope = _$rootScope_; + $timeout = _$timeout_; absenceTypes = _.cloneDeep(absenceTypeData.all().values); contactData = {}; leaveRequest = _.cloneDeep(leaveRequestData.all().values[0]); @@ -258,6 +259,70 @@ define([ }); }); + // @TODO this should be moved to a decorator to uib-tooltip + describe('toggleTooltip()', function () { + it('has the tooltip hidden by default', function () { + expect(controller.tooltip.show).toBe(false); + }); + + describe('when user hovers the day cell', function () { + beforeEach(function () { + toggleTooltip('day_cell', true); + }); + + it('shows tooltip', function () { + expect(controller.tooltip.show).toBe(true); + }); + + describe('and then user unhovers the day cell', function () { + beforeEach(function () { + toggleTooltip('day_cell', false); + }); + + it('hides the tooltip', function () { + expect(controller.tooltip.show).toBe(false); + }); + }); + + describe('and then user unhovers the day cell but hovers the tooltip', function () { + beforeEach(function () { + toggleTooltip('day_cell', false); + toggleTooltip('tooltip', true); + }); + + it('leaves the tooltip shown', function () { + expect(controller.tooltip.show).toBe(true); + }); + + describe('and then user unhovers the tooltip', function () { + beforeEach(function () { + toggleTooltip('tooltip', false); + }); + + it('hides the tooltip', function () { + expect(controller.tooltip.show).toBe(false); + }); + }); + + describe('and then user unhovers the tooltip but hovers the day cell back', function () { + beforeEach(function () { + toggleTooltip('tooltip', false); + toggleTooltip('tooltip', true); + }); + + it('leaves the tooltip shown', function () { + expect(controller.tooltip.show).toBe(true); + }); + }); + }); + }); + + function toggleTooltip (sourceElement, isHovered) { + controller.toggleTooltip(sourceElement, isHovered); + $timeout.flush(); + } + }); + /** * Compiles and stores the component instance. Passes the contact and * support data to the controller. diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html index 1230712f0dc..fbc02b24e69 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html @@ -1,7 +1,12 @@
    -
    - {{leaveRequestAttributes.absenceTypeTitle}} -
    -
    -

    - {{leaveRequestAttributes['from_date_type']}} -

    -
    -
    -

    - From: {{leaveRequestAttributes.from_date | date:'dd MMM yyyy'}}, - {{leaveRequestAttributes['from_date_type']}}
    - To: {{leaveRequestAttributes.to_date | date:'dd MMM yyyy'}}, - {{leaveRequestAttributes['to_date_type']}} -

    +
    +
    + {{leaveRequestAttributes.absenceTypeTitle}} +
    +
    +

    + {{leaveRequestAttributes['from_date_type']}} +

    +
    +
    +

    + From: {{leaveRequestAttributes.from_date | date:'dd MMM yyyy'}}, + {{leaveRequestAttributes['from_date_type']}}
    + To: {{leaveRequestAttributes.to_date | date:'dd MMM yyyy'}}, + {{leaveRequestAttributes['to_date_type']}} +

    +
    +
    +

    + From: {{leaveRequestAttributes.from_date | date:'HH:mm'}}
    + To: {{leaveRequestAttributes.to_date | date:'HH:mm'}}
    + For: {{ leaveRequest.from_date_amount | timeUnitApplier :leaveRequestAttributes.unit }} +

    +
    +
    +

    + From: {{leaveRequestAttributes.from_date | date:'dd MMM yyyy HH:mm'}}
    + To: {{leaveRequestAttributes.to_date | date:'dd MMM yyyy HH:mm'}} +

    +
    -
    -

    - From: {{leaveRequestAttributes.from_date | date:'HH:mm'}}
    - To: {{leaveRequestAttributes.to_date | date:'HH:mm'}}
    - For: {{ leaveRequest.from_date_amount | timeUnitApplier :leaveRequestAttributes.unit }} +

    +

    + + {{day.supportData.toilAmounts[leaveRequest.toil_to_accrue].label}} + + + {{leaveRequest.toil_to_accrue | timeUnitApplier : 'hours' }} +

    -
    -

    - From: {{leaveRequestAttributes.from_date | date:'dd MMM yyyy HH:mm'}}
    - To: {{leaveRequestAttributes.to_date | date:'dd MMM yyyy HH:mm'}} -

    -
    -
    -
    -

    - - {{day.supportData.toilAmounts[leaveRequest.toil_to_accrue].label}} - - - {{leaveRequest.toil_to_accrue | timeUnitApplier : 'hours' }} - -

    From df505df9aa7e12b1064360bc87b90ebdaa6b67d6 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Fri, 27 Apr 2018 16:28:54 +0100 Subject: [PATCH 183/203] PCHR-3581: Style tooltip and make clickable --- .../scss/components/_leave-calendar.scss | 30 +++++++++++++++++++ .../shared/components/leave-calendar-day.html | 10 +++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave-calendar.scss b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave-calendar.scss index 222bd4933b4..b2e0e9e0e41 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave-calendar.scss +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/scss/components/_leave-calendar.scss @@ -3,6 +3,8 @@ $chr-leave-calendar-cell-font-size: 10px; $chr-leave-calendar-item-requested-border-color: #c7cbd0; $chr-leave-calendar-item-requested-border-height: 0.5em; $chr-leave-calendar-legend-size: 20px; +$chr-leave-calendar-tooltip-shadow: 0 3px 8px 0 rgba(49, 40, 40, 0.25); +$chr-leave-calendar-tooltip-item-min-width: 154px; .chr_leave-calendar__dates-container { @@ -32,6 +34,34 @@ $chr-leave-calendar-legend-size: 20px; } } +// @TODO the tooltip style should be moved to the global styling +leave-calendar-day { + .tooltip.in { + opacity: 1; + } + + .tooltip-arrow { + border-top-color: $crm-white !important; + } + + .tooltip-inner { + background-color: $crm-white; + border-radius: 0; + box-shadow: $chr-leave-calendar-tooltip-shadow; + color: $gray-darker; + padding: 0; + } +} + +.chr_leave-calendar__day-tooltip_item { + min-width: $chr-leave-calendar-tooltip-item-min-width; + padding: $crm-gap-medium; + + &:hover { + background-color: $gray-light; + } +} + .chr_leave-calendar__day--disabled { opacity: 0.5; } diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html index fbc02b24e69..46a4a9ac940 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html @@ -30,7 +30,8 @@ + ng-click="day.tooltip.show = false; + day.openLeavePopup($event, leaveRequest, null, null, $root.section === 'my-leave')">
    -
    +
    {{leaveRequestAttributes.absenceTypeTitle}}
    From 790f366b544fbfc15f496d34a0188dc63907c34f Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Fri, 27 Apr 2018 17:04:44 +0100 Subject: [PATCH 184/203] PCHR-3581: Fix the issue with leave in hours --- .../request-modal-details-leave.controller.js | 2 ++ ...est-modal-details-leave.controller.spec.js | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller.js index 0bbcc718c28..42ebeefbb37 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller.js @@ -374,6 +374,8 @@ define([ return detailsController.handleError(err); }) .finally(function () { + detailsController.uiOptions.times[dateType].loading = false; + isSingleDayRequest && (detailsController.uiOptions.times['to'].loading = false); }); } diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-leave.controller.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-leave.controller.spec.js index c556a6c28e7..2f2ee7d706c 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-leave.controller.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/controllers/sub-controllers/request-modal-details-leave.controller.spec.js @@ -413,6 +413,32 @@ define([ }); }); + describe('when a leave request is edited', function () { + describe('when the leave request is in hours', function () { + beforeEach(function () { + var absenceType = _.assign(_.cloneDeep(absenceTypeData.all().values[0]), { + calculation_unit_name: 'hours' + }); + + var leaveRequest = LeaveRequestInstance.init({ + from_date: date2016InServerFormat, + to_date: date2016InServerFormat, + type_id: absenceType.id + }); + + compileComponent({ + mode: 'edit', + request: leaveRequest, + absenceTypes: [absenceType] + }); + }); + + it('finishes loading "from" time and shows the selector to UI', function () { + expect(controller.uiOptions.times['from'].loading).toBe(false); + }); + }); + }); + /** * Compiles and initializes the component's controller. It returns the * parameters used to initialize the controller plus default parameter From 4a4dc3c0d98e8fc2f3fadc3491e016191e44b89b Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Sat, 28 Apr 2018 11:59:51 +0100 Subject: [PATCH 185/203] PCHR-3581: Fix the issue with UI not reacting to changes --- .../shared/components/leave-calendar-day.html | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html index 46a4a9ac940..d15e70917ac 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html @@ -14,17 +14,16 @@ }">
    - {{leaveRequestAttributes.label}} + {{day.contactData.leaveRequestsAttributes[leaveRequest.id].label}}
    - {{leaveRequestAttributes.absenceTypeTitle}} -
    -
    + {{day.contactData.leaveRequestsAttributes[leaveRequest.id].absenceTypeTitle}} +
    +

    - {{leaveRequestAttributes['from_date_type']}} + {{day.contactData.leaveRequestsAttributes[leaveRequest.id].from_date_type}}

    -
    +

    - From: {{leaveRequestAttributes.from_date | date:'dd MMM yyyy'}}, - {{leaveRequestAttributes['from_date_type']}}
    - To: {{leaveRequestAttributes.to_date | date:'dd MMM yyyy'}}, - {{leaveRequestAttributes['to_date_type']}} + From: {{day.contactData.leaveRequestsAttributes[leaveRequest.id].from_date | date:'dd MMM yyyy'}}, + {{day.contactData.leaveRequestsAttributes[leaveRequest.id].from_date_type}}
    + To: {{day.contactData.leaveRequestsAttributes[leaveRequest.id].to_date | date:'dd MMM yyyy'}}, + {{day.contactData.leaveRequestsAttributes[leaveRequest.id].to_date_type}}

    -
    +

    - From: {{leaveRequestAttributes.from_date | date:'HH:mm'}}
    - To: {{leaveRequestAttributes.to_date | date:'HH:mm'}}
    - For: {{ leaveRequest.from_date_amount | timeUnitApplier :leaveRequestAttributes.unit }} + From: {{day.contactData.leaveRequestsAttributes[leaveRequest.id].from_date | date:'HH:mm'}}
    + To: {{day.contactData.leaveRequestsAttributes[leaveRequest.id].to_date | date:'HH:mm'}}
    + For: {{ leaveRequest.from_date_amount | timeUnitApplier :day.contactData.leaveRequestsAttributes[leaveRequest.id].unit }}

    -
    +

    - From: {{leaveRequestAttributes.from_date | date:'dd MMM yyyy HH:mm'}}
    - To: {{leaveRequestAttributes.to_date | date:'dd MMM yyyy HH:mm'}} + From: {{day.contactData.leaveRequestsAttributes[leaveRequest.id].from_date | date:'dd MMM yyyy HH:mm'}}
    + To: {{day.contactData.leaveRequestsAttributes[leaveRequest.id].to_date | date:'dd MMM yyyy HH:mm'}}

    -
    -

    +

    +

    {{day.supportData.toilAmounts[leaveRequest.toil_to_accrue].label}} From be734b31f6cf2cdf73b2c310d272cda5873c1fb9 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Sat, 28 Apr 2018 12:49:15 +0100 Subject: [PATCH 186/203] PCHR-3581: Fix the issue with shrinking leave request dates --- .../leave-calendar-month.component.js | 28 +++++++++++++++++-- .../leave-calendar-month.component.spec.js | 11 ++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-month.component.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-month.component.js index 381f5b58990..692fd0d37d5 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-month.component.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-month.component.js @@ -146,8 +146,14 @@ define([ * @param {LeaveRequestInstance} leaveRequest */ function deleteLeaveRequest (leaveRequest) { - removeLeaveRequestFromIndexedList(leaveRequest); - updateLeaveRequestDaysContactData(leaveRequest); + var indexedLeaveRequest = findIndexedLeaveRequest(leaveRequest); + + if (!indexedLeaveRequest) { + return; + } + + removeLeaveRequestFromIndexedList(indexedLeaveRequest); + updateLeaveRequestDaysContactData(indexedLeaveRequest); } /** @@ -169,6 +175,24 @@ define([ : leaveRequests; } + /** + * Finds indexed leave request by a leave request given + * + * @param {LeaveRequestInstance} leaveRequest + * @return {LeaveRequestInstance} indexed leave request + */ + function findIndexedLeaveRequest (leaveRequest) { + var indexedLeaveRequest; + + _.forEach(leaveRequests[leaveRequest.contact_id], function (day) { + indexedLeaveRequest = _.find(day, function (leaveRequestObj) { + return +leaveRequestObj.id === +leaveRequest.id; + }) || indexedLeaveRequest; + }); + + return indexedLeaveRequest; + } + /** * Get profile URL for the given contact id * diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-month.component.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-month.component.spec.js index f6d567818ac..adae78affb7 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-month.component.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-month.component.spec.js @@ -623,9 +623,13 @@ describe('leave request status update event', function () { beforeEach(function () { + var shrinkedLeaveRequest = _.cloneDeep(leaveRequestToDelete); + // Srinking the leave in terms of dates to ensure later that all dates are flushed + shrinkedLeaveRequest.to_date = shrinkedLeaveRequest.from_date; + pubSub.publish('LeaveRequest::statusUpdate', { status: 'delete', - leaveRequest: leaveRequestToDelete + leaveRequest: shrinkedLeaveRequest }); $rootScope.$digest(); }); @@ -633,12 +637,15 @@ itHandlesLeaveRequestDeleteEvent(); }); + /** + * Checks that the leave request is deleted + */ function itHandlesLeaveRequestDeleteEvent () { it('does not re-fetch the leave requests from the backend', function () { expect(LeaveRequest.all).not.toHaveBeenCalled(); }); - it('resets the properties of each day that the leave request spans', function () { + it('resets the properties of each day that the original leave request spans', function () { expect(getLeaveRequestDays(leaveRequestToDelete).every(isDayContactDataNull)).toBe(true); }); } From ba094489bbf46c7e06bdf111cb3577f414d40972 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Sat, 28 Apr 2018 14:35:21 +0100 Subject: [PATCH 187/203] PCHR-3581: Fix issue with closing stacked modals --- .../_modal-scroll-locker.scss | 5 + .../ui-bootstrap/uib-modal.decorator.js | 31 ++---- .../ui-bootstrap/uib-modal.decorator.spec.js | 98 +++++++++++++------ 3 files changed, 83 insertions(+), 51 deletions(-) create mode 100644 org.civicrm.bootstrapcivihr/scss/components/outside-namespace/_modal-scroll-locker.scss diff --git a/org.civicrm.bootstrapcivihr/scss/components/outside-namespace/_modal-scroll-locker.scss b/org.civicrm.bootstrapcivihr/scss/components/outside-namespace/_modal-scroll-locker.scss new file mode 100644 index 00000000000..f431b1ca59f --- /dev/null +++ b/org.civicrm.bootstrapcivihr/scss/components/outside-namespace/_modal-scroll-locker.scss @@ -0,0 +1,5 @@ +.chr_scroll-lock { + height: 100% !important; + overflow: hidden !important; + width: 100% !important; +} diff --git a/org.civicrm.reqangular/src/common/decorators/ui-bootstrap/uib-modal.decorator.js b/org.civicrm.reqangular/src/common/decorators/ui-bootstrap/uib-modal.decorator.js index 62b314f29cd..ad91bc7c2a8 100644 --- a/org.civicrm.reqangular/src/common/decorators/ui-bootstrap/uib-modal.decorator.js +++ b/org.civicrm.reqangular/src/common/decorators/ui-bootstrap/uib-modal.decorator.js @@ -20,38 +20,23 @@ define([ function open () { var modalInstance; var elements = [ - { - item: angular.element($document[0].body), - styles: [ - { name: 'overflow', old: null, new: 'hidden' }, - { name: 'height', old: null, new: '100%' }, - { name: 'width', old: null, new: '100%' } - ] - }, - { - item: angular.element($document[0].getElementsByTagName('html')[0]), - styles: [ - { name: 'overflow', old: null, new: 'hidden' }, - { name: 'height', old: null, new: '100%' }, - { name: 'width', old: null, new: '100%' } - ] - } + $document.find('body'), + $document.find('html') ]; elements.forEach(function (element) { - element.styles.forEach(function (style) { - style.old = element.item.css(style.name); - element.item.css(style.name, style.new); - }); + element.addClass('chr_scroll-lock'); }); modalInstance = originalOpenFunction.apply(this, arguments); modalInstance.closed.then(function () { + if ($document.find('.modal-dialog').length) { + return; + } + elements.forEach(function (element) { - element.styles.forEach(function (style) { - element.item.css(style.name, style.old); - }); + element.removeClass('chr_scroll-lock'); }); }); diff --git a/org.civicrm.reqangular/test/decorators/ui-bootstrap/uib-modal.decorator.spec.js b/org.civicrm.reqangular/test/decorators/ui-bootstrap/uib-modal.decorator.spec.js index b5fc40dba3b..720742afc1c 100644 --- a/org.civicrm.reqangular/test/decorators/ui-bootstrap/uib-modal.decorator.spec.js +++ b/org.civicrm.reqangular/test/decorators/ui-bootstrap/uib-modal.decorator.spec.js @@ -10,7 +10,7 @@ define([ 'use strict'; describe('$uibModal.open', function () { - var $uibModal, $document; + var $document, $rootScope, $uibModal; beforeEach(module('ui.bootstrap')); @@ -18,61 +18,103 @@ define([ $provide.decorator('$uibModal', $uibModalDecorator); })); - beforeEach(inject(function (_$document_, _$uibModal_) { + beforeEach(inject(function (_$document_, _$rootScope_, _$uibModal_) { $document = _$document_; + $rootScope = _$rootScope_; $uibModal = _$uibModal_; })); describe('init', function () { - var originalStyles; var arg1 = { template: '' }; var arg2 = 'another_argument'; var elements = {}; beforeEach(function () { - elements.body = $document[0].body; - elements.html = $document[0].getElementsByTagName('html')[0]; - - if (!originalStyles) { - originalStyles = { - body: _.clone(elements.body.style), - html: _.clone(elements.html.style) - }; - } + elements.body = $document.find('body'); + elements.html = $document.find('html'); }); describe('when modal is opened', function () { - var modalInstance; + var modalInstance1; beforeEach(function () { - modalInstance = $uibModal.open(arg1, arg2); + modalInstance1 = $uibModal.open(arg1, arg2); + $rootScope.$digest(); }); - ['body', 'html'].forEach(function (element) { - _.forOwn({ overflow: 'hidden', height: '100%', width: '100%' }, function (value, style) { - it('sets ' + style + ' to ' + value + ' for <' + element + '>', function () { - expect(elements[element].style[style]).toBe(value); - }); - }); + afterEach(function () { + $document.find('.modal-dialog').remove(); + }); + + it('locks document scroll', function () { + expect($document.find('.modal-dialog').length).toBe(1); + expect(checkLockingClassForAllElements()).toBe(true); }); describe('when modal is closed', function () { beforeEach(function () { - // @TODO The solution to simply close the modal was not found and - // the test cannot be run at the moment. If you have any idea - // on how to make this test work, please amend it and turn on. - modalInstance.close(); + // Closes the modal and executes the listener + $document.find('.modal-dialog').remove(); + modalInstance1.closed.$$state.pending[0][1](); + }); + + it('unlocks document scroll', function () { + expect($document.find('.modal-dialog').length).toBe(0); + expect(checkLockingClassForAllElements()).toBe(false); + }); + }); + + describe('when second modal is opened on top of the first modal', function () { + var modalInstance2; + + beforeEach(function () { + modalInstance2 = $uibModal.open(arg1, arg2); + $rootScope.$digest(); }); - ['body', 'html'].forEach(function (element) { - ['width', 'height', 'overflow'].forEach(function (style) { - xit('sets original ' + style + ' for <' + element + '>', function () { - expect(elements[element].style[style]).toBe(originalStyles[element][style]); + it('remains document scroll locked', function () { + expect($document.find('.modal-dialog').length).toBe(2); + expect(checkLockingClassForAllElements()).toBe(true); + }); + + describe('when second modal is closed', function () { + beforeEach(function () { + // Closes second modal and executes the listener + $document.find('.modal-dialog').last().remove(); + modalInstance2.closed.$$state.pending[0][1](); + }); + + it('remains document scroll locked', function () { + expect($document.find('.modal-dialog').length).toBe(1); + expect(checkLockingClassForAllElements()).toBe(true); + }); + + describe('and when the first modal is closed', function () { + beforeEach(function () { + // Closes the first modal and executes the listener + $document.find('.modal-dialog').first().remove(); + modalInstance1.closed.$$state.pending[0][1](); + }); + + it('unlocks document scroll', function () { + expect($document.find('.modal-dialog').length).toBe(0); + expect(checkLockingClassForAllElements()).toBe(false); }); }); }); }); }); + + /** + * Checks for the state of document scroll locking + * + * @return {Boolean} + */ + function checkLockingClassForAllElements () { + return _.every(elements, function (element) { + return element.hasClass('chr_scroll-lock'); + }); + } }); }); }); From f8f6ebe33285b171c64bd48546f39728bb1dbf09 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Sun, 29 Apr 2018 14:03:25 +0100 Subject: [PATCH 188/203] PCHR-3581: Fix issue with single day requests --- .../leave-calendar-month.component.js | 41 +++++++++------ .../leave-calendar-month.component.spec.js | 12 +++++ .../shared/components/leave-calendar-day.html | 52 ++++++++++--------- 3 files changed, 65 insertions(+), 40 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-month.component.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-month.component.js index 692fd0d37d5..3bfe97f70b5 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-month.component.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-month.component.js @@ -202,6 +202,31 @@ define([ return CRM.url('civicrm/contact/view', { cid: contactId }); } + /** + * Returns leave requests additional attributes for UI + * + * @param {Object} day + * @param {Array} leaveRequests [{LeaveRequestInstance}] + * @return {Object} collection of leave requests attributes + * indexed by leave requests IDs + */ + function getLeaveRequestsAttributes (day, leaveRequests) { + var attributes = {}; + + leaveRequests.forEach(function (leaveRequest) { + attributes[leaveRequest.id] = { + styles: styles(leaveRequest), + isAccruedTOIL: isLeaveType(leaveRequest, 'toil'), + isRequested: isRequested(leaveRequest), + isAM: isDayType('half_day_am', leaveRequest, day.date), + isPM: isDayType('half_day_pm', leaveRequest, day.date), + isSingleDay: moment(leaveRequest.from_date).isSame(leaveRequest.to_date, 'day') + }; + }); + + return attributes; + } + /** * Indexes for easy access the data that the component needs */ @@ -516,22 +541,6 @@ define([ }); } - function getLeaveRequestsAttributes (day, leaveRequests) { - var attributes = {}; - - leaveRequests.forEach(function (leaveRequest) { - attributes[leaveRequest.id] = { - styles: styles(leaveRequest), - isAccruedTOIL: leaveRequest ? isLeaveType(leaveRequest, 'toil') : null, - isRequested: leaveRequest ? isRequested(leaveRequest) : null, - isAM: leaveRequest ? isDayType('half_day_am', leaveRequest, day.date) : null, - isPM: leaveRequest ? isDayType('half_day_pm', leaveRequest, day.date) : null - }; - }); - - return attributes; - } - /** * It sets the properties of every day of the month * diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-month.component.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-month.component.spec.js index adae78affb7..aa1e44e03c2 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-month.component.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-month.component.spec.js @@ -583,6 +583,18 @@ expect(leaveRequestAttributes.isAccruedTOIL).toBe(true); }); }); + + describe('when the leave request is a single day request', function () { + beforeEach(function () { + leaveRequest.from_date = leaveRequest.to_date; + + commonSetup(); + }); + + it('marks it as such', function () { + expect(leaveRequestAttributes.isSingleDay).toBe(true); + }); + }); }); function getDayWithType (dayType, returnContactData) { diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html index d15e70917ac..c2cf299f15d 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html @@ -50,31 +50,35 @@ day.openLeavePopup($event, leaveRequest, null, null, $root.section === 'my-leave')"> {{day.contactData.leaveRequestsAttributes[leaveRequest.id].absenceTypeTitle}}

    -
    -

    - {{day.contactData.leaveRequestsAttributes[leaveRequest.id].from_date_type}} -

    +
    +
    +

    + {{day.contactData.leaveRequestsAttributes[leaveRequest.id].from_date_type}} +

    +
    +
    +

    + From: {{day.contactData.leaveRequestsAttributes[leaveRequest.id].from_date | date:'HH:mm'}}
    + To: {{day.contactData.leaveRequestsAttributes[leaveRequest.id].to_date | date:'HH:mm'}}
    + For: {{ leaveRequest.from_date_amount | timeUnitApplier :day.contactData.leaveRequestsAttributes[leaveRequest.id].unit }} +

    +
    -
    -

    - From: {{day.contactData.leaveRequestsAttributes[leaveRequest.id].from_date | date:'dd MMM yyyy'}}, - {{day.contactData.leaveRequestsAttributes[leaveRequest.id].from_date_type}}
    - To: {{day.contactData.leaveRequestsAttributes[leaveRequest.id].to_date | date:'dd MMM yyyy'}}, - {{day.contactData.leaveRequestsAttributes[leaveRequest.id].to_date_type}} -

    -
    -
    -

    - From: {{day.contactData.leaveRequestsAttributes[leaveRequest.id].from_date | date:'HH:mm'}}
    - To: {{day.contactData.leaveRequestsAttributes[leaveRequest.id].to_date | date:'HH:mm'}}
    - For: {{ leaveRequest.from_date_amount | timeUnitApplier :day.contactData.leaveRequestsAttributes[leaveRequest.id].unit }} -

    -
    -
    -

    - From: {{day.contactData.leaveRequestsAttributes[leaveRequest.id].from_date | date:'dd MMM yyyy HH:mm'}}
    - To: {{day.contactData.leaveRequestsAttributes[leaveRequest.id].to_date | date:'dd MMM yyyy HH:mm'}} -

    +
    +
    +

    + From: {{day.contactData.leaveRequestsAttributes[leaveRequest.id].from_date | date:'dd MMM yyyy'}}, + {{day.contactData.leaveRequestsAttributes[leaveRequest.id].from_date_type}}
    + To: {{day.contactData.leaveRequestsAttributes[leaveRequest.id].to_date | date:'dd MMM yyyy'}}, + {{day.contactData.leaveRequestsAttributes[leaveRequest.id].to_date_type}} +

    +
    +
    +

    + From: {{day.contactData.leaveRequestsAttributes[leaveRequest.id].from_date | date:'dd MMM yyyy HH:mm'}}
    + To: {{day.contactData.leaveRequestsAttributes[leaveRequest.id].to_date | date:'dd MMM yyyy HH:mm'}} +

    +
    From d68c2fab9eeb8c929ad13131eb28b8ed6a6c8f78 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Sun, 29 Apr 2018 14:20:40 +0100 Subject: [PATCH 189/203] PCHR-3581: Sort leave requests --- .../leave-calendar-month.component.js | 9 +++ .../leave-calendar-month.component.spec.js | 65 +++++++++++++++++-- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-month.component.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-month.component.js index 3bfe97f70b5..4b88ecd8072 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-month.component.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-calendar-month.component.js @@ -533,6 +533,8 @@ define([ return leaveRequests[contactId] && leaveRequests[contactId][day.date] ? leaveRequests[contactId][day.date] : []; }) .then(function (leaveRequests) { + leaveRequests = sortLeaveRequests(leaveRequests); + _.assign(day.contactsData[contactId], { leaveRequests: leaveRequests, leaveRequestsToShowInCell: filterLeaveRequestsToShowInCell(leaveRequests), @@ -575,6 +577,13 @@ define([ } } + function sortLeaveRequests (leaveRequests) { + return _.sortBy(leaveRequests, function (leaveRequest) { + return +moment(leaveRequest.from_date).format('X') + + (isDayType('half_day_pm', leaveRequest, leaveRequest.from_date) ? 1 : 0); + }); + } + /** * Returns the styles for a specific leaveRequest * which will be used in the view for each date diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-month.component.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-month.component.spec.js index aa1e44e03c2..68cfd525b48 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-month.component.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/test/shared/components/leave-calendar-month.component.spec.js @@ -388,6 +388,11 @@ jasmine.clock().uninstall(); }); + /** + * Mocks current day + * + * @param {String} date + */ function setCurrentDay (date) { jasmine.clock().mockDate(date); compileComponent(); @@ -469,6 +474,38 @@ }); }); + describe('when day contains unsorted requests in hours', function () { + beforeEach(function () { + leaveRequest1 = _.clone(LeaveRequestData.singleDataSuccess().values[0]); + leaveRequest1.from_date = leaveRequest1.from_date.split(' ')[0] + ' 23:00'; + leaveRequest2 = _.clone(LeaveRequestData.singleDataSuccess().values[0]); + leaveRequest2.from_date = leaveRequest2.from_date.split(' ')[0] + ' 11:00'; + + commonSetup([leaveRequest1, leaveRequest2]); + }); + + it('sorts leave requests', function () { + expect(contactData.leaveRequests[0]).toBe(leaveRequest2); + expect(contactData.leaveRequests[1]).toBe(leaveRequest1); + }); + }); + + describe('when day contains unsorted requests in days', function () { + beforeEach(function () { + leaveRequest1 = _.clone(LeaveRequestData.singleDataSuccess().values[0]); + leaveRequest1.from_date_type = getDayTypeId('half_day_pm'); + leaveRequest2 = _.clone(LeaveRequestData.singleDataSuccess().values[0]); + leaveRequest2.from_date_type = getDayTypeId('half_day_am'); + + commonSetup([leaveRequest1, leaveRequest2]); + }); + + it('sorts leave requests', function () { + expect(contactData.leaveRequests[0]).toBe(leaveRequest2); + expect(contactData.leaveRequests[1]).toBe(leaveRequest1); + }); + }); + describe('when day contains a mix of TOIL and non-TOIL requests', function () { beforeEach(function () { leaveRequest1 = _.clone(LeaveRequestData.singleDataSuccess().values[0]); @@ -546,9 +583,7 @@ describe('when the leave request is for half day am', function () { beforeEach(function () { - leaveRequest.from_date_type = _.find(OptionGroupData.getCollection('hrleaveandabsences_leave_request_day_type'), function (absenceType) { - return absenceType.name === 'half_day_am'; - }).value; + leaveRequest.from_date_type = getDayTypeId('half_day_am'); commonSetup(); }); @@ -560,9 +595,7 @@ describe('when leave request is for half day pm', function () { beforeEach(function () { - leaveRequest.from_date_type = _.find(OptionGroupData.getCollection('hrleaveandabsences_leave_request_day_type'), function (absenceType) { - return absenceType.name === 'half_day_pm'; - }).value; + leaveRequest.from_date_type = getDayTypeId('half_day_pm'); commonSetup(); }); @@ -597,6 +630,13 @@ }); }); + /** + * Returns a day by a given day type + * + * @param {String} dayType + * @param {Boolean} returnContactData + * @return {Object} + */ function getDayWithType (dayType, returnContactData) { var day; @@ -917,6 +957,19 @@ !!sendSignal && sendShowMonthsSignal(); } + /** + * Gets day type ID by its name + * + * @param {String} dayTypeName + * @return {String} + */ + function getDayTypeId (dayTypeName) { + return _.find(OptionGroupData.getCollection( + 'hrleaveandabsences_leave_request_day_type'), function (dayType) { + return dayType.name === dayTypeName; + }).value; + } + /** * Sends the "show months" signal to the component * From e465e501c400f2f6f4731fc65b2d9d967b5eba7f Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Sun, 29 Apr 2018 14:37:29 +0100 Subject: [PATCH 190/203] PCHR-3581: Fix issue in PHP unit tests --- .../CRM/HRLeaveAndAbsences/BAO/LeaveRequestTest.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveRequestTest.php b/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveRequestTest.php index b58f01fe820..4b3eba25338 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveRequestTest.php +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/tests/phpunit/CRM/HRLeaveAndAbsences/BAO/LeaveRequestTest.php @@ -3313,9 +3313,12 @@ public function testToilCanBeAccruedWhenTheCurrentBalanceForPeriodEntitlementIsZ } public function testToilCanBeAccruedWhenTheToilRequestHasNoWorkingDay() { + $dateSaturday = CRM_Utils_Date::processDate('2018-05-05'); + $dateSunday = CRM_Utils_Date::processDate('2018-05-06'); + $period = AbsencePeriodFabricator::fabricate([ - 'start_date' => CRM_Utils_Date::processDate('-1 day'), - 'end_date' => CRM_Utils_Date::processDate('+10 days'), + 'start_date' => $dateSaturday, + 'end_date' => $dateSunday, ]); $absenceType = AbsenceTypeFabricator::fabricate([ @@ -3348,9 +3351,9 @@ public function testToilCanBeAccruedWhenTheToilRequestHasNoWorkingDay() { 'type_id' => $absenceType->id, 'contact_id' => $periodEntitlement->contact_id, 'status_id' => 1, - 'from_date' => CRM_Utils_Date::processDate('saturday'), + 'from_date' => $dateSaturday, 'from_date_type' => 1, - 'to_date' => CRM_Utils_Date::processDate('sunday'), + 'to_date' => $dateSunday, 'to_date_type' => 1, 'toil_to_accrue' => 2.5, 'toil_duration' => 120, From 2279ff1774bd0eab03a977b993e41a42b6dd2daa Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Sun, 29 Apr 2018 15:26:00 +0100 Subject: [PATCH 191/203] PCHR-3581: Remove unnecessary paragraphs --- .../shared/components/leave-calendar-day.html | 49 +++++++------------ 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html index c2cf299f15d..fa7006b6462 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-calendar-day.html @@ -6,7 +6,6 @@ tooltip-trigger="none" tooltip-enable="day.contactData.leaveRequests.length" ng-mouseenter="day.toggleTooltip('day_cell', true)" - ng-mouseleave="day.toggleTooltip('day_cell', false)" ng-class="{ 'chr_leave-calendar__day-container--type--weekend': day.contactData.isWeekend, 'chr_leave-calendar__day-container--non-working': day.contactData.isNonWorkingDay, @@ -42,8 +41,7 @@
    +
    + {{contact.display_name}} {{contact.display_name}}